« blib/lib/App/Netdisco/Worker/Plugin/Delete/Hooks.pm
↑ Summary
blib/lib/App/Netdisco/Worker/Plugin/Discover/CanonicalIP.pm »
| 1 | package App::Netdisco::Worker::Plugin::Discover; | ||
| 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_discoverable_now'; | ||
| 8 | use Time::HiRes 'gettimeofday'; | ||
| 9 | |||
| 10 | register_worker({ phase => 'check' }, sub { | ||
| 11 | my ($job, $workerconf) = @_; | ||
| 12 | my $device = $job->device; | ||
| 13 | |||
| 14 | return Status->error('discover failed: unable to interpret device param') | ||
| 15 | unless defined $device; | ||
| 16 | |||
| 17 | return Status->error("discover failed: no device param (need -d ?)") | ||
| 18 | if $device->ip eq '0.0.0.0'; | ||
| 19 | |||
| 20 | return Status->info("discover skipped: $device is not discoverable") | ||
| 21 | unless is_discoverable_now($device); | ||
| 22 | |||
| 23 | # would be possible just to use LOCALTIMESTAMP on updated records, but by using this | ||
| 24 | # same value for them all, we can if we want add a job at the end to | ||
| 25 | # select and do something with the updated set (see set archive, below) | ||
| 26 | vars->{'timestamp'} = ($job->is_offline and $job->entered) | ||
| 27 | ? (schema('netdisco')->storage->dbh->quote($job->entered) .'::timestamp') | ||
| 28 | : 'to_timestamp('. (join '.', gettimeofday) .')::timestamp'; | ||
| 29 | |||
| 30 | return Status->done('Discover is able to run.'); | ||
| 31 | }); | ||
| 32 | |||
| 33 | true; |