[#73] NetBIOS Poller - nbtstat and nbtwalk

This commit is contained in:
Eric A. Miller
2014-02-03 19:54:58 -05:00
parent 652bd171d6
commit 5847dafb6d
19 changed files with 547 additions and 11 deletions

View File

@@ -22,8 +22,10 @@ sub capacity_for {
debug "checking local capacity for action $action";
my $action_map = {
Poller => [qw/discoverall discover arpwalk arpnip macwalk macsuck expiry/],
Interactive => [qw/location contact portcontrol portname vlan power/],
Poller => [
qw/discoverall discover arpwalk arpnip macwalk macsuck nbtstat nbtwalk expiry/
],
Interactive => [qw/location contact portcontrol portname vlan power/],
};
my $role_map = {

View File

@@ -13,7 +13,7 @@ my $fqdn = hostfqdn || 'localhost';
my $role_map = {
(map {$_ => 'Poller'}
qw/discoverall discover arpwalk arpnip macwalk macsuck expiry/),
qw/discoverall discover arpwalk arpnip macwalk macsuck nbtstat nbtwalk expiry/),
(map {$_ => 'Interactive'}
qw/location contact portcontrol portname vlan power/)
};

View File

@@ -10,6 +10,7 @@ with 'App::Netdisco::Daemon::Worker::Common';
with 'App::Netdisco::Daemon::Worker::Poller::Device',
'App::Netdisco::Daemon::Worker::Poller::Arpnip',
'App::Netdisco::Daemon::Worker::Poller::Macsuck',
'App::Netdisco::Daemon::Worker::Poller::Nbtstat',
'App::Netdisco::Daemon::Worker::Poller::Expiry';
sub worker_type { 'pol' }

View File

@@ -88,4 +88,80 @@ sub _single_body {
return job_done("Ended $job_type for ". $host->addr);
}
# _walk_nodes_body
# Queue a job for all active nodes that have been seen in the last
# configured days.
#
sub _walk_nodes_body {
my ($self, $job_type) = @_;
my $action_method = $job_type .'_action';
my $job_action = $self->$action_method;
my $jobqueue = schema('netdisco')->resultset('Admin');
my $rs = schema('netdisco')->resultset('NodeIp')
->search({ip => { -not_in =>
$jobqueue->search({
device => { '!=' => undef},
action => $job_type,
status => { -like => 'queued%' },
})->get_column('device')->as_query
}, -bool => 'active'});
my $ip_version = $job_type .'_ip_version';
my $job_ip_ver = $self->$ip_version;
if ($job_ip_ver) {
$rs = $rs->ip_version($job_ip_ver)
}
my $config_max_age = $job_type . '_max_age';
my $max_age = setting($config_max_age);
if ($max_age) {
my $interval = "$max_age day";
$rs = $rs->search(
{ time_last => \[ '>= now() - ?::interval', $interval ] } );
}
my @nodes = $rs->get_column('ip')->all;
my $filter_method = $job_type .'_filter';
my $job_filter = $self->$filter_method;
my @filtered_nodes = grep {$job_filter->($_)} @nodes;
schema('netdisco')->resultset('Admin')->txn_do_locked(sub {
$jobqueue->populate([
map {{
device => $_,
action => $job_type,
status => 'queued',
}} (@filtered_nodes)
]);
});
return job_done("Queued $job_type job for all nodes");
}
sub _single_node_body {
my ($self, $job_type, $job) = @_;
my $action_method = $job_type .'_action';
my $job_action = $self->$action_method;
my $host = NetAddr::IP::Lite->new($job->device);
my $filter_method = $job_type .'_filter';
my $job_filter = $self->$filter_method;
unless ($job_filter->($host->addr)) {
return job_defer("$job_type deferred: $host is not ${job_type}able");
}
$job_action->($host->addr);
return job_done("Ended $job_type for ". $host->addr);
}
1;

View File

@@ -0,0 +1,18 @@
package App::Netdisco::Daemon::Worker::Poller::Nbtstat;
use App::Netdisco::Core::Nbtstat 'do_nbtstat';
use App::Netdisco::Util::Node 'is_nbtstatable';
use Role::Tiny;
use namespace::clean;
with 'App::Netdisco::Daemon::Worker::Poller::Common';
sub nbtstat_action { \&do_nbtstat }
sub nbtstat_filter { \&is_nbtstatable }
sub nbtstat_ip_version { 4 }
sub nbtwalk { (shift)->_walk_nodes_body('nbtstat', @_) }
sub nbtstat { (shift)->_single_node_body('nbtstat', @_) }
1;

View File

@@ -14,10 +14,10 @@ my $jobactions = {
discoverall
arpwalk
macwalk
nbtwalk
expiry
/
# saveconfigs
# nbtwalk
# backup
};