我正在尝试利用PySNMP查询HP Procurve交换机。到目前为止,我已通过mibdump.py将hpicfChassis.mib转换为HP-ICF-CHASSIS.py,并确认此MIB处于正确的路径中。我曾尝试过使用和不使用MibBuilder代码,但仍然遇到错误。HP Procurve上的PySNMP MIB查询不起作用
我试图在此MIB中查询hpicfSlotDescr的SNMP值,以及其他SNMP值,它只是与以下错误消息炸弹:
pysnmp.smi.error.SmiError:实例指数(0)至对象'hpicfSlotDescr'上的OID转换失败:ConstraintsIntersection(ConstraintsIntersection(ConstraintsIntersection(),ValueRangeConstraint(-2147483648,21247483647)),ValueRangeConstraint(1,16))失败:“ValueRangeConstraint(1,16)失败:”0“在Integer32
我已经完成了数据包捕获,并且当使用hpicfSlotDescr(最多可以返回6个值)时,SNMP查询从不会向交换机生成请求。
当查询不同的SNMP值(例如hpicfEntityIndex,期望1返回值)时,我看到请求已发出,但交换机从未回复。在脚本和交换机上的社区名称匹配,我只是迷失了,并想知道我想要完成的是否可行,如果是的话,我错过了哪些主要组件?
在此先感谢!
from pysnmp.hlapi import *
from pysnmp.smi import builder
#MIBDIR = '/Python/Lib/site-packages/pysnmp_mibs'
#mibBuilder = builder.MibBuilder()
#mibSources = mibBuilder.getMibSources() + (builder.DirMibSource(MIBDIR),)
#mibBuilder.setMibSources(*mibSources)
#mibBuilder.loadModules('HP-ICF-CHASSIS')
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
CommunityData('<comm name>', mpModel=1),
UdpTransportTarget(('<ipv4 address>', 161)),
ContextData(),
ObjectType(ObjectIdentity('HP-ICF-CHASSIS', 'hpicfSlotDescr', 0)))
)
if errorIndication:
print(errorIndication)
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
这是修复,非常感谢。 – RM092