diff --git a/lib/App/Netdisco/Util/SNMP.pm b/lib/App/Netdisco/Util/SNMP.pm index 2527ab38..0fad3d7f 100644 --- a/lib/App/Netdisco/Util/SNMP.pm +++ b/lib/App/Netdisco/Util/SNMP.pm @@ -172,6 +172,7 @@ sub snmp_comm_reindex { if ($ver == 3) { my $prefix = ''; my @comms = _build_communities($device, 'read'); + # find a context prefix configured by the user foreach my $c (@comms) { next unless $c->{tag} and $c->{tag} eq (eval { $device->community->snmp_auth_tag_read } || ''); @@ -182,14 +183,16 @@ sub snmp_comm_reindex { debug sprintf '[%s] reindexing to "%s%s" (ver: %s, class: %s)', $device->ip, $prefix, $vlan, $ver, $snmp->class; - $snmp->update(Context => ($prefix . $vlan)); + $vlan ? $snmp->update(Context => ($prefix . $vlan)) + : $snmp->update(Context => ''); } else { my $comm = $snmp->snmp_comm; debug sprintf '[%s] reindexing to vlan %s (ver: %s, class: %s)', $device->ip, $vlan, $ver, $snmp->class; - $snmp->update(Community => $comm . '@' . $vlan); + $vlan ? $snmp->update(Community => $comm . '@' . $vlan) + : $snmp->update(Community => $comm); } } diff --git a/lib/App/Netdisco/Worker/Plugin/Macsuck/Nodes.pm b/lib/App/Netdisco/Worker/Plugin/Macsuck/Nodes.pm index 836fcd80..3f73ca27 100644 --- a/lib/App/Netdisco/Worker/Plugin/Macsuck/Nodes.pm +++ b/lib/App/Netdisco/Worker/Plugin/Macsuck/Nodes.pm @@ -27,9 +27,6 @@ register_worker({ stage => 'check', driver => 'snmp' }, sub { my $now = 'to_timestamp('. (join '.', gettimeofday) .')'; my $total_nodes = 0; - # do this before we start messing with the snmp community string - my $guard = guard { }; # FIXME TODO reset snmp community - # cache the device ports to save hitting the database for many single rows my $device_ports = {map {($_->port => $_)} $device->ports(undef, {prefetch => {neighbor_alias => 'device'}})->all}; @@ -41,10 +38,14 @@ register_worker({ stage => 'check', driver => 'snmp' }, sub { # ...then per-vlan if supported my @vlan_list = get_vlan_list($device); - foreach my $vlan (@vlan_list) { - snmp_comm_reindex($snmp, $device, $vlan); - my $pv_fwtable = walk_fwtable($device, $interfaces, $port_macs, $device_ports, $vlan); - $fwtable = {%$fwtable, %$pv_fwtable}; + { + my $guard = guard { snmp_comm_reindex($snmp, $device, 0) }; + foreach my $vlan (@vlan_list) { + snmp_comm_reindex($snmp, $device, $vlan); + my $pv_fwtable = + walk_fwtable($device, $interfaces, $port_macs, $device_ports, $vlan); + $fwtable = {%$fwtable, %$pv_fwtable}; + } } # now it's time to call store_node for every node discovered