McDarren has asked for the wisdom of the Perl Monks concerning the following question:
I strongly suspect that the answer to this may be a non-Perl one, but here goes anyway.
I am using Net::SNMP to retrieve configuration data from some remote devices. Some of the data that I am after is in the form of IP ranges, ie. a "starting IP" and an "ending IP".
To pull this data, I've written a small routine which I call each time I need to (once the net::snmp session is established). The routine is as follows:
sub get_ip_list { my $table_index = shift; my $oid = "$base_oid"."$oids{$version}".".$table_index"; my $table = $session->get_table( -baseoid => $oid, ); if (!defined $table) { my $err = $session->error; print "ERROR: $err\n"; return 0; } my $ips; for my $entry (sort keys %{$table}) { my $tail; ($tail = $entry) =~ s/^$oid//; if ($tail =~ m/^\.5\.1\.4\.(\d)/) { $ips->{$1}{start} = $table->{$entry}; } elsif ($tail =~ m/^\.5\.1\.6\.(\d)/) { $ips->{$1}{end} = $table->{$entry}; } } return $ips; }
The above is called as get_ip_list(n), where n represents the SNMP table index to use as a starting point. Mostly, it works fine. However, with certain table indexes the get_table() method returns undef, indicating an error. The error I get is:
ERROR: Received noError(0) error-status at error-index 1
Apart from the fact that I'm not really sure what that error means, I'm also a bit bewildered as to why it's failing in the first place. This is because if I do a manual snmpwalk (via command line) using the same starting OID - I get the expected result. An (edited) example looks something like this:
darren@monitor:~/nomadix> snmpwalk -v1 -c XXXXX B x.x.x.x 1.3.6.1.4.1. +3309.1.4.17 SNMPv2-SMI::enterprises.3309.1.4.17.1.0 = INTEGER: 1 SNMPv2-SMI::enterprises.3309.1.4.17.2.0 = INTEGER: 1 SNMPv2-SMI::enterprises.3309.1.4.17.3.0 = INTEGER: 1 SNMPv2-SMI::enterprises.3309.1.4.17.4.0 = INTEGER: 0 SNMPv2-SMI::enterprises.3309.1.4.17.5.1.2.1 = Counter32: 1 SNMPv2-SMI::enterprises.3309.1.4.17.5.1.4.1 = IpAddress: 61.115.200.69 SNMPv2-SMI::enterprises.3309.1.4.17.5.1.6.1 = IpAddress: 61.115.200.99 SNMPv2-SMI::enterprises.3309.1.4.17.5.1.10.1 = INTEGER: 1
However, when I use the above OID (1.3.6.1.4.1.3309.1.4.17) in my code with get_table() - it fails. I do suspect that this may be a bug in the SNMP implementation of the devices I am querying, but I guess it may also be a problem either with Net:SNMP or my code.
I've tried replacing the line:
with the hard-coded OID, however this gives the same result. And, as I mentioned above - it works fine with other OID's, so I don't really think the code is the problem.my $oid = "$base_oid"."$oids{$version}".".$table_index";
Can anybody offer any insight or advice?
Thanks,
Darren :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net:SNMP get_table() method failing
by monarch (Priest) on Oct 31, 2006 at 09:27 UTC | |
by McDarren (Abbot) on Oct 31, 2006 at 10:29 UTC | |
by monarch (Priest) on Oct 31, 2006 at 23:01 UTC |