Reputation: 61
What I need to do is write a function that finds the MIB name for a given OID. E.g when I give '1.3.6.1.2.1.31.1.1.1.6' as an argument, it should return '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?
Upvotes: 1
Views: 2824
Reputation: 5555
It is possible with pysnmp, you do not need to create a MIB parser. ;-)
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
. One caveat here is that you need to load the MIB that defines the OID before you could look it up. The unresolved tail of the OID might appear in 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.
BTW, the same tool can build a JSON index which would look like this. You could use it to map your OID onto the MIB module where it's defined.
Upvotes: 2