【发布时间】:2020-09-10 16:09:31
【问题描述】:
我正在使用这个脚本来获取内存和 cpu 静态数据
'''
from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
CommunityData('public', mpModel=0),
UdpTransportTarget(('demo.snmplabs.com', 3161)),
ContextData(),
ObjectType(ObjectIdentity('1.3.6.1.4.1.2021.4.6.0')),
ObjectType(ObjectIdentity('1.3.6.1.4.1.2021.11.10.0')),
ObjectType(ObjectIdentity('1.3.6.1.4.1.2021.10.1.3.3')))
)
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]))
'''
我得到以下输出
但是,我只需要输出最右边的实际值,并将它们保存为 float 或 int 值。
【问题讨论】:
-
根据您的代码,
varBind可能是一个列表,第二项是您想要的值。 -
你说的完全正确,感谢它。
标签: python python-3.x snmp pysnmp mib