简体   繁体   English

pysnmp OID解析

[英]pysnmp OID resolution

Using pysnmp, how you perform resolution on queries that return an OID instead of value? 使用pysnmp,如何对返回OID而不是值的查询执行解析?

I wrote a lookup tool using pysnmp, here are the inputs and results : 我使用pysnmp编写了一个查找工具,以下是输入和结果:

./run_snmp_discovery.py --host 1.1.1.1 --community XXXXXX --command get --mib_oid_index  '{ "mib" : "SNMPv2-MIB", "oid" : "sysObjectID", "index" : "0"  }' --verbose
Debug: 'varBind': SNMPv2-MIB::sysObjectID.0 = SNMPv2-SMI::enterprises.9.1.222
{"0": {"sysObjectID": "SNMPv2-SMI::enterprises.9.1.222"}}

How can the result be converted to the text value cisco7206VXR (reference http://www.circitor.fr/Mibs/Html/C/CISCO-PRODUCTS-MIB.php#cisco7206VXR ) 如何将结果转换为文本值cisco7206VXR (请参阅http://www.circitor.fr/Mibs/Html/C/CISCO-PRODUCTS-MIB.php#cisco7206VXR

If you are using code like this : 如果您使用的是这样的代码:

from pysnmp.hlapi import *

errorIndication, errorStatus, errorIndex, varBinds = next(
    getCmd(SnmpEngine(),
           CommunityData('public'),
           UdpTransportTarget(('demo.snmplabs.com', 161)),
           ContextData(),
           ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)))
)

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

And you want MIB object to be represented as an OID, then the varBind in the code above is actually an ObjectType class instance which behaves like a tuple of two elements. 并且您希望将MIB对象表示为OID,那么上面代码中的varBind实际上是一个ObjectType类实例,其行为类似于两个元素的元组。 The first element is ObjectIdentity which has the .getOid method: 第一个元素是ObjectIdentity ,它具有.getOid方法:

>>> objectIdentity = ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)
>>> objectIdentity.resolveWithMib(mibViewController)
>>> objectIdentity.getOid()
ObjectName('1.3.6.1.2.1.1.1.0')

If you want MIB object and its value to be fully represented in MIB terms (ie value resolved into an enumeration), then you just need to load the MIB that defines that MIB object (perhaps, CISCO-PRODUCTS-MIB) using .loadMibs() method. 如果要使MIB对象及其值完全用MIB术语表示(即,将值解析为枚举),则只需使用.loadMibs( )加载定义该MIB对象的MIB(也许是CISCO-PRODUCTS-MIB)。 方法。 You might also need to set up a search path to let pysnmp find the MIB you refer. 您可能还需要设置搜索路径,以使pysnmp查找您引用的MIB。

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

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