解析 SNMP MIB 文件以生成设备和 OID 列表
我正在处理大量 SNMP MIB 文件,并从中创建设备及其各自 ID 的字典,格式为“1.3.6.1.4.1.9.1.694”:“catalyst296024”。
我目前正在使用 Mibble 进行 MIB 解析部分,因为在尝试了其他应用程序/模块之后,我发现它是理想的选择。然后我使用 python 来处理数据。
我的问题是我只需要“设备名称和OID”。因为当我解析时我得到了所有的 OID 数据,所以我还没有设法找到一种方法来智能地识别设备并忽略其余的东西。 (缺少逐行物理查看数据)
I am processing a large number of SNMP MIB Files and from them creating a dictionary of devices and their respective ID, in the form "1.3.6.1.4.1.9.1.694":"catalyst296024".
I am currently using Mibble for the MIB parsing part as after trying out other apps/modules, I found it to be the ideal. Then I am using python to work on the data.
My problem is that I only need the "device name & OID". Since when I parse I am getting all the OID data I have not yet managed to find a way to intelligently identify the device and ignore the rest of the stuff. (Short of physically looking at the data line by line)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

最简单的事情之一是使用 Net-SNMP 的
mib2c
程序,它可以让您根据一组 MIB 对象编写快速输出。有关如何编写 mib2c 脚本的详细信息,请参阅它的 wiki 页面。另外,您可以简单地解析命令的输出,例如 snmptranslate 将打印一个树结构输出(使用
-Tp
),它可能比 MIB 文件本身更容易解析。One of the easiest things to do would be to use Net-SNMP's
mib2c
program, which will let you write a quick output based on a set of MIB objects. See it's wiki page for details on how to write mib2c scripts.Also, you could simply parse the output of a command, like snmptranslate that will print a tree structure output (use
-Tp
) that is likely easier to parse than the MIB file itself.