Search code examples
pythonsnmppysnmp

How do I convert my private MIB files into .py format so that I can perform GET/SET actions on my device


I am trying to write a script that will perform GET/SET commands on my device. While I have tried to do GET action on sysDescr (which is part of the standard MIB SNMPv2) I managed to get a response. I have tried to use the mibdump.py script in several different ways, in order to convert my proprietary MIB files so that I could later on work with them:

  1. activate the mibdump.py on a specific MIB file (see the result) with .mib extension and without

     c:\Program Files\Python35\Scripts>python mibdump.py SL-XPDR.mib
        Source MIB repositories: file:///usr/share/snmp/mibs, h ttp://mibs.snmplabs.com/a
        sn1/@mib@
        Borrow missing/failed MIBs from: h ttp://mibs.snmplabs.com/pysnmp/notexts/@mib@
        Existing/compiled MIB locations: pysnmp.smi.mibs, pysnmp_mibs
        Compiled MIBs destination directory: C:\Users\alpha_2.PL\PySNMP   Configuration\mibs
        MIBs excluded from code generation: RFC-1212, RFC-1215, RFC1065-SMI, RFC1155-SMI
        , RFC1158-MIB, RFC1213-MIB, SNMP-FRAMEWORK-MIB, SNMP-TARGET-MIB,   SNMPv2-CONF, SN
        MPv2-SMI, SNMPv2-TC, SNMPv2-TM, TRANSPORT-ADDRESS-MIB
        MIBs to compile: SL-XPDR
        Destination format: pysnmp
        Parser grammar cache directory: not used
        Also compile all relevant MIBs: yes
        Rebuild MIBs regardless of age: no
        Do not create/update MIBs: no
        Byte-compile Python modules: yes (optimization level 0)
        Ignore compilation errors: no
        Generate OID->MIB index: no
        Generate texts in MIBs: no
        Try various filenames while searching for MIB module: yes
        Created/updated MIBs:
        Pre-compiled MIBs borrowed:
        Up to date MIBs:
        Missing source MIBs: SL-XPDR
        Ignored MIBs:
        Failed MIBs:
    
  2. I have tried again with specific MIB file location with no success

  3. I have even tried to compile the whole MIB folder without any success

    c:\Program Files\Python35\Scripts>python mibdump.py C:\Program Files\Python35\Scripts\mibs
        Source MIB repositories: file:///usr/share/snmp/mibs, file://C:\, file://c:\Prog
        ram Files\Python35\Scripts\Files\Python35\Scripts, h ttp://mibs.snmplabs.com/asn1/@mib@
        Borrow missing/failed MIBs from: h ttp://mibs.snmplabs.com/pysnmp/notexts/@mib@
        Existing/compiled MIB locations: pysnmp.smi.mibs, pysnmp_mibs
        Compiled MIBs destination directory: C:\Users\alpha_2.PL\PySNMP Configuration\mibs
        MIBs excluded from code generation: RFC-1212, RFC-1215, RFC1065-SMI, RFC1155-SMI, RFC1158-MIB, RFC1213-MIB, SNMP-FRAMEWORK-MIB, SNMP-TARGET-MIB, SNMPv2-CONF, SNMPv2-SMI, SNMPv2-TC, SNMPv2-TM, TRANSPORT-ADDRESS-MIB
        MIBs to compile: Program, mibs
        Destination format: pysnmp
        Parser grammar cache directory: not used
        Also compile all relevant MIBs: yes
        Rebuild MIBs regardless of age: no
        Do not create/update MIBs: no
        Byte-compile Python modules: yes (optimization level 0)
        Ignore compilation errors: no
        Generate OID->MIB index: no
        Generate texts in MIBs: no
        Try various filenames while searching for MIB module: yes
        Created/updated MIBs:
        Pre-compiled MIBs borrowed:
        Up to date MIBs:
        Missing source MIBs: Program, mibs
        Ignored MIBs:
        Failed MIBs:
    

What is the right way to transform my proprietary MIB files into .py files ?


Solution

  • If you are running SNMP management application, you do not really need to compile MIBs explicitly -- pysnmp will do that for you behind the scenes by calling pysmi compiler and caching compiled MIB for future occasions. Here's an example script that does just that.

    You problems with mibdump seems to be related to MIB search paths. Given you have your MIB file in currect working directory, this command should do it:

    mibdump.py  --mib-source . --mib-source http://mibs.snmplabs.com/asn1/@mib@ SL-XPDR
    

    The idea is that you tell mibdump to first check out your cwd, then try the on-line MIB repository (for other MIB files your MIB may depend on).

    In your screen paste it looks like paths get corrupted by whitespaces. I'm not sure is it because of cut&paste or you need to quote them at your command-line.