4

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 ?

Bence Kaulics
  • 7,066
  • 7
  • 33
  • 63
Moshe S.
  • 2,834
  • 3
  • 19
  • 31
  • I have also tried the following script option **c:\> python mibdump.py --mib-source= SL-XPDR** without any success – Moshe S. Feb 20 '17 at 09:08

1 Answers1

6

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.

Ilya Etingof
  • 5,440
  • 1
  • 17
  • 21
  • I have tried your suggested script and got the following result: c:\Program Files\Python35\Scripts>mibdump.py --mib-source . --mib-source http:/ /mibs.snmplabs.com/asn1/@mib@ --mib-module SL-XPDR ERROR: option --mib-module not recognized – Moshe S. Feb 20 '17 at 11:05
  • By the way, I liked your suggestion regarding using the pysmi compiler in my code. Can you please give an example for such use ? When you say " running SNMP management application" what do you mean ? – Moshe S. Feb 20 '17 at 11:08
  • shoot, right! no --mib-module option, just MIB name (updated my answer) – Ilya Etingof Feb 20 '17 at 11:21
  • @MosheS.Added a link to pysnmp example that uses pysmi – Ilya Etingof Feb 20 '17 at 11:24
  • Great. Finally !!! Will I need to copy all the .py files (once MIB) to the pysnmp mib directory ? – Moshe S. Feb 20 '17 at 11:43
  • Could it be better to perform the conversion based only on my own MIB sources ? How do I actually switch the http path with a regular (local) path – Moshe S. Feb 20 '17 at 11:45
  • @MosheS.You could use your own MIBs of course. Here's a [quick link](http://pysmi.sourceforge.net/user-perspective.html#specifying-mib-source) to the user manual. – Ilya Etingof Feb 20 '17 at 15:32
  • @MosheS. You could put compiled pysnmp MIBs into any local directory and tell pysnmp where to find them (see example script). Default location is noted by mibdump (C:\Users\alpha_2.PL\PySNMP) – Ilya Etingof Feb 20 '17 at 19:56