diff --git a/lib/App/Netdisco/Worker/Plugin/Discover/Neighbors.pm b/lib/App/Netdisco/Worker/Plugin/Discover/Neighbors.pm index 86de75e3..613e402a 100644 --- a/lib/App/Netdisco/Worker/Plugin/Discover/Neighbors.pm +++ b/lib/App/Netdisco/Worker/Plugin/Discover/Neighbors.pm @@ -238,7 +238,6 @@ sub store_neighbors { # OK, remote IP seems sane $remote_ip = $r_netaddr->addr; - my $peer_device = get_device($remote_ip); # what we came here to do.... discover the neighbor debug sprintf ' [%s] neigh - %s with ID [%s] on %s', @@ -246,6 +245,9 @@ sub store_neighbors { push @to_discover, [$remote_ip, $remote_type, $remote_id]; $remote_port = $c_port->{$entry}; + my $peer_device = get_device($remote_ip); + my $peer_port = undef; + if (defined $remote_port) { # clean weird characters $remote_port =~ s/[^\d\s\/\.,()\w:-]+//gi; @@ -253,7 +255,7 @@ sub store_neighbors { # attempt to resolve port name when it is given wrong # https://github.com/netdisco/netdisco/issues/380 if ($peer_device and $peer_device->in_storage) { - my $peer_port = schema('netdisco')->resultset('DevicePort')->search({ + $peer_port = schema('netdisco')->resultset('DevicePort')->search({ ip => $peer_device->ip, port => [ {'=', $remote_port}, @@ -291,11 +293,6 @@ sub store_neighbors { port => $portrow->slave_of }); - my $peer_port = schema('netdisco')->resultset('DevicePort')->single({ - ip => $peer_device->ip, - port => $portrow->remote_port, - }); - if ($master and not ($portrow->is_master or defined $master->slave_of)) { $master->update({ remote_ip => ($peer_device->ip || $remote_ip),