当我试图加载时,我一直在PySNMP构建器中得到这个错误。下面的代码适用于我到目前为止尝试过的所有其他mibs,但是这个已经被卡住了。这也是我第一次尝试遍历整个表(rttMonStats),所以我可能只是做错了。以下是我所做的:
我下载了Version 2列这里:http://tools.cisco.com/Support/SNMP/do/BrowseMIB.do?local=en&mibName=CISCO-RTTMON-MIB下的所有文件
标记为“非思科MIB”的那些,我在网上找到了一个搜索“下载MIB_NAME”的网站。我在build mib中运行了其中的每一个,比如:
build-pysnmp-mib MIB_NAME.my > MIB_NAME.py.
然后,我将所有*.py文件复制到/opt/appname/mib/
下面是snmpcommands.py中相关的def:
def walk(community, ipaddress, mib, oid, index):
cmdGen = cmdgen.CommandGenerator()
mibBuilder = cmdGen.snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder
mibSources = mibBuilder.getMibSources() + (
builder.DirMibSource('/opt/appname/mibs'),
)
mibBuilder.setMibSources(*mibSources)
mibBuilder.loadModules()
errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
cmdgen.CommunityData(community, mpModel=0),
cmdgen.UdpTransportTarget((ipaddress, 161)),
cmdgen.MibVariable(mib, oid, index),
lookupValues=True, lookupNames=True
)
if errorIndication:
print(errorIndication)
else:
if errorStatus:
print('%s at %s' % (
errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex)-1] or '?'
)
)
else:
result = {}
for tableRow in varBindTable:
for oid, val in tableRow:
result[oid.prettyPrint()] = val.prettyPrint()
return json.dumps(result)
我称之为:
>>>import snmpcommands
>>>snmpcommands.walk('community', 'ip.add.ress', 'CISCO-RTTMON-MIB', 'rttMonStats', '0.0.0.0')
然而,我明白这一点:
>>> snmpcommands.walk('community', 'ip.add.ress', 'CISCO-RTTMON-MIB', 'rttMonStats', '0.0.0.0')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "snmpcommands.py", line 57, in walk
mibBuilder.loadModules()
File "/usr/lib/python2.6/site-packages/pysnmp-4.2.4-py2.6.egg/pysnmp/smi/builder.py", line 251, in loadModules
'MIB module \"%s\" load error: %s' % (modPath, sys.exc_info()[1])
pysnmp.smi.error.SmiError: MIB module "/opt/appname/mibs/CISCO-RTTMON-MIB.py" load error: ConstraintsIntersection(ConstraintsIntersection(ConstraintsIntersection(ConstraintsIntersection(), ValueSizeConstraint(0, 65535)), ValueSizeConstraint(0, 255)), ValueSizeConstraint(1, 64)) failed at: "ValueSizeConstraint(1, 64) failed at: """ at SnmpAdminString
我对PySNMP非常陌生,所以我猜想问题是它期望从SNMP MIB中提取一个值,并且它是空的。我只是不知道怎么解决。
发布于 2013-08-22 02:51:42
看起来,在CISCO-RTTMON-MIB.py中有一个空字符串作为SnmpAdminString("")初始化器。这似乎违反了最终导致异常的SnmpAdminString约束。因此,对于空的SnmpAdminString初始化器,我会使用grepcisco-RTTMON-MIB.py,或者用一个兼容的值(1-64八进制)替换它们,或者只是删除空的初始化器(例如,使其看起来像SnmpAdminString())。
https://stackoverflow.com/questions/18337771
复制相似问题