move nbtstat and nbtwalk to worker plugins

This commit is contained in:
Oliver Gorwits
2017-09-09 14:46:00 +01:00
parent e7508a9eca
commit 271ef1a25c
7 changed files with 133 additions and 83 deletions

View File

@@ -0,0 +1,50 @@
package App::Netdisco::Worker::Plugin::Nbtstat::Core;
use Dancer ':syntax';
use App::Netdisco::Worker::Plugin;
use aliased 'App::Netdisco::Worker::Status';
use App::Netdisco::Util::Nbtstat qw/nbtstat_resolve_async store_nbt/;
use App::Netdisco::Util::Node 'is_nbtstatable';
use Dancer::Plugin::DBIC 'schema';
use Time::HiRes 'gettimeofday';
register_worker({ primary => true }, sub {
my ($job, $workerconf) = @_;
my $host = $job->device->ip;
# get list of nodes on device
my $interval = (setting('nbtstat_max_age') || 7) . ' day';
my $rs = schema('netdisco')->resultset('NodeIp')->search({
-bool => 'me.active',
-bool => 'nodes.active',
'nodes.switch' => $host,
'me.time_last' => \[ '>= now() - ?::interval', $interval ],
},{
join => 'nodes',
columns => 'ip',
distinct => 1,
})->ip_version(4);
my @ips = map {+{'ip' => $_}}
grep { is_nbtstatable( $_ ) }
$rs->get_column('ip')->all;
# Unless we have IPs don't bother
if (scalar @ips) {
my $now = 'to_timestamp('. (join '.', gettimeofday) .')';
my $resolved_nodes = nbtstat_resolve_async(\@ips);
# update node_nbt with status entries
foreach my $result (@$resolved_nodes) {
if (defined $result->{'nbname'}) {
store_nbt($result, $now);
}
}
}
return Status->done("Ended nbtstat for $host");
});
true;