我要从Power NET MIB中检索memSensorsTemperature和memSensorsHumidity的值。我不确定我是否需要打两次电话,或者是否有一个单一的电话只是为了剔除我需要的特定OID的方法。当我在一个调用中同时包含这两个调用时,它看起来像是在做某种嵌套的操作
每个OID调用中有6个值。。。所以6个温度和6个嗡嗡声读数
#!/usr/bin/env python
from pysnmp.hlapi import *
result1 = bulkCmd(SnmpEngine(),
CommunityData('public'),
UdpTransportTarget(('xx.xx.xx.xx', 161)),
ContextData(),
1, 6,
ObjectType(
ObjectIdentity('PowerNet-MIB', 'memSensorsTemperature').addAsn1MibSource('http://mibs.snmplabs.com/asn1/@mib@')
),
ObjectType(
ObjectIdentity('PowerNet-MIB', 'memSensorsHumidity').addAsn1MibSource('http://mibs.snmplabs.com/asn1/@mib@')
),
lexicographicMode=False
)
#errorIndication, errorStatus, errorIndex, varBinds = next()
#memSensorsTemperature
for errorIndication, errorStatus, errorIndex, varBinds in result1:
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]))
结果(截断)
PowerNet-MIB::memSensorsHumidity.0.1 = 16
PowerNet-MIB::memSensorsTemperature.0.1 = 81
PowerNet-MIB::memSensorsHumidity.0.2 = 56
PowerNet-MIB::memSensorsTemperature.0.1 = 81
PowerNet-MIB::memSensorsHumidity.0.3 = 16
PowerNet-MIB::memSensorsTemperature.0.1 = 81
PowerNet-MIB::memSensorsHumidity.0.4 = 41
PowerNet-MIB::memSensorsTemperature.0.1 = 81
PowerNet-MIB::memSensorsHumidity.0.5 = 46
PowerNet-MIB::memSensorsTemperature.0.1 = 81
PowerNet-MIB::memSensorsHumidity.0.6 = -1
PowerNet-MIB::memSensorsTemperature.0.2 = 80
PowerNet-MIB::memSensorsHumidity.0.6 = No more variables left in this MIB View
PowerNet-MIB::memSensorsTemperature.0.2 = 80
PowerNet-MIB::memSensorsHumidity.0.6 = No more variables left in this MIB View
PowerNet-MIB::memSensorsTemperature.0.2 = 80
PowerNet-MIB::memSensorsHumidity.0.6 = No more variables left in this MIB View
PowerNet-MIB::memSensorsTemperature.0.2 = 80
PowerNet-MIB::memSensorsHumidity.0.6 = No more variables left in this MIB View
PowerNet-MIB::memSensorsTemperature.0.2 = 80
PowerNet-MIB::memSensorsHumidity.0.6 = No more variables left in this MIB View
PowerNet-MIB::memSensorsTemperature.0.2 = 80
PowerNet-MIB::memSensorsHumidity.0.6 = No more variables left in this MIB View```
你的代码似乎几乎正确!您只需要将nonRepeaters值设置为
0
,而不是1
。因为使用1
,您的第一个对象(memSensorsTemperature
)不会被迭代-它只是重新读取相同的表条目代码方面:
响应将始终是一个包含0到6行的二维表(取决于响应中的内容)
RFC1905解释了
nonRepeaters
的语义:相关问题 更多 >
编程相关推荐