« blib/lib/App/Netdisco/Worker/Plugin/Macsuck.pm
↑ Summary
blib/lib/App/Netdisco/Worker/Plugin/Macsuck/InterfacesStatus.pm »
| 1 | package App::Netdisco::Worker::Plugin::Macsuck::Hooks; | ||
| 2 | |||
| 3 | use Dancer ':syntax'; | ||
| 4 | use App::Netdisco::Worker::Plugin; | ||
| 5 | use aliased 'App::Netdisco::Worker::Status'; | ||
| 6 | |||
| 7 | use App::Netdisco::Util::Worker; | ||
| 8 | use App::Netdisco::Util::Permission qw/acl_matches acl_matches_only/; | ||
| 9 | |||
| 10 | register_worker({ phase => 'late' }, sub { | ||
| 11 | my ($job, $workerconf) = @_; | ||
| 12 | my $count = 0; | ||
| 13 | |||
| 14 | my $best = $job->best_status; | ||
| 15 | if (Status->$best->level != Status->done->level) { | ||
| 16 | return Status | ||
| 17 | ->info(sprintf ' [%s] hooks - skipping due to incomplete job', $job->device); | ||
| 18 | } | ||
| 19 | |||
| 20 | foreach my $conf (@{ setting('hooks') }) { | ||
| 21 | my $no = ($conf->{'filter'}->{'no'} || []); | ||
| 22 | my $only = ($conf->{'filter'}->{'only'} || []); | ||
| 23 | |||
| 24 | next if acl_matches( $job->device, $no ); | ||
| 25 | next unless acl_matches_only( $job->device, $only); | ||
| 26 | |||
| 27 | if ($conf->{'event'} eq 'macsuck') { | ||
| 28 | $count += queue_hook('macsuck', $conf); | ||
| 29 | debug sprintf ' [%s] hooks - %s queued', 'macsuck', $job->device; | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | return Status | ||
| 34 | ->info(sprintf ' [%s] hooks - %d queued', $job->device, $count); | ||
| 35 | }); | ||
| 36 | |||
| 37 | true; |