blib/lib/App/Netdisco/Worker/Plugin/Nbtstat/Core.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 7 Podpod n/a totaltotal 0.0% 0 / 55 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package App::Netdisco::Worker::Plugin::Nbtstat::Core;
2  
3 use Dancer ':syntax';
4 use App::Netdisco::Worker::Plugin;
5 use aliased 'App::Netdisco::Worker::Status';
6  
7 use App::Netdisco::Util::Nbtstat qw/nbtstat_resolve_async store_nbt/;
8 use App::Netdisco::Util::Node 'is_nbtstatable';
9 use Dancer::Plugin::DBIC 'schema';
10 use Time::HiRes 'gettimeofday';
11  
12 register_worker({ phase => 'main' }, sub {
13 my ($job, $workerconf) = @_;
14 my $host = $job->device->ip;
15  
16 # get list of nodes on device
17 my $interval = (setting('nbtstat_max_age') || 7) . ' day';
18 my $rs = schema('netdisco')->resultset('NodeIp')->search({
19 -bool => 'me.active',
20 -bool => 'nodes.active',
21 'nodes.switch' => $host,
22 'me.vrf' => '',
23 'me.time_last' => \[ '>= LOCALTIMESTAMP - ?::interval', $interval ],
24 },{
25 join => 'nodes',
26 columns => 'ip',
27 distinct => 1,
28 })->ip_version(4);
29  
30 my @ips = map {+{'ip' => $_}}
31 grep { is_nbtstatable( $_ ) }
32 $rs->get_column('ip')->all;
33  
34 # Unless we have IPs don't bother
35 if (scalar @ips) {
36 my $now = 'to_timestamp('. (join '.', gettimeofday) .')::timestamp';
37 my $resolved_nodes = nbtstat_resolve_async(\@ips);
38  
39 # update node_nbt with status entries
40 foreach my $result (@$resolved_nodes) {
41 if (defined $result->{'nbname'}) {
42 store_nbt($result, $now);
43 }
44 }
45 }
46  
47 return Status->done("Ended nbtstat for $host");
48 });
49  
50 true;