http://qs321.pair.com?node_id=852162

spickles has asked for the wisdom of the Perl Monks concerning the following question:

This may not necessarily be perl related per se, but I'm hoping someone knows enough about SNMP to help anyways as I'm sure I'm not implementing the Net::SNMP get_bulk_request properly. If I use my MIB walk via SolarWinds, I get a tree that represents all of the MAC addresses of the APs connected to the controller. I see an OID that represents the AP MAC address in general, but each MAC address has additional OID digits that are added on to show each individual record. So if I try to enter the root OID that is common to each AP, I get an error that states that there is noSuchInstance. This behavior goes away when I input the OID for a particular AP. So how does my SolarWinds program walk the MIB successfully, yet I cannot perform the same function with Net::SNMP? A couple of the OIDs are as follows:

Root OID: 1.3.6.1.4.1.9.9.513.1.1.1.1.2
AP Specific OID: 1.3.6.1.4.1.9.9.513.1.1.1.1.2.0.23.223.167.189.192

So I'm hoping someone can tell me either what it is about how SNMP works that I don't understand, or what it is about my code that doesn't work to grab all of the MAC addresses for my APs. Code is below:

Thanks,
Scott
#!c:/perl/bin/perl use strict; use warnings; use Net::SNMP; #my $OID = '1.3.6.1.4.1.9.9.513.1.1.1.1.2.0.23.223.167.189.192'; my $OID = ("1.3.6.1.4.1.9.9.513.1.1.1.1.2"); my ($session, $error) = Net::SNMP->session( -hostname => '172.16.0.2', -version => 'snmpv2c', -community => 'private' ); if (!defined $session) { printf "ERROR: %s.\n", $error; exit 1; } my $result = $session->get_request(-varbindlist => [ $OID ],); #my $result = $session->get_bulk_request(-varbindlist => [ \@OID ],); if (!defined $result) { printf "ERROR: %s.\n", $session->error(); $session->close(); exit 1; } #print "$result->{$OID}\n"; foreach my $key ( sort keys %$result ) { print "$key => $$result{$key}\n"; } $session->close();

Replies are listed 'Best First'.
Re: Net::SNMP get_bulk_request Not Working
by Corion (Pope) on Jul 30, 2010 at 20:31 UTC

      It's the same code, but different issues. Khen suggested I turn on debugging for the no response issue, which appears to be host specific. For that, I'll put a sniffer on the wire as you suggest, but I'm not good at reading those. I think my current problem with why Net::SNMP doesn't do what I want is the following:

      SolarWinds will do a MIB walk, starting on the branch OID that I specified and I'm assuming that's how it 'discovers' the other device specific OIDs. What I'm trying to do with Net::SNMP is essentially the same thing, but I now understand that the get_request and get_bulk_request methods are for known OIDs rather than a MIB walk. So it may turn out that Net::SNMP can't do a MIB walk? At this point I don't understand enough of the module to know for sure. I'll keep working on it and hopefully people will post back with other useful pointers for me.

      Regards,
      Scott
        Actually, it does mibwalk. There's an example script in the examples directory. See: snmpwalk.pl.

        The general idea: SNMP v1 has set, get, get_next. set($oid,$value); ($oid, $value) = get($oid); ($oid, $value) = get_next($root). For the set, get you a full OID leaf value, for the get_next you can use either any OID value because get_next returns the next available OID in the MIB after the one you gave it. So if you have a tree like:

        1.2.1.1.0 = 42
        1.2.1.1.1 = 43
        1.2.1.1.3 = 44
        1.2.1.2.0 = 'a'
        1.2.1.2.1 = 'b'
        1.2.1.2.3 = 'c'
        
        get(1.2.1.1) -> error
        get_next(1.2.1.1) -> (1.2.1.1.0, 42)
        get_next(1.2.1.1.0) -> (1.2.1.1.1, 43)
        ...
        get_next(1.2.1.1.3) -> 1.2.1.2.0, 'a)
        ...
        get_next(1.2.1.2.3) -> 1.2.1.3.something, something)
        

        A walk just does a get_next over and over until the returned OID is outside of the tree root you gave it to start with. In this case if you started with 1.2.1.1 it would stop at 1.2.1.1.3 and not give you 1.2.1.2 and later.

        A get_table is just a wrapper that walks multiple tree roots at the same time, e.g. get_table(1.2.1.1, 1.2.1.2) would return all six of the above values.

        SNMP v2c and v3 have the bulk versions of these, they can just request/get multiple OIDs in the same data packet rather than doing a get_next for each OID in turn.

        IIRC, the Net::SNMP module returns everything in a hash reference. The SNMP module for the net-snmp library returns VarBind objects (array references) and will return a get_table in columns like:

        [
         [ 1.2.1.1.0, 42,  1.2.1.2.0, 'a' ],
         [ 1.2.1.1.1, 43,  1.2.1.2.1, 'b' ],
        ]
        

        This is by no means a detailed description, method names, signatures, returns, details differ depending on which SNMP module you're using, and which version of SNMP you're using to communicate with the device. But it all pretty much breaks down to set, get, get_next.