diff --git a/lib/App/Netdisco/Worker/Plugin/Arpnip/Hooks.pm b/lib/App/Netdisco/Worker/Plugin/Arpnip/Hooks.pm new file mode 100644 index 00000000..e99e4efc --- /dev/null +++ b/lib/App/Netdisco/Worker/Plugin/Arpnip/Hooks.pm @@ -0,0 +1,31 @@ +package App::Netdisco::Worker::Plugin::Arpnip::Hooks; + +use Dancer ':syntax'; +use App::Netdisco::Worker::Plugin; +use aliased 'App::Netdisco::Worker::Status'; + +use App::Netdisco::Util::Worker; +use App::Netdisco::Util::Permission qw/check_acl_no check_acl_only/; + +register_worker({ phase => 'late' }, sub { + my ($job, $workerconf) = @_; + my $count = 0; + + foreach my $conf (@{ setting('hooks') }) { + my $no = ($conf->{'filter'}->{'no'} || []); + my $only = ($conf->{'filter'}->{'only'} || []); + + next if check_acl_no( $job->device, $no ); + next unless check_acl_only( $job->device, $only); + + if ($conf->{'event'} eq 'arpnip') { + $count += queue_hook('arpnip', $conf); + sprintf ' [%s] hooks - %s queued', 'arpnip', $job->device; + } + } + + return Status + ->info(sprintf ' [%s] hooks - %d queued', $job->device, $count); +}); + +true; diff --git a/lib/App/Netdisco/Worker/Plugin/Discover/Hooks.pm b/lib/App/Netdisco/Worker/Plugin/Discover/Hooks.pm index 0404a759..d647a38a 100644 --- a/lib/App/Netdisco/Worker/Plugin/Discover/Hooks.pm +++ b/lib/App/Netdisco/Worker/Plugin/Discover/Hooks.pm @@ -18,11 +18,15 @@ register_worker({ phase => 'late' }, sub { next if check_acl_no( $job->device, $no ); next unless check_acl_only( $job->device, $only); - $count += queue_hook('new_device', $conf) - if vars->{'new_device'} and $conf->{'event'} eq 'new_device'; + if (vars->{'new_device'} and $conf->{'event'} eq 'new_device') { + $count += queue_hook('new_device', $conf); + debug sprintf ' [%s] hooks - %s queued', 'new_device', $job->device; + } - $count += queue_hook('discover', $conf) - if $conf->{'event'} eq 'discover'; + if ($conf->{'event'} eq 'discover') { + $count += queue_hook('discover', $conf); + debug sprintf ' [%s] hooks - %s queued', 'discover', $job->device; + } } return Status diff --git a/lib/App/Netdisco/Worker/Plugin/Macsuck/Hooks.pm b/lib/App/Netdisco/Worker/Plugin/Macsuck/Hooks.pm new file mode 100644 index 00000000..0594fc62 --- /dev/null +++ b/lib/App/Netdisco/Worker/Plugin/Macsuck/Hooks.pm @@ -0,0 +1,31 @@ +package App::Netdisco::Worker::Plugin::Macsuck::Hooks; + +use Dancer ':syntax'; +use App::Netdisco::Worker::Plugin; +use aliased 'App::Netdisco::Worker::Status'; + +use App::Netdisco::Util::Worker; +use App::Netdisco::Util::Permission qw/check_acl_no check_acl_only/; + +register_worker({ phase => 'late' }, sub { + my ($job, $workerconf) = @_; + my $count = 0; + + foreach my $conf (@{ setting('hooks') }) { + my $no = ($conf->{'filter'}->{'no'} || []); + my $only = ($conf->{'filter'}->{'only'} || []); + + next if check_acl_no( $job->device, $no ); + next unless check_acl_only( $job->device, $only); + + if ($conf->{'event'} eq 'macsuck') { + $count += queue_hook('macsuck', $conf); + sprintf ' [%s] hooks - %s queued', 'macsuck', $job->device; + } + } + + return Status + ->info(sprintf ' [%s] hooks - %d queued', $job->device, $count); +}); + +true;