0
我想弄清楚如何加载mib并获取思科交换机的sysObjectID,然后将其解析为人类可读的内容。现在我的代码可以工作,但是让我感到困惑的是getCmd()的参数,而不是使用OID发送字符串,我如何发送托管对象?pysnmp snmp获取托管对象
我怎么能更改以下线在我的代码
'1.3.6.1.2.1.1.2.0',
要像“sysObjectdID.0”,但作为一个管理对象
#!/bin/env python
from pysnmp.entity.rfc3413.oneliner import cmdgen
from pysnmp.smi import view
from pysnmp.smi.rfc1902 import ObjectType, ObjectIdentity
cmdGen = cmdgen.CommandGenerator()
print "Loading & Indexing MIB Modules..."
mibBuilder = cmdGen.snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder
mibPath = mibBuilder.getMibPath() + ('/Users/jeffrey.dambly/Documents/mibs',)
mibBuilder.setMibPath(*mibPath)
cmdGen.snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder.loadModules('CISCO-SMI', 'CISCO-PRODUCTS-MIB')
mibView = view.MibViewController(mibBuilder)
print 'Done'
#print 'MIB symbol name lookup by name: '
#oid, label, suffix = mibView.getNodeName((1, 3, 6, 1, 4, 1, 9, 1, 12))
#print oid, label, suffix
print 'Done'
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
cmdgen.CommunityData('xxxxxxxx'),
cmdgen.UdpTransportTarget(('192.168.8.10', 161)),
'1.3.6.1.2.1.1.2.0',
lookupNames=True,
lookupValues=True,
)
# Check for errors and print out results
if errorIndication:
print(errorIndication)
else:
if errorStatus:
print('%s at %s' % (
errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex)-1] or '?'
)
)
else:
for name, val in varBinds:
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))