From 34b4452f665e9f5372486c3699399de1fe44022d Mon Sep 17 00:00:00 2001 From: Neil Johnson <8146426+njohnsn@users.noreply.github.com> Date: Tue, 1 Feb 2022 12:59:37 -0600 Subject: [PATCH] fix undefined variable error on NXOS (#854) Only process entries with defined (IPv4/v6 address). Older code was bombing out here to undefiend entries for ip when process NXOS CLI arpnip. --- .../Netdisco/Worker/Plugin/Arpnip/Nodes.pm | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/App/Netdisco/Worker/Plugin/Arpnip/Nodes.pm b/lib/App/Netdisco/Worker/Plugin/Arpnip/Nodes.pm index 91ba0303..1e8efa41 100644 --- a/lib/App/Netdisco/Worker/Plugin/Arpnip/Nodes.pm +++ b/lib/App/Netdisco/Worker/Plugin/Arpnip/Nodes.pm @@ -92,13 +92,27 @@ register_worker({ phase => 'main', driver => 'cli' }, sub { # 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; + my $a_entry; + my $a_ip; + my $a_mac; - # cache v6 neighbor cache - push @{ vars->{'v6arps'} }, - grep { NetAddr::IP::Lite->new($_->{ip})->bits == 128 } @arps; + # should be both v4 and v6 + my @arps = @{ get_arps_cli($device, [$cli->arpnip]) }; + + foreach $a_entry (@arps) { + $a_ip = NetAddr::IP::Lite->new($a_entry->{ip}); + + if (defined($a_ip)) { + # IPv4 + if ($a_ip->bits == 32 ) { + push @{ vars->{"v4arps"} }, $a_entry; + } + # IPv6 + if ($a_ip->bits == 128 ) { + push @{ vars->{"v6arps"} }, $a_entry; + } + } + } $device->update({layers => \[q{overlay(layers placing '1' from 6 for 1)}]}); return Status->done("Gathered arp caches from $device");