From a267efa3d8138e4a6b54f5585f19be423253626e Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 1 Sep 2019 18:39:22 +0100 Subject: [PATCH] only set layer if successful action --- .../Netdisco/Worker/Plugin/Arpnip/Nodes.pm | 33 +++++++++---------- .../Netdisco/Worker/Plugin/Macsuck/Nodes.pm | 5 +-- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/lib/App/Netdisco/Worker/Plugin/Arpnip/Nodes.pm b/lib/App/Netdisco/Worker/Plugin/Arpnip/Nodes.pm index 0c26bc82..91ba0303 100644 --- a/lib/App/Netdisco/Worker/Plugin/Arpnip/Nodes.pm +++ b/lib/App/Netdisco/Worker/Plugin/Arpnip/Nodes.pm @@ -34,10 +34,7 @@ register_worker({ phase => 'store' }, sub { debug sprintf ' [%s] arpnip - processed %s IPv6 Neighbor Cache entries', $device->ip, scalar @{ vars->{'v6arps'} }; - $device->update({ - last_arpnip => \$now, - layers => \[q{overlay(layers placing '1' from 6 for 1)}], - }); + $device->update({last_arpnip => \$now}); my $status = $job->best_status; return Status->$status("Ended arpnip for $device"); @@ -58,6 +55,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub { push @{ vars->{'v6arps'} }, @{get_arps_snmp($device, $snmp->ipv6_n2p_mac, $snmp->ipv6_n2p_addr) }; + $device->update({layers => \[q{overlay(layers placing '1' from 6 for 1)}]}); return Status->done("Gathered arp caches from $device"); }); @@ -85,24 +83,25 @@ sub get_arps_snmp { } register_worker({ phase => 'main', driver => 'cli' }, sub { - my ($job, $workerconf) = @_; + my ($job, $workerconf) = @_; - my $device = $job->device; - my $cli = App::Netdisco::Transport::SSH->session_for($device) - or return Status->defer("arpnip failed: could not SSH connect to $device"); + my $device = $job->device; + my $cli = App::Netdisco::Transport::SSH->session_for($device) + or return Status->defer("arpnip failed: could not SSH connect to $device"); - # should be both v4 and v6 - my @arps = @{ get_arps_cli($device, [$cli->arpnip]) }; + # should be both v4 and v6 + my @arps = @{ get_arps_cli($device, [$cli->arpnip]) }; - # cache v4 arp table - push @{ vars->{'v4arps'} }, - grep { NetAddr::IP::Lite->new($_->{ip})->bits == 32 } @arps; + # cache v4 arp table + push @{ vars->{'v4arps'} }, + grep { NetAddr::IP::Lite->new($_->{ip})->bits == 32 } @arps; - # cache v6 neighbor cache - push @{ vars->{'v6arps'} }, - grep { NetAddr::IP::Lite->new($_->{ip})->bits == 128 } @arps; + # cache v6 neighbor cache + push @{ vars->{'v6arps'} }, + grep { NetAddr::IP::Lite->new($_->{ip})->bits == 128 } @arps; - return Status->done("Gathered arp caches from $device"); + $device->update({layers => \[q{overlay(layers placing '1' from 6 for 1)}]}); + return Status->done("Gathered arp caches from $device"); }); sub get_arps_cli { diff --git a/lib/App/Netdisco/Worker/Plugin/Macsuck/Nodes.pm b/lib/App/Netdisco/Worker/Plugin/Macsuck/Nodes.pm index 99aa8165..029adb2a 100644 --- a/lib/App/Netdisco/Worker/Plugin/Macsuck/Nodes.pm +++ b/lib/App/Netdisco/Worker/Plugin/Macsuck/Nodes.pm @@ -92,10 +92,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub { debug sprintf ' [%s] macsuck - removed %d fwd table entries to archive', $device->ip, $archived; - $device->update({ - last_macsuck => \$now, - layers => \[q{overlay(layers placing '1' from 7 for 1)}], - }); + $device->update({last_macsuck => \$now}); return Status->done("Ended macsuck for $device"); });