From f3f55748b503b96080dfe7d92091459d75c7794e Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Wed, 8 Jan 2014 05:37:44 +0000 Subject: [PATCH] Support for snmpforce_v1, snmpforce_v2, snmpforce_v3 --- Netdisco/Changes | 1 + .../lib/App/Netdisco/Manual/Configuration.pod | 32 +++++++++++-------- Netdisco/lib/App/Netdisco/Util/Device.pm | 12 ++++--- Netdisco/lib/App/Netdisco/Util/SNMP.pm | 9 ++++-- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index 61348991..555d5390 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -11,6 +11,7 @@ * [#30] Support for expire_devices, expire_nodes, and expire_nodes_archive * Port Log viewable via an icon by device port name (Port Control rights req'd) * [#1] Subnet Utilization report (J. van Ingen) + * Support for snmpforce_v1, snmpforce_v2, snmpforce_v3 [ENHANCEMENTS] diff --git a/Netdisco/lib/App/Netdisco/Manual/Configuration.pod b/Netdisco/lib/App/Netdisco/Manual/Configuration.pod index a3c93bcb..ca22d841 100644 --- a/Netdisco/lib/App/Netdisco/Manual/Configuration.pod +++ b/Netdisco/lib/App/Netdisco/Manual/Configuration.pod @@ -388,7 +388,7 @@ of the device. The regex must match the complete value. =head3 C -Value: Numnber. Default: 20. +Value: Number. Default: 20. Sets the Net-SNMP C value, which is used on C operations. See L for more info. @@ -409,6 +409,24 @@ Value: C<1|2|3>. Default: 3. Highest version of the SNMP protocol used when connecting to devices. Use this setting to disable SNMP v3 globally. Usually you don't need to configure this. +=head3 C + +Value: List of Network Identifiers or Device Properties. Default: Empty List. + +Forces matching devices to use SNMPv1. + +=head3 C + +Value: List of Network Identifiers or Device Properties. Default: Empty List. + +Forces matching devices to use SNMPv2c. + +=head3 C + +Value: List of Network Identifiers or Device Properties. Default: Empty List. + +Forces matching devices to use SNMPv3. + =head3 C Value: Number. Default: 1000000. @@ -874,18 +892,6 @@ C =item * -C - -=item * - -C - -=item * - -C - -=item * - C =back diff --git a/Netdisco/lib/App/Netdisco/Util/Device.pm b/Netdisco/lib/App/Netdisco/Util/Device.pm index 0aaceae3..6ecae240 100644 --- a/Netdisco/lib/App/Netdisco/Util/Device.pm +++ b/Netdisco/lib/App/Netdisco/Util/Device.pm @@ -101,7 +101,8 @@ sub check_acl { =head2 check_no( $ip, $setting_name ) Given the IP address of a device, returns true if the configuration setting -C<$setting_name> matches that device, else returns false. +C<$setting_name> matches that device, else returns false. If the setting +is undefined or empty, then C also returns false. print "rejected!" if check_no($ip, 'discover_no'); @@ -133,15 +134,16 @@ sub check_no { my ($ip, $setting_name) = @_; my $config = setting($setting_name) || []; - return 0 unless scalar @$config; + return 0 if not scalar @$config; return check_acl($ip, $config); } =head2 check_only( $ip, $setting_name ) -Given the IP address of a device, returns false if the configuration setting -C<$setting_name> matches that device, else returns true. +Given the IP address of a device, returns true if the configuration setting +C<$setting_name> matches that device, else returns false. If the setting +is undefined or empty, then C also returns true. print "rejected!" unless check_only($ip, 'discover_only'); @@ -173,7 +175,7 @@ sub check_only { my ($ip, $setting_name) = @_; my $config = setting($setting_name) || []; - return 1 unless scalar @$config; + return 1 if not scalar @$config; return check_acl($ip, $config); } diff --git a/Netdisco/lib/App/Netdisco/Util/SNMP.pm b/Netdisco/lib/App/Netdisco/Util/SNMP.pm index 1bfdd965..bd2fe8a1 100644 --- a/Netdisco/lib/App/Netdisco/Util/SNMP.pm +++ b/Netdisco/lib/App/Netdisco/Util/SNMP.pm @@ -96,9 +96,12 @@ sub _snmp_connect_generic { $snmp_args{AutoSpecity} = 1; } - # TODO: add version force support - # use existing SNMP version or try 3, 2, 1 - my @versions = reverse (1 .. (setting('snmpver') || 3)); + # 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);