From d264fb7d9d92e904d1b5e4d0ca0216497a1320cb Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 11 Jan 2014 13:57:45 +0000 Subject: [PATCH] Allow cached SNMP community hint to override SNMP version cycle --- Netdisco/Changes | 1 + Netdisco/lib/App/Netdisco/Util/SNMP.pm | 38 ++++++++++++++------------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index 2a00df1d..6fc99b6f 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -18,6 +18,7 @@ * Correct is_discoverable check in Undiscovered Neighbors report * Correct macsuck for Q-BRIDGE-MIB based devices + * Allow cached SNMP community hint to override SNMP version cycle 2.021000 - 2014-01-08 diff --git a/Netdisco/lib/App/Netdisco/Util/SNMP.pm b/Netdisco/lib/App/Netdisco/Util/SNMP.pm index bd2fe8a1..50e8971b 100644 --- a/Netdisco/lib/App/Netdisco/Util/SNMP.pm +++ b/Netdisco/lib/App/Netdisco/Util/SNMP.pm @@ -87,6 +87,16 @@ sub _snmp_connect_generic { $snmp_args{BulkWalk} = 0; } + # get the community string(s) + my @communities = _build_communities($device, $mode); + + # which SNMP versions to try and in what order + my @versions = + ( check_no($device->ip, 'snmpforce_v3') ? (3) + : check_no($device->ip, 'snmpforce_v2') ? (2) + : check_no($device->ip, 'snmpforce_v1') ? (1) + : (reverse (1 .. (setting('snmpver') || 3))) ); + # use existing or new device class my @classes = ('SNMP::Info'); if ($device->snmp_class) { @@ -96,30 +106,22 @@ sub _snmp_connect_generic { $snmp_args{AutoSpecity} = 1; } - # which SNMP versions to try and in what order - my @versions = - ( check_no($device->ip, 'snmpforce_v3') ? (3) - : check_no($device->ip, 'snmpforce_v2') ? (2) - : check_no($device->ip, 'snmpforce_v1') ? (1) - : (reverse (1 .. (setting('snmpver') || 3))) ); - - # get the community string(s) - my @communities = _build_communities($device, $mode); - my $info = undef; - VERSION: foreach my $ver (@versions) { - next unless $ver; + COMMUNITY: foreach my $comm (@communities) { + next unless $comm; - CLASS: foreach my $class (@classes) { - next unless $class; + VERSION: foreach my $ver (@versions) { + next unless $ver; - COMMUNITY: foreach my $comm (@communities) { - next if $ver eq 3 and exists $comm->{community}; - next if $ver ne 3 and !exists $comm->{community}; + next if $ver eq 3 and exists $comm->{community}; + next if $ver ne 3 and !exists $comm->{community}; + + CLASS: foreach my $class (@classes) { + next unless $class; my %local_args = (%snmp_args, Version => $ver); $info = _try_connect($device, $class, $comm, $mode, \%local_args); - last VERSION if $info; + last COMMUNITY if $info; } } }