簡體   English   中英

Python snmp OID 值

[英]Python snmp OID values

我使用這個腳本來獲取 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]))

'''

我得到以下 output

響應值

但是,我只需要最右邊輸出的實際值,並將它們保存為 float 或 int 值。

您可以更換:

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

經過

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM