Always borrow pysnmp MIBsΒΆ

Try to borrow precompiled pysnmp MIB file(s) from a web-site.

In this example no attempt is made to find and compile ASN.1 MIB source.

Fetched pysnmp MIB(s) are stored in a local directory.

from pysmi.reader import HttpReader
from pysmi.searcher import PyFileSearcher
from pysmi.borrower import PyFileBorrower
from pysmi.writer import PyFileWriter
from pysmi.parser import NullParser
from pysmi.codegen import NullCodeGen
from pysmi.compiler import MibCompiler

inputMibs = ['BORROWED-MIB']

httpBorrowers = [
    ('', 80, '/pysnmp/notexts/@mib@')
dstDirectory = '.pysnmp-mibs'

# Initialize compiler infrastructure

mibCompiler = MibCompiler(
    NullParser(), NullCodeGen(), PyFileWriter(dstDirectory)

# check compiled/borrowed MIBs in our own productions

# search for precompiled MIBs at Web sites
    *[PyFileBorrower(HttpReader(*x)) for x in httpBorrowers]

# run MIB compilation
results = mibCompiler.compile(*inputMibs)

print('Results: %s' % ', '.join(['%s:%s' % (x, results[x]) for x in results]))

Download script.