简体   繁体   English

Python snmp OID 值

[英]Python snmp OID values

Im using this script to get memory and cpu statics我使用这个脚本来获取 memory 和 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]))

''' '''

I'm getting the following output我得到以下 output

响应值

However, I only need the actual values outputted that are in the far right, and save them as float or int values.但是,我只需要最右边输出的实际值,并将它们保存为 float 或 int 值。

you can repalce:您可以更换:

for varBind in varBinds:
        print(' = '.join([x.prettyPrint() for x in varBind]))

by经过

for oid, val in varBinds:
    print(oid.prettyPrint(),' = ', val.prettyPrint())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM