pysnmp
pysnmp copied to clipboard
Not returning correct MIB for sysObjectID OID
trafficstars
Consider the following block of code:
from pysnmp.smi import builder, view, compiler, error, instrum
from pysnmp.proto.rfc3412 import MsgAndPduDispatcher
from pysnmp.hlapi import *
mib_builder = builder.MibBuilder()
mib_builder.addMibSources(builder.DirMibSource('/path/to/compiled/mibs/'))
engine = SnmpEngine(msgAndPduDsp=MsgAndPduDispatcher(mibInstrumController=instrum.MibInstrumController(mib_builder)))
oid = ObjectIdentity("SNMPv2-MIB", "sysObjectID")
for (errorIndication,
errorStatus,
errorIndex,
varBinds) in nextCmd(
self.engine,
CommunityData('public', mpModel=1),
UdpTransportTarget(('192.168.0.222', 161)),
ContextData(),
ObjectType(oid),
lexicographicMode=False
):
if errorIndication:
print(errorIndication)
break
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
break
else:
for varBind in varBinds:
print(varBind)
It should return correct MIB for sysObjectID. But it returns,
SNMPv2-MIB::sysObjectID.0 = SNMPv2-SMI::enterprises.9.1.1047
then I tried,
for varBind in varBinds:
print(varBind)
if type(varBind[1]) == type(oid):
_oid, label, suffix = view.MibViewController(mib_builder).getNodeName(varBind[1].getOid())
print(_oid, label, suffix)
which returns
SNMPv2-MIB::sysObjectID.0 = SNMPv2-SMI::enterprises.9.1.1047
1.3.6.1.4.1 ('iso', 'org', 'dod', 'internet', 'private', 'enterprises') 9.1.1047
The correct MIB resides in CISCO-PRODUCTS-MIB and I have it compiled.
So, what can I do to get correct MIB for sysObjectID?
I can reproduce this issue and a workaround is to add a call to force load the Cisco module,
mib_builder.loadModule('CISCO-PRODUCTS-MIB')
But about why PySNMP does not load the module automatically, more investigation is required.