【发布时间】:2016-11-02 19:33:20
【问题描述】:
我正在尝试使用 PySNMP 来查询 HP Procurve 交换机。到目前为止,我已通过 mibdump.py 将 hpicfChassis.mib 转换为 HP-ICF-CHASSIS.py,并确认此 MIB 位于正确的路径中。我已经尝试过使用和不使用 MibBuilder 代码,但仍然有很多错误。
我正在尝试查询 hpicfSlotDescr 的 SNMP 值,以及此 MIB 中的其他 SNMP 值,它只是用以下错误消息进行轰炸:
pysnmp.smi.error.SmiError:对象“hpicfSlotDescr”处的实例索引 (0,) 到 OID 转换失败:ConstraintsIntersection(ConstraintsIntersection(ConstraintsIntersection(), ValueRangeConstraint(-2147483648, 2147483647)), ValueRangeConstraint(1, 16) ) 失败于:“ValueRangeConstraint(1, 16) 失败于:Integer32 处的“0””
我已经完成了一个数据包捕获,当使用最多可以返回六个值的 hpicfSlotDescr 时,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]))
【问题讨论】:
标签: pysnmp