def fetch_mib(mib):
        target_directory = os.path.dirname(pysnmp_mibs.__file__)

        reader = HttpReader('mibs.snmplabs.com', 80, '/asn1/@mib@')
        mibCompiler = MibCompiler(SmiStarParser(), PySnmpCodeGen(),
                                  PyFileWriter(target_directory))

        mibCompiler.addSources(reader)

        mibCompiler.compile(mib)
Esempio n. 2
0
def fetch_mib(mib):
    import pysnmp_mibs
    from pysmi.codegen import PySnmpCodeGen
    from pysmi.compiler import MibCompiler
    from pysmi.parser import SmiStarParser
    from pysmi.reader import HttpReader
    from pysmi.writer import PyFileWriter

    target_directory = os.path.dirname(pysnmp_mibs.__file__)

    reader = HttpReader('mibs.snmplabs.com', 80, '/asn1/@mib@')
    mibCompiler = MibCompiler(SmiStarParser(), PySnmpCodeGen(), PyFileWriter(target_directory))

    mibCompiler.addSources(reader)

    mibCompiler.compile(mib)
Esempio n. 3
0
def fetch_mib(mib, source_url):
    try:
        from urllib.parse import urlparse
    except ImportError:
        from urlparse import urlparse

    import pysnmp_mibs
    from pysmi.codegen import PySnmpCodeGen
    from pysmi.compiler import MibCompiler
    from pysmi.parser import SmiStarParser
    from pysmi.reader import HttpReader
    from pysmi.writer import PyFileWriter

    target_directory = os.path.dirname(pysnmp_mibs.__file__)

    parsed_url = urlparse(source_url)
    reader = HttpReader(parsed_url.netloc, 80, parsed_url.path)
    mibCompiler = MibCompiler(SmiStarParser(), PySnmpCodeGen(),
                              PyFileWriter(target_directory))

    mibCompiler.addSources(reader)

    mibCompiler.compile(mib)
    # Compiler infrastructure

    borrowers = [PyFileBorrower(x[1], genTexts=mibBorrowers[x[0]][1])
                 for x in enumerate(getReadersFromUrls(*[m[0] for m in mibBorrowers], **dict(lowcaseMatching=False)))]

    searchers = [PyFileSearcher(dstDirectory)]

    for mibSearcher in mibSearchers:
        searchers.append(PyPackageSearcher(mibSearcher))

    searchers.append(StubSearcher(*mibStubs))

    codeGenerator = PySnmpCodeGen()

    fileWriter = PyFileWriter(dstDirectory).setOptions(pyCompile=pyCompileFlag,
                                                       pyOptimizationLevel=pyOptimizationLevel)

elif dstFormat == 'json':
    if not mibStubs:
        mibStubs = JsonCodeGen.baseMibs

    if not mibBorrowers:
        mibBorrowers = [('http://mibs.snmplabs.com/json/notexts/@mib@', False),
                        ('http://mibs.snmplabs.com/json/fulltexts/@mib@', True)]

    if not dstDirectory:
        dstDirectory = os.path.join('.')

    # Compiler infrastructure

    borrowers = [AnyFileBorrower(x[1], genTexts=mibBorrowers[x[0]][1]).setOptions(exts=['.json'])
Esempio n. 5
0
from pysmi.reader import FtpReader
from pysmi.reader import FileReader
from pysmi.searcher import StubSearcher
from pysmi.writer import PyFileWriter
from pysmi.parser import SmiStarParser
from pysmi.codegen import PySnmpCodeGen
from pysmi.compiler import MibCompiler

inputMibs = ['IF-MIB', 'BRIDGE-MIB', 'LUXL-POE-MIB', 'LUXL-SMI', 'LUXL-TC']
httpSources = [('mibs.snmplabs.com', 80, '/asn1/@mib@')]
ftpSources = [('ftp.cisco.com', '/pub/mibs/v2/@mib@')]
srcDirectories = [('./LUXL_MIBs_ALL')]
dstDirectory = './lib/python3.7/site-packages/pysnmp/smi/mibs/'

# Initialize compiler infrastructure

mibCompiler = MibCompiler(SmiStarParser(), PySnmpCodeGen(),
                          PyFileWriter(dstDirectory))

# search for source MIBs at Web and FTP sites
mibCompiler.addSources(*[HttpReader(*x) for x in httpSources])
mibCompiler.addSources(*[FtpReader(*x) for x in ftpSources])
mibCompiler.addSources(*[FileReader(x) for x in srcDirectories])

# never recompile MIBs with MACROs
mibCompiler.addSearchers(StubSearcher(*PySnmpCodeGen.baseMibs))

# run non-recursive MIB compilation
results = mibCompiler.compile(*inputMibs, **dict(noDeps=True))

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