Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

SNMP problems

by ribasushi (Monk)
on Sep 11, 2007 at 10:21 UTC ( #638272=perlquestion: print w/ replies, xml ) Need Help??
ribasushi has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks, I am trying to read the current mac address table of a cisco switch as in this example:
dominus@Arzamas:~$ snmpwalk -v 2c -c $SNMP_CO 192.168.58.254 1.3.6.1.2.1.17.4.3.1.1
SNMPv2-SMI::mib-2.17.4.3.1.1.0.1.230.83.2.208 = Hex-STRING: 00 01 E6 53 02 D0 
SNMPv2-SMI::mib-2.17.4.3.1.1.0.4.35.176.177.68 = Hex-STRING: 00 04 23 B0 B1 44 
SNMPv2-SMI::mib-2.17.4.3.1.1.0.7.233.149.143.23 = Hex-STRING: 00 07 E9 95 8F 17 
SNMPv2-SMI::mib-2.17.4.3.1.1.0.10.230.233.145.114 = Hex-STRING: 00 0A E6 E9 91 72 
SNMPv2-SMI::mib-2.17.4.3.1.1.0.10.230.234.38.175 = Hex-STRING: 00 0A E6 EA 26 AF 
SNMPv2-SMI::mib-2.17.4.3.1.1.0.16.220.252.120.239 = Hex-STRING: 00 10 DC FC 78 EF 
SNMPv2-SMI::mib-2.17.4.3.1.1.0.19.211.101.23.117 = Hex-STRING: 00 13 D3 65 17 75 
SNMPv2-SMI::mib-2.17.4.3.1.1.0.24.139.118.113.223 = Hex-STRING: 00 18 8B 76 71 DF 
SNMPv2-SMI::mib-2.17.4.3.1.1.0.24.139.118.117.77 = Hex-STRING: 00 18 8B 76 75 4D 
SNMPv2-SMI::mib-2.17.4.3.1.1.0.24.139.118.117.109 = Hex-STRING: 00 18 8B 76 75 6D 
SNMPv2-SMI::mib-2.17.4.3.1.1.0.24.139.118.117.124 = Hex-STRING: 00 18 8B 76 75 7C 
SNMPv2-SMI::mib-2.17.4.3.1.1.0.24.139.118.117.138 = Hex-STRING: 00 18 8B 76 75 8A 
SNMPv2-SMI::mib-2.17.4.3.1.1.0.24.139.124.36.250 = Hex-STRING: 00 18 8B 7C 24 FA 
SNMPv2-SMI::mib-2.17.4.3.1.1.0.24.139.127.68.159 = Hex-STRING: 00 18 8B 7F 44 9F 
SNMPv2-SMI::mib-2.17.4.3.1.1.0.32.237.139.16.188 = Hex-STRING: 00 20 ED 8B 10 BC 
SNMPv2-SMI::mib-2.17.4.3.1.1.0.192.240.105.142.190 = Hex-STRING: 00 C0 F0 69 8E BE 
SNMPv2-SMI::mib-2.17.4.3.1.1.0.224.76.136.97.150 = Hex-STRING: 00 E0 4C 88 61 96 
SNMPv2-SMI::mib-2.17.4.3.1.1.0.224.76.186.184.231 = Hex-STRING: 00 E0 4C BA B8 E7 
dominus@Arzamas:~$ 
Here is the code I have so far
my $snmp = SNMP::Session->new ( DestHost => $switchaddr, Community => $community, Version => '2c', RemotePort => $port, ) or die "Unable to connect to $switchaddr:$port\n"; print Dumper ($snmp->gettable ('.1.3.6.1.2.1.17.4.3.1.1'));
and it bombs like this:
STORE(SNMP::MIB=HASH(0x84c5050) mib-2.17.4.3.1.1 HASH(0x8435700)) : write access to the MIB not implemented
Modification of non-creatable array value attempted, subscript -1 at /usr/lib/perl5/SNMP.pm line 695.
If however I use a less obscure OID (e.g. ifTable) - everything works as expected. Can someone help me with this?

Thank you! UPDATE: append missing leading dot to the OID

Comment on SNMP problems
Download Code
Re: SNMP problems
by andyford (Curate) on Sep 11, 2007 at 13:58 UTC
    What kind of switches have this table? I tried a 6506 and got
    $VAR1 = {};

    non-Perl: Andy Ford

      In my case it is a 2950, but any switch supporting Bridge-MIB should have it as listed here
      What I am querying seems to be this
Re: SNMP problems
by talexb (Canon) on Sep 11, 2007 at 18:54 UTC

    I'm not familiar with this equipment, or with the module, but how about getting the result back from $snmp->gettable, putting it in a variable, and then dumping the variable?

    You should get a better idea of what's going on at that point.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

      The call
      $snmp->gettable ('1.3.6.1.2.1.17.4.3.1.1');
      itself causes the exception mentioned in the original post. The Dumper call is just there in case it works, but the exception happens in gettable().
Re: SNMP problems
by andyford (Curate) on Sep 11, 2007 at 20:40 UTC

    Can you show all your code or at least a working subset? I am having trouble duplicating your results: I get the same empty result set with the mac table or ifTable and I never get the error message.

    non-Perl: Andy Ford

      Here is my complete test script:
      #!/usr/bin/perl use warnings; use strict; use SNMP; use Data::Dumper; $Data::Dumper::Useqq = 1; my $switchaddr = '<SET_ME>'; my $community = '<SET_ME>'; my $snmp = SNMP::Session->new ( DestHost => $switchaddr, Community => $community, Version => '2c', ) or die "Unable to connect to $switchaddr\n"; for my $oid (qw/ .1.3.6.1.2.1.2.2 .1.3.6.1.2.1.17.4.3.1.1 /) { print "\nTrying snmpwalk on $oid\n=========================\n"; print scalar `snmpwalk -O n -v 2c -c $community $switchaddr $oid`; print "\nTrying SNMP->gettable on $oid\n=========================\ +n"; my $response; eval { $response = $snmp->gettable ($oid) }; if ($@) { print "FAILED: $@\n"; } else { print Dumper $response; } }

      and here is the result.

        Wow, ran your code and still got no results from gettable() for either OID but my snmpwalk results look great. I'm using perl 5.8.5 and SNMP 5.1.2 on Linux. How 'bout you?

        Update: fixed version and module name

        non-Perl: Andy Ford

      On reading my original posting I realized that I omitted a leading '.' when pasting things around. Sorry about that.
Re: SNMP problems
by andyford (Curate) on Sep 12, 2007 at 17:45 UTC
      I reported a bug with a new test script here. Can you run it on your end and confirm my results? Much appreciated. As far as my current problem - I'll just Net::SNMP. Thanks for the help!

        Great bug report! I get the same results as always, with Net::SNMP perfect and SNMP's output empty of results.

        non-Perl: Andy Ford

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://638272]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (13)
As of 2014-09-30 11:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (364 votes), past polls