简体   繁体   English

PySNMP可以找到OID的MIB名称吗?

[英]Can PySNMP find the MIB name for an OID?

What I need to do is write a function that finds the MIB name for a given OID. 我需要做的是编写一个函数,该函数查找给定OID的MIB名称。 Eg when I give '1.3.6.1.2.1.31.1.1.1.6' as an argument, it should return 'ifHCInOctets'. 例如,当我给出“ 1.3.6.1.2.1.31.1.1.1.6”作为参数时,它应该返回“ ifHCInOctets”。 I've been searching the PySNMP documentation and Stack Overflow but didn't find anything so: Is this something that's possible with PySNMP, or do I have to write a parser for the MIB files? 我一直在搜索PySNMP文档和堆栈溢出,但没有找到任何东西:PySNMP是否可以实现此功能,还是我必须为MIB文件编写解析器?

It is possible with pysnmp, you do not need to create a MIB parser. pysnmp是可能的,您无需创建MIB解析器。 ;-) ;-)

If you follow this example , specifically these pieces: 如果您遵循此示例 ,特别是以下内容:

from pysnmp.smi import builder, view, compiler

mibBuilder = builder.MibBuilder()
compiler.addMibCompiler(mibBuilder, sources=['/usr/share/snmp/mibs'])
mibBuilder.loadModules('IF-MIB', ...)
mibView = view.MibViewController(mibBuilder)

oid, label, suffix = mibView.getNodeName((1,3,6,1,2,1,31,1,1,1,6))

The label variable should return ifHCInOctets . label变量应返回ifHCInOctets One caveat here is that you need to load the MIB that defines the OID before you could look it up. 这里的一个警告是,您需要先加载定义OID的MIB,然后才能进行查找。 The unresolved tail of the OID might appear in suffix . OID的未解析尾巴可能会出现在suffix

Another approach could be to use pysmi's mibdump tool (or the underlying pysmi library) to turn ASN.1 MIBs into JSON for further processing by your application. 另一种方法可能是使用pysmi的mibdump工具(或底层pysmi库)将ASN.1 MIB转换为JSON,以供应用程序进一步处理。

BTW, the same tool can build a JSON index which would look like this . 顺便说一句,同一工具可以构建一个看起来像这样的JSON 索引 You could use it to map your OID onto the MIB module where it's defined. 您可以使用它将OID映射到定义它的MIB模块上。

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

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