Using pysnmp, how you perform resolution on queries that return an OID instead of value?
I wrote a lookup tool using pysnmp, here are the inputs and results :
./run_snmp_discovery.py --host 1.1.1.1 --community XXXXXX --command get --mib_oid_index '{ "mib" : "SNMPv2-MIB", "oid" : "sysObjectID", "index" : "0" }' --verbose
Debug: 'varBind': SNMPv2-MIB::sysObjectID.0 = SNMPv2-SMI::enterprises.9.1.222
{"0": {"sysObjectID": "SNMPv2-SMI::enterprises.9.1.222"}}
How can the result be converted to the text value cisco7206VXR
(reference http://www.circitor.fr/Mibs/Html/C/CISCO-PRODUCTS-MIB.php#cisco7206VXR)
If you are using code like this:
from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
CommunityData('public'),
UdpTransportTarget(('demo.pysnmp.com', 161)),
ContextData(),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)))
)
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
And you want MIB object to be represented as an OID, then the varBind
in the code above is actually an ObjectType class instance which behaves like a tuple of two elements. The first element is ObjectIdentity which has the .getOid method:
>>> objectIdentity = ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)
>>> objectIdentity.resolveWithMib(mibViewController)
>>> objectIdentity.getOid()
ObjectName('1.3.6.1.2.1.1.1.0')
If you want MIB object and its value to be fully represented in MIB terms (i.e. value resolved into an enumeration), then you just need to load the MIB that defines that MIB object (perhaps, CISCO-PRODUCTS-MIB) using .loadMibs() method. You might also need to set up a search path to let pysnmp find the MIB you refer.