简体   繁体   English

pysnmp获取子树并且不针对mib名称解析oid

[英]pysnmp get subtree and do not resolve oid against mib name

I want to provide pysnmp with a base oid for example 1.3.6.1.2.1.2.2.1.8 and be able to get all it's children underneath it eg 1.3.6.1.2.1.2.2.1.8.1 - 1.3.6.1.2.1.2.2.1.8.n without going over to 1.3.6.1.2.1.2.2.1.9 . 我想为pysnmp提供一个基本的oid,例如1.3.6.1.2.1.2.2.1.8并能够在其下获取所有子元素,例如1.3.6.1.2.1.2.2.1.8.1 - 1.3.6.1.2.1.2.2.1.8.n而不移至1.3.6.1.2.1.2.2.1.9 I was wondering how I would go about this? 我想知道我该怎么做? I have also tried doing a GETNEXT but not sure how to go about achieving what I want. 我也尝试过执行GETNEXT,但不确定如何实现我想要的。 Another question is pysnmp seems to try to resolve the oid to the mib associated with it, how do I go about turning this feature off? 另一个问题是pysnmp似乎试图将oid解析为与其关联的mib,我该如何关闭此功能? I am currently using the latest version of pysnmp. 我当前正在使用最新版本的pysnmp。

Try passing both lookupMib=False and lexicographicMode=False to nextCmd() or bulkCmd(): 尝试将lookupMib = FalselexicographicMode = False都传递给nextCmd()或bulkCmd():

from pysnmp.hlapi import *

for errorIndication, errorStatus, \
    errorIndex, varBinds in bulkCmd(
        SnmpEngine(),
        CommunityData('public'),
        UdpTransportTarget(('demo.snmplabs.com', 161)),
        ContextData(),
        0, 50,  # GETBULK specific: request up to 50 OIDs in a single response
        ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.8')),
        lookupMib=False, lexicographicMode=False):

    if errorIndication:
        print(errorIndication)
        break
    elif errorStatus:
        print('%s at %s' % (errorStatus.prettyPrint(),
                            errorIndex and varBinds[int(errorIndex)-1][0] or '?'))
        break
    else:
        for varBind in varBinds:
            print(' = '.join([x.prettyPrint() for x in varBind]))

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

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