How to pass MIB to the Manager

  1. How to make use of random MIBs at my Manager application?

  1. 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 your user cache directory: $XDG_CACHE_HOME/pysnmp/mibs (or ~/.cache/pysnmp/mibs) on Linux and the BSDs, ~/Library/Caches/pysnmp/mibs on macOS, and %LOCALAPPDATA%\pysnmp\Cache\mibs on Windows. An older ~/.pysnmp/mibs that already exists keeps being used, so upgrading does not orphan a cache you already have. Passing destination= to addMibCompiler() overrides all of it.

    PySMI bundles the standard MIB set – SNMPv2-SMI, IF-MIB and 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 newer MODULE-IDENTITY revision 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 MIBs Depot 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://data.mibsdepot.com/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')
))