Si vous utilisez pysnmp avec Python, il faut mettre les mibs au bon format pour les utiliser simplement.
Si les mibs ne sont pas au format pysnmp, vous aurez l'erreur suivante:
[root@Supervision script_super]# ./script-python.py
Traceback (most recent call last):
File "./script-python.py", line 17, in <module>
lexicographicMode=False):
File "build/bdist.linux-x86_64/egg/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 111, in getCmd
File "build/bdist.linux-x86_64/egg/pysnmp/hlapi/asyncore/cmdgen.py", line 130, in getCmd
File "build/bdist.linux-x86_64/egg/pysnmp/hlapi/varbinds.py", line 39, in makeVarBinds
File "build/bdist.linux-x86_64/egg/pysnmp/smi/rfc1902.py", line 847, in resolveWithMib
File "build/bdist.linux-x86_64/egg/pysnmp/smi/rfc1902.py", line 481, in resolveWithMib
File "build/bdist.linux-x86_64/egg/pysnmp/smi/builder.py", line 419, in importSymbols
File "build/bdist.linux-x86_64/egg/pysnmp/smi/builder.py", line 388, in loadModules
pysnmp.smi.error.MibNotFoundError: INTERFACEMIB compilation error(s): missingcaused by <class 'pysnmp.smi.error.MibNotFoundError'>: MIB file "INTERFACEMIB.py[co]" not found in search path (ZipMibSource('pysnmp/smi/mibs'), ZipMibSource('pysnmp/smi/mibs/instances'), DirMibSource('pysnmp_mibs'))caused by <type 'exceptions.IOError'>: [Errno 2] No suitable module found: 'INTERFACEMIB'
[root@Supervision script_super]#
Pour mettre les mibs au bon format, voici la commande:
[root@Supervision script_super]# /usr/bin/mibdump.py --destination-directory=/var/spool/openmanage/.pysnmp/mibs/ /var/spool/openmanage/.pysnmp/mibs/INTERFACES-MIB.mib
Source MIB repositories: /var/spool/openmanage/.pysnmp/mibs, file:///usr/share/snmp/mibs, http://mibs.snmplabs.com/asn1/@mib@
Borrow missing/failed MIBs from: http://mibs.snmplabs.com/pysnmp/notexts/@mib@
Existing/compiled MIB locations: pysnmp.smi.mibs, pysnmp_mibs
Compiled MIBs destination directory: /var/spool/openmanage/.pysnmp/mibs/
MIBs excluded from code generation: INET-ADDRESS-MIB, PYSNMP-USM-MIB, 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: INTERFACES-MIB
Destination format: pysnmp
Parser grammar cache directory: not used
Also compile all relevant MIBs: yes
Rebuild MIBs regardless of age: no
Dry run mode: no
Create/update MIBs: yes
Byte-compile Python modules: yes (optimization level no)
Ignore compilation errors: no
Generate OID->MIB index: no
Generate texts in MIBs: no
Keep original texts layout: no
Try various file names while searching for MIB module: yes
Created/updated MIBs:
Pre-compiled MIBs borrowed:
Up to date MIBs: INTERFACES-MIB, IANAifType-MIB, IF-MIB, INET-ADDRESS-MIB, SNMPv2-CONF, SNMPv2-MIB, SNMPv2-SMI, SNMPv2-TC
Missing source MIBs:
Ignored MIBs:
Failed MIBs:
[root@Supervision script_super]#
On vérifie que les fichiers .py et .pyc sont bien créés.
[root@Supervision script_super]# ls /var/spool/openmanage/.pysnmp/mibs/
INTERFACES-MIB.mib INTERFACES-MIB.pyc IANAifType-MIB.py IF-MIB.py SNMPv2-MIB.py
INTERFACES-MIB.py INTERFACEMIB.mib IANAifType-MIB.pyc IF-MIB.pyc SNMPv2-MIB.pyc