contrib: snmptest.pl SNMPwalk can't access to all variables/wrong sort

Large quantity of data will be missing when snmptest.pl is used.  The reason
is a sort in lexicographic order:

    $ snmpwalk -v2c -c public localhost .1.3.6.1.4.1.2021.250.255 |head
    iso.3.6.1.4.1.2021.250.255.2.1 = STRING:  "10.4.52.1"
    iso.3.6.1.4.1.2021.250.255.2.10 = STRING: "192.168.35.64"
    iso.3.6.1.4.1.2021.250.255.2.100 = STRING: "192.168.196.1"
    iso.3.6.1.4.1.2021.250.255.2.101 = STRING: "192.168.198.1"
    iso.3.6.1.4.1.2021.250.255.2.102 = STRING: "192.168.209.225"
    iso.3.6.1.4.1.2021.250.255.2.103 = STRING: "192.168.209.241"

SNMPGetNext after "root.2.1" should give "root.2.2".  Thus, lots of
variables are missing.

The function is now dependant on a CPAN module NetSNMP::OID, (debian/ubuntu
package is called libsnmp-perl).  This is probably not the most efficient
way to do it: walking the whole tree will be much slower.

Signed-off-by: Jean Benoit <jean@unistra.fr>
This commit is contained in:
Jean Benoit 2020-09-04 19:30:21 +01:00 committed by Sami Kerola
parent b005ce9a25
commit 0f19d44c1d
No known key found for this signature in database
GPG key ID: 0D46FEF7E61DBB46
2 changed files with 11 additions and 3 deletions

1
THANKS
View file

@ -48,3 +48,4 @@ Sebastián Cramatte
Mark Sangster
Brent Swingle
Mathieu Morier
Jean Benoit

View file

@ -23,9 +23,10 @@
# you set $dbg to 1 then output will be generated in /tmp.
use strict;
use NetSNMP::OID;
# Version info:
my $SNMPver = "snmp1.0";
my $SNMPver = "snmp1.1";
my $DHCPver = "dhcp1.0";
my $VERSION = "$SNMPver/$DHCPver";
#
@ -193,7 +194,7 @@ sub ParseDataFile () {
}
close IN;
if ($dbg) {
foreach (sort @validoidlist) { print DBG "ValidOID: $_\n"; }
foreach (sort Oidcmp @validoidlist) { print DBG "ValidOID: $_\n"; }
}
if ($dbg) {
@ -370,7 +371,7 @@ sub GetData ($) {
@userquery = split (/\./, $userqueryoid);
my $found = 0;
foreach (sort @validoidlist) {
foreach (sort Oidcmp @validoidlist) {
$next = $_;
print DBG "Comparing $userqueryoid vs. $_\n" if $dbg;
@validoid = split (/\./, $_);
@ -432,6 +433,12 @@ sub Pong {
$line = 0;
}
sub Oidcmp {
my $oida = new NetSNMP::OID($a);
my $oidb = new NetSNMP::OID($b);
snmp_oid_compare($oida, $oidb);
}
################################## START ##################################
#
# Main