Parse SNMP MIB Files to generate a list of Devices and OID

user1215841 picture user1215841 · Feb 17, 2012 · Viewed 11.7k times · Source

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)

Answer

Wes Hardaker picture Wes Hardaker · Feb 17, 2012

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.