How to pass MIB to the Manager¶
How to make use of random MIBs at my Manager application?
Starting from PySNMP 4.3.x, plain-text (ASN.1) MIBs can be automatically parsed into PySNMP form by the PySMI tool. PySNMP will call PySMI automatically, parsed PySNMP MIB will be cached in $HOME/.pysnmp/mibs/ (default location).
PySMI bundles the standard MIB set –
SNMPv2-SMI,IF-MIBand the rest of what a vendor MIB imports – and searches it alongside whatever sources you configure, so a MIB that only imports standard modules compiles with no source configured at all and no network. Where a copy you configure carries a newerMODULE-IDENTITYrevision than the bundled one, yours is used.MIB compiler could be configured to search for plain-text MIBs at multiple local and remote locations, which is what a MIB importing something outside that set needs. As for remote MIB repos, you are welcome to use our collection of ASN.1 MIB files at https://pysnmp.github.io/mibs/asn1/ as shown below.
# Configure the SNMP engine with access to the
# common Linux ASN.1 (Textual) MIB directories...
from pysnmp import hlapi
from pysnmp.smi import compiler
engine = hlapi.Engine()
builder = engine.getMibBuilder()
compiler.addMibCompiler(builder, sources=[
'/usr/share/snmp/mibs',
os.path.expanduser('~/.snmp/mibs'),
'https://pysnmp.github.io/mibs/asn1/@mib@',
])
Alternatively, you can invoke the mibdump.py (shipped with PySMI) by hand and this way compile plain-text MIB into PySNMP format. Once the compiled MIBs are stored in a directory, add the directory to your MibBuilder’s MibSources.
builder = engine.getMibBuilder()
# Make ./mibs available to all OIDs that are created
# e.g. with "MIB-NAME-MIB::identifier"
builder.addMibSources(builder_module.DirMibSource(
os.path.join( HERE, 'mibs')
))