« blib/lib/App/Netdisco/Worker/Plugin/AddPseudoDevice.pm
↑ Summary
blib/lib/App/Netdisco/Worker/Plugin/Arpnip/Hooks.pm »
| 1 | package App::Netdisco::Worker::Plugin::Arpnip; | ||
| 2 | |||
| 3 | use Dancer ':syntax'; | ||
| 4 | use App::Netdisco::Worker::Plugin; | ||
| 5 | use aliased 'App::Netdisco::Worker::Status'; | ||
| 6 | |||
| 7 | use App::Netdisco::Util::Device 'is_arpnipable_now'; | ||
| 8 | |||
| 9 | register_worker({ phase => 'check' }, sub { | ||
| 10 | my ($job, $workerconf) = @_; | ||
| 11 | my $device = $job->device; | ||
| 12 | |||
| 13 | return Status->error('arpnip failed: unable to interpret device param') | ||
| 14 | unless defined $device; | ||
| 15 | |||
| 16 | return Status->error("arpnip skipped: $device not yet discovered") | ||
| 17 | unless $device->in_storage; | ||
| 18 | |||
| 19 | if ($job->port or $job->extra) { | ||
| 20 | $job->is_offline(true); | ||
| 21 | debug 'arpnip offline: will update from CLI or API'; | ||
| 22 | } | ||
| 23 | else { | ||
| 24 | return Status->info("arpnip skipped: $device is not arpnipable") | ||
| 25 | unless is_arpnipable_now($device); | ||
| 26 | } | ||
| 27 | |||
| 28 | # support for Hooks | ||
| 29 | vars->{'hook_data'} = { $device->get_columns }; | ||
| 30 | delete vars->{'hook_data'}->{'snmp_comm'}; # for privacy | ||
| 31 | |||
| 32 | return Status->done('arpnip is able to run'); | ||
| 33 | }); | ||
| 34 | |||
| 35 | true; |