1package App::Netdisco::Worker::Plugin::Discover::Hooks;
2
3use Dancer ':syntax';
4use App::Netdisco::Worker::Plugin;
5use aliased 'App::Netdisco::Worker::Status';
6
7use App::Netdisco::Util::Worker;
8use App::Netdisco::Util::Permission qw/check_acl_no check_acl_only/;
9
10register_worker({ phase => 'late' }, sub {
11  my ($job, $workerconf) = @_;
12  my $count = 0;
13
14  foreach my $conf (@{ setting('hooks') }) {
15    my $no   = ($conf->{'filter'}->{'no'}   || []);
16    my $only = ($conf->{'filter'}->{'only'} || []);
17
18    next if check_acl_no( $job->device, $no );
19    next unless check_acl_only( $job->device, $only);
20
21    if (vars->{'new_device'} and $conf->{'event'} eq 'new_device') {
22      $count += queue_hook('new_device', $conf);
23      debug sprintf ' [%s] hooks - %s queued', 'new_device', $job->device;
24    }
25
26    if ($conf->{'event'} eq 'discover') {
27      $count += queue_hook('discover', $conf);
28      debug sprintf ' [%s] hooks - %s queued', 'discover', $job->device;
29    }
30  }
31
32  return Status
33    ->info(sprintf ' [%s] hooks - %d queued', $job->device, $count);
34});
35
36true;
37