Asynchronous NBTstat

This commit is contained in:
Eric A. Miller
2014-07-20 21:51:20 -04:00
parent b86ff6580e
commit e7803caa59
7 changed files with 381 additions and 47 deletions

View File

@@ -3,7 +3,7 @@ package App::Netdisco::Daemon::Worker::Poller::Nbtstat;
use Dancer qw/:moose :syntax :script/;
use Dancer::Plugin::DBIC 'schema';
use App::Netdisco::Core::Nbtstat 'do_nbtstat';
use App::Netdisco::Core::Nbtstat qw/nbtstat_resolve_async store_nbt/;
use App::Netdisco::Util::Node 'is_nbtstatable';
use App::Netdisco::Util::Device qw/get_device is_discoverable/;
use App::Netdisco::Daemon::Util ':all';
@@ -33,7 +33,7 @@ sub nbtstat {
}
# get list of nodes on device
my $interval = (setting('nbt_max_age') || 7) . ' day';
my $interval = (setting('nbtstat_max_age') || 7) . ' day';
my $rs = schema('netdisco')->resultset('NodeIp')->search({
-bool => 'me.active',
-bool => 'nodes.active',
@@ -46,10 +46,25 @@ sub nbtstat {
})->ip_version(4);
my @nodes = $rs->get_column('ip')->all;
my $now = 'to_timestamp('. (join '.', gettimeofday) .')';
$self->_single_node_body('nbtstat', $_, $now)
for @nodes;
# Unless we have IP's don't bother
if (scalar @nodes) {
# filter exclusions from config
@nodes = grep { is_nbtstatable( $_ ) } @nodes;
# setup the hash nbtstat_resolve_async expects
my @ips = map {+{'ip' => $_}} @nodes;
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 job_done("Ended nbtstat for ". $host->addr);
}