Request a numeric OID in PySNMP?

I am trying to query an SNMP variable on a Cisco routing device in Python and am struggling.

I have a snmpwalk command that works fine:

$snmpwalk -v2c -c <our_community_string> <device_ip_address> 1.3.6.1.4.1.9.9.42.1.2.10.1.1.950 SNMPv2-SMI::enterprises.9.9.42.1.2.10.1.1.950 = Gauge32: 68 

Now I am trying to do the same in Python using pysnmp.

I tried using something based on examples here - http://pysnmp.sourceforge.net/examples/current/index.html - but got a SmiError:

 In [1]: from pysnmp.entity.rfc3413.oneliner import cmdgen In [2]: cmdGen = cmdgen.CommandGenerator() In [3]: errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd( ...: cmdgen.CommunityData('0pe3aro'), ...: cmdgen.UdpTransportTarget(('10.65.113.28', 161)), ...: cmdgen.MibVariable('1.3.6.1.4.1.9.9.42.1.2.10.1.1.950', 0) ...: ) 

But I get the following:

 SmiError: MIB file "1.3.6.1.4.1.9.9.42.1.2.10.1.1.950.py[co]" not found in search path 

Basically - I wanted it to be in NetSNMP, but in PySNMP ( http://ben.akrin.com/?p=1234 ).

Does anyone know an easy way to request a numeric OID in PySNMP?

Cheers, Victor

+6
source share
1 answer

I believe the following code will work for you:

 from pysnmp.entity.rfc3413.oneliner import cmdgen cmdGen = cmdgen.CommandGenerator() errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd( cmdgen.CommunityData('public'), cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)), '1.3.6.1.2.1.1.3.0' ) print('\n'.join([ '%s = %s' % varBind for varBind in varBinds])) 

You can cut and paste it into your Python tooltip to try and experiment with it.

The MibVariable object can be used to access the MIB symbol by name.

+4
source

All Articles