SNMP MIB On board Guide
How to onboard a MIB file into EMS ¶
1.Environment Prepare ¶
Pre-request
This action need run on Linux or MacOs.
Make sure you have python installed and the pip tool should have installed alone with python.
Install pysnmp & pysmi
Let's take python3 and pip3 as example:
/opt/emspython/bin/python3.7 -m pip install pysnmp
/opt/emspython/bin/python3.7 -m pip install pysmi
pip3 install --upgrade pysnmp
pip3 install pysmi
python3 -m site (find where your python site pkg is)
Find mibdump bin file in your system bin directory, maybe in /usr/local/bin/mibdump.
Try run it by
/usr/local/bin/mibdump it may return some ssl error, then you will need run
pip3 install urllib3==1.26.15 for downgrade ssl pkg for compatibility issues. 2.MIB Prepare ¶
Check the "import" of the new MIB file, if there do have some imports, then you will need get those import MIB file and put them together at same folder.
You will need get .my file.
Sample:
SNMPv2-SMI.my
SNMPv2-TC.my
SNMPv2-CONF.my
You can search and get the link of some common MIB file from here:
https://snmp.cloudapps.cisco.com/Support/SNMP/do/BrowseMIB.do?local=en&step=2
3.Dump MIB to .py ¶
Run Command like:
/usr/local/bin/mibdump --mib-source=/xxx/xxx/xxx/ --destination-format pysnmp --destination-directory=/xxx/xxx/xxx/ TEST-SNMP-MIB
- --mib-source: the directory where your MIB files are located.
- --destination-directory: the output directory for the generated files.
- TEST-SNMP-MIB: The MIB file you want to convert.
If success you will get the .py file at the destination-directory and get output log like:
shengz@SHENGZ-M-YM2M Downloads % /usr/local/bin/mibdump --mib-source=/Users/shengz/Desktop/ --destination-format pysnmp --destination-directory=/Users/shengz/Desktop/ TEST-SNMP-MIB
Source MIB repositories: /Users/shengz/Desktop/
Borrow missing/failed MIBs from: https://mibs.pysnmp.com:443/mibs/notexts/@mib@
Existing/compiled MIB locations: pysnmp.smi.mibs, pysnmp_mibs
Compiled MIBs destination directory: /Users/shengz/Desktop/
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: TEST-SNMP-MIB
Destination format: pysnmp
Custom destination template: None
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: TEST-SNMP-MIB
Pre-compiled MIBs borrowed:
Up to date MIBs: SNMPv2-CONF, SNMPv2-SMI, SNMPv2-TC
Missing source MIBs:
Ignored MIBs:
Failed MIBs:
If you don't prepare enough dependence MIB, you will get error msg in output log like:
......
Up to date MIBs:
Missing source MIBs: SNMPv2-CONF
SNMPv2-SMI
SNMPv2-TC
Ignored MIBs:
Failed MIBs: TEST-SNMP-MIB (no module "SNMPv2-SMI" in symbolTable at MIB TEST-SNMP-MIB)
4.Load the mib.py into db ¶
- Go to ewb or epi server where ecenter pkg is installed.
- Sometimes you will need prepare the dependence MIB's mib.py by going through above steps and put all mib.py at same folder.
- Go to modify file /webapp/ecenter/core/ems_snmp_service.py.
at line 30/31/35, modify python version to a correct one
at line 66~69, fill the right mib file name, both the MIB you want load and the dependence MIB
at line 64, define the mib py file folder - Run Command:
/opt/emspython/bin/python3.7 /webapp/ecenter/core/ems_snmp_service.py --mib2db --debug --stdout
Fail Case:
[root@mbtny1ewb001 core]# /opt/emspython/bin/python3.7 /webapp/ecenter/core/ems_snmp_service.py --mib2db --debug --stdout
MIBs analyzed 0, MIBs failed 1
Traceback (most recent call last):
File "/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 417, in loadModules
self.loadModule(modName, **userCtx)
File "/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 396, in loadModule
", ".join([str(x) for x in self.__mibSources]),
pysnmp.smi.error.MibNotFoundError: MIB file "IANAifType-MIB.py[co]" not found in search path (DirMibSource('/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/mibs'), DirMibSource('/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/mibs/instances'), DirMibSource('pysnmp_mibs'), DirMibSource('/root/.pysnmp/mibs'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 376, in loadModule
exec(codeObj, g)
File "/root/.pysnmp/mibs/IF-MIB.py", line 50, in <module>
"IANAifType")
File "/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 464, in importSymbols
self.loadModules(modName, **userCtx)
File "/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 436, in loadModules
f"{modName} compilation error(s): {errs}"
pysnmp.smi.error.MibNotFoundError: IANAifType-MIB compilation error(s): missing caused by <class 'pysnmp.smi.error.MibNotFoundError'>: MIB file "IANAifType-MIB.py[co]" not found in search path (DirMibSource('/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/mibs'), DirMibSource('/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/mibs/instances'), DirMibSource('pysnmp_mibs'), DirMibSource('/root/.pysnmp/mibs'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/webapp/ecenter/core/ems_snmp_service.py", line 67, in <module>
mibBuilder.loadModules('IF-MIB')
File "/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 417, in loadModules
self.loadModule(modName, **userCtx)
File "/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 381, in loadModule
f"MIB module '{modPath}' load error: {traceback.format_exception(*sys.exc_info())}"
pysnmp.smi.error.MibLoadError: MIB module '/root/.pysnmp/mibs/IF-MIB/root/.pysnmp/mibs/IF-MIB.py' load error: ['Traceback (most recent call last):\n', ' File "/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 417, in loadModules\n self.loadModule(modName, **userCtx)\n', ' File "/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 396, in loadModule\n ", ".join([str(x) for x in self.__mibSources]),\n', 'pysnmp.smi.error.MibNotFoundError: MIB file "IANAifType-MIB.py[co]" not found in search path (DirMibSource(\'/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/mibs\'), DirMibSource(\'/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/mibs/instances\'), DirMibSource(\'pysnmp_mibs\'), DirMibSource(\'/root/.pysnmp/mibs\'))\n', '\nDuring handling of the above exception, another exception occurred:\n\n', 'Traceback (most recent call last):\n', ' File "/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 376, in loadModule\n exec(codeObj, g)\n', ' File "/root/.pysnmp/mibs/IF-MIB.py", line 50, in <module>\n "IANAifType")\n', ' File "/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 464, in importSymbols\n self.loadModules(modName, **userCtx)\n', ' File "/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 436, in loadModules\n f"{modName} compilation error(s): {errs}"\n', 'pysnmp.smi.error.MibNotFoundError: IANAifType-MIB compilation error(s): missing caused by <class \'pysnmp.smi.error.MibNotFoundError\'>: MIB file "IANAifType-MIB.py[co]" not found in search path (DirMibSource(\'/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/mibs\'), DirMibSource(\'/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/mibs/instances\'), DirMibSource(\'pysnmp_mibs\'), DirMibSource(\'/root/.pysnmp/mibs\'))\n'] caused by <class 'pysnmp.smi.error.MibNotFoundError'>: IANAifType-MIB compilation error(s): missing caused by <class 'pysnmp.smi.error.MibNotFoundError'>: MIB file "IANAifType-MIB.py[co]" not found in search path (DirMibSource('/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/mibs'), DirMibSource('/opt/emspython/lib/python3.7/site-packages/pysnmp/smi/mibs/instances'), DirMibSource('pysnmp_mibs'), DirMibSource('/root/.pysnmp/mibs'))
[root@mbtny1ewb001 core]# vi ems_snmp_service.py
[root@mbtny1ewb001 core]# /opt/emspython/bin/python3.7 /webapp/ecenter/core/ems_snmp_service.py --mib2db --debug --stdout
2025-04-02 02:50:13,848 - __main__ - INFO - Writing to stdout..
2025-04-02 02:50:13,848 - __main__ - DEBUG - MibLoader() __init__()
2025-04-02 02:50:13,848 - __main__ - DEBUG - MibLoader() __init__() processing TEST-SNMP-MIB
2025-04-02 02:50:13,848 - __main__ - DEBUG - MibLoader() __init__() processing TEST-SNMP-MIB, Yes present,adding
2025-04-02 02:50:13,848 - __main__ - DEBUG - ['ASN1', 'ASN1-ENUMERATION', 'ASN1-REFINEMENT', 'SNMPv2-SMI', 'SNMPv2-CONF', 'SNMPv2-TC', 'TEST-SNMP-MIB']
2025-04-02 02:50:13,848 - __main__ - DEBUG - MibLoader() do()
Success Case:
[root@mbtny1ewb001 core]# /opt/emspython/bin/python3.7 /webapp/ecenter/core/ems_snmp_service.py --mib2db --debug --stdout
2025-04-02 03:00:29,409 - __main__ - INFO - Writing to stdout..
2025-04-02 03:00:29,409 - __main__ - DEBUG - MibLoader() __init__()
2025-04-02 03:00:29,409 - __main__ - DEBUG - MibLoader() __init__() processing IANAifType-MIB
2025-04-02 03:00:29,409 - __main__ - DEBUG - MibLoader() __init__() processing IANAifType-MIB, Yes present,adding
2025-04-02 03:00:29,409 - __main__ - DEBUG - MibLoader() __init__() processing IF-MIB
2025-04-02 03:00:29,409 - __main__ - DEBUG - MibLoader() __init__() processing IF-MIB, Yes present,adding
2025-04-02 03:00:29,409 - __main__ - DEBUG - ['ASN1', 'ASN1-ENUMERATION', 'ASN1-REFINEMENT', 'SNMPv2-SMI', 'SNMPv2-CONF', 'SNMPv2-TC', 'IANAifType-MIB', 'SNMPv2-MIB', 'IF-MIB']
2025-04-02 03:00:29,409 - __main__ - DEBUG - MibLoader() do()
2025-04-02 03:00:29,409 - __main__ - DEBUG - MibLoader() do() processing ifGeneralGroup => .1.3.6.1.2.1.31.2.1.1
2025-04-02 03:00:29,409 - __main__ - DEBUG - MibLoader() do() checking if ifGeneralGroup is existing or not..
2025-04-02 03:00:29,409 - __main__ - DEBUG - MibLoader() do() creating ifGeneralGroup..
2025-04-02 03:00:29,409 - __main__ - DEBUG - MibLoader() do() DUP CHECK ifGeneralGroup..
2025-04-02 03:00:29,430 - __main__ - ERROR - *** DUP CHECK **, EventNotificationDef matching query does not exist.
2025-04-02 03:00:29,433 - __main__ - INFO - Added ifGeneralGroup to the notification definition..
2025-04-02 03:00:29,433 - __main__ - DEBUG - MibLoader() do() ifDescr => .1.3.6.1.2.1.2.2.1.2
2025-04-02 03:00:29,433 - __main__ - DEBUG - MibLoader() do() creating var ifDescr for ifGeneralGroup..
2025-04-02 03:00:29,438 - __main__ - INFO - Created var ifDescr for ifGeneralGroup..
2025-04-02 03:00:29,439 - __main__ - DEBUG - MibLoader() do() ifType => .1.3.6.1.2.1.2.2.1.3
2025-04-02 03:00:29,439 - __main__ - DEBUG - MibLoader() do() creating var ifType for ifGeneralGroup..
2025-04-02 03:00:29,442 - __main__ - INFO - Created var ifType for ifGeneralGroup..
2025-04-02 03:00:29,442 - __main__ - DEBUG - MibLoader() do() ifSpeed => .1.3.6.1.2.1.2.2.1.5
2025-04-02 03:00:29,442 - __main__ - DEBUG - MibLoader() do() creating var ifSpeed for ifGeneralGroup..
……
……
……
2025-04-02 03:00:29,972 - __main__ - INFO - Created var ifAdminStatus for linkUp..
2025-04-02 03:00:29,972 - __main__ - DEBUG - MibLoader() do() ifOperStatus => .1.3.6.1.2.1.2.2.1.8
2025-04-02 03:00:29,972 - __main__ - DEBUG - MibLoader() do() creating var ifOperStatus for linkUp..
2025-04-02 03:00:29,975 - __main__ - INFO - Created var ifOperStatus for linkUp..
5.Generate the MIB mapping ¶
This step is for auto generate event message mapping with MIB varbind. Run Command:
/opt/emspython/bin/python3.7 /webapp/ecenter/core/ems_snmp_service.py --autoconfig --debug --stdout
Success Case(it will have a very long output):
[root@mbtny1ewb001 core]# /opt/emspython/bin/python3.7 /webapp/ecenter/core/ems_snmp_service.py --autoconfig --debug --stdout
2025-04-02 04:07:16,685 - __main__ - INFO - Writing to stdout..
2025-04-02 04:07:16,686 - __main__ - DEBUG - AutoConfig() __init__()
2025-04-02 04:07:16,725 - __main__ - INFO - Loaded 1995 objects from mibs
2025-04-02 04:07:16,725 - __main__ - DEBUG - AutoConfig() do()
2025-04-02 04:07:16,725 - __main__ - DEBUG - AutoConfig() do() processing backplaneBusCHighUtilClose..
2025-04-02 04:07:16,725 - __main__ - DEBUG - AutoConfig() do() checking if backplaneBusCHighUtilClose exists in config table..
2025-04-02 04:07:16,726 - __main__ - DEBUG - AutoConfig() do() backplaneBusCHighUtilClose existing, skipping..
2025-04-02 04:07:16,726 - __main__ - DEBUG - AutoConfig() do() processing sslProxyServiceOperationalUnavailableToSnmpPollClose..
2025-04-02 04:07:16,727 - __main__ - DEBUG - AutoConfig() do() checking if sslProxyServiceOperationalUnavailableToSnmpPollClose exists in config table..
2025-04-02 04:07:16,728 - __main__ - DEBUG - AutoConfig() do() sslProxyServiceOperationalUnavailableToSnmpPollClose existing, skipping..
2025-04-02 04:07:16,728 - __main__ - DEBUG - AutoConfig() do() processing opticalOutputPowerLow..
2025-04-02 04:07:16,728 - __main__ - DEBUG - AutoConfig() do() checking if opticalOutputPowerLow exists in config table..
2025-04-02 04:07:16,729 - __main__ - DEBUG - AutoConfig() do() opticalOutputPowerLow existing, skipping..
2025-04-02 04:07:16,729 - __main__ - DEBUG - AutoConfig() do() processing loadBalancerHighPacketDropRateClose..
2025-04-02 04:07:16,729 - __main__ - DEBUG - AutoConfig() do() checking if loadBalancerHighPacketDropRateClose exists in config table..
2025-04-02 04:07:16,730 - __main__ - DEBUG - AutoConfig() do() loadBalancerHighPacketDropRateClose existing, skipping..
2025-04-02 04:07:16,730 - __main__ - DEBUG - AutoConfig() do() processing portHighOpticalInputPower..
2025-04-02 04:07:16,730 - __main__ - DEBUG - AutoConfig() do() checking if portHighOpticalInputPower exists in config table..
2025-04-02 04:07:16,731 - __main__ - DEBUG - AutoConfig() do() portHighOpticalInputPower existing, skipping..
2025-04-02 04:07:16,731 - __main__ - DEBUG - AutoConfig() do() processing wanPortHighInboundDiscardsClose..
......
2025-04-02 04:07:19,066 - __main__ - DEBUG - AutoConfig() do() checking if linkUp exists in config table..
2025-04-02 04:07:19,067 - __main__ - DEBUG - AutoConfig() do() does not linkUp exist, going to create new snmpEventConfig()
2025-04-02 04:07:19,068 - __main__ - DEBUG - AutoConfig() do() linkUp - auto params: {"ifIndex": ".1.3.6.1.2.1.2.2.1.1", "ifAdminStatus": ".1.3.6.1.2.1.2.2.1.7", "ifOperStatus": ".1.3.6.1.2.1.2.2.1.8"}
2025-04-02 04:07:19,070 - __main__ - DEBUG - AutoConfig() do() linkUp - auto message: ifIndex : $ifIndex ifAdminStatus : $ifAdminStatus ifOperStatus : $ifOperStatus
2025-04-02 04:07:19,074 - __main__ - DEBUG - AutoConfig() do() snmpConfig for linkUp created with id 4434
5.Test ¶
Install net-snmp package and run command:
/usr/bin/snmptrap -v 2c -c public bmbttraps.webex.com "" .1.3.6.1.2.1.31.2.1.9 .1.3.6.1.2.1.31.1.2.1.3 i 0
truncating integer value > 32 bits