简体   繁体   English

具有PYSNMP F5 ltm的Python SNMP

[英]Python SNMP with PYSNMP F5 ltm

I'am new in this thing, 我是这方面的新手,

When I run the following command: 当我运行以下命令时:

snmpwalk -v2c -c public localhost .1.3.6.1.4.1.3375.2.2.5.6.2.1.6

in my F5 LTM I get all my nodes, pools and state like this: 在我的F5 LTM中,我得到了所有的节点,池和状态,如下所示:

F5-BIGIP-LOCAL-MIB::ltmPoolMbrStatusEnabledState."/Common/pool-cnv-proc-financeiro-processamento-was-9169"."/Common/HAPP102".9169 = INTEGER: enabled(1)

But when I use the same OID by pysnmp I get this: 但是当我通过pysnmp使用相同的OID时,我得到了:

[ObjectType(ObjectIdentity(<ObjectName value object at 0x6373150 tagSet <TagSet object at 0x4ab5190 tags 0:0:6> payload [1.3.6.1.4.1.3375...80.49.48.52.9144]>), <Integer value object at 0x6373050 subtypeSpec <ConstraintsIntersection object at 0x4ab5c90 consts <ValueRangeConstraint object at 0x4a17c90 consts -2147483648, 2147483647>> tagSet <TagSet object at 0x4aabad0 tags 0:0:2> payload [1]>)]

My question: 我的问题:

Is there a way to parse this pysnmp response or am I doing something wrong? 有没有办法解析此pysnmp响应,或者我做错了什么?

Here is the python code: 这是python代码:

from pysnmp.hlapi import *


def walk(host, oid):
    for (errorIndication, errorStatus, errorIndex, varBinds) in nextCmd(SnmpEngine(),
                                                                        CommunityData('public'),
                                                                        UdpTransportTarget((host, 161)),
                                                                        ContextData(),
                                                                        ObjectType(ObjectIdentity(oid)),
                                                                        lexicographicMode=False):
        if errorIndication:
            break
        elif errorStatus:
            break

        else:

            for varBind in varBinds:
                print(varBind)


walk('10.10.100.89', '1.3.6.1.4.1.3375.2.2.5.6.2.1.6')

You just need to .prettyPrint() the pysnmp objects you get in response: 您只需要.prettyPrint()作为响应得到的pysnmp对象:

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

Like shown in the examples . 示例所示。

EDIT: 编辑:

If you want the response variable-bindings to be resolved against a MIB, you need to load that MIB (perhaps, F5-BIGIP-LOCAL-MIB ) into pysnmp like this: 如果你想响应变量绑定到对一个MIB来解决,需要加载该MIB(也许, F5-BIGIP-LOCAL-MIB )成这样pysnmp:

...
ContextData(),
ObjectType(ObjectIdentity(oid)).loadMibs('F5-BIGIP-LOCAL-MIB'),
...

Alternatively, if you specify MIB symbols in request (as opposed to specifying OIDs), pysnmp will load up the named MIB automatically. 或者,如果您在请求中指定MIB符号(而不是指定OID),则pysnmp将自动加载命名的MIB。

...
ContextData(),
ObjectType(ObjectIdentity('F5-BIGIP-LOCAL-MIB', 'ltmPoolMbrStatusEnabledState')),
...

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

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