etingof / pysnmp

Python SNMP library
http://snmplabs.com/pysnmp/
BSD 2-Clause "Simplified" License
580 stars 200 forks source link

IEEE8023-LAG-MIB OID mismatch between .my and .py #92

Closed greenpau closed 7 years ago

greenpau commented 7 years ago

I have IEEE8023-LAG-MIB.my in /usr/share/snmp/mibs/ieee. The MIB gets loaded:

2017-10-11 21:30:35,038 pysnmp: loadModule: trying IEEE8023-LAG-MIB at DirMibSource('/root/.pysnmp/mibs')
2017-10-11 21:30:35,038 pysnmp [DEBUG] loadModule: trying IEEE8023-LAG-MIB at DirMibSource('/root/.pysnmp/mibs')
2017-10-11 21:30:35,039 pysnmp: file IEEE8023-LAG-MIB.pyc mtime 1507753662
2017-10-11 21:30:35,039 pysnmp [DEBUG] file IEEE8023-LAG-MIB.pyc mtime 1507753662
2017-10-11 21:30:35,039 pysnmp: file IEEE8023-LAG-MIB.py mtime 1507753662
2017-10-11 21:30:35,039 pysnmp [DEBUG] file IEEE8023-LAG-MIB.py mtime 1507753662
2017-10-11 21:30:35,040 pysnmp: loadModule: seen /root/.pysnmp/mibs/IEEE8023-LAG-MIB.pyc
2017-10-11 21:30:35,040 pysnmp [DEBUG] loadModule: seen /root/.pysnmp/mibs/IEEE8023-LAG-MIB.pyc

However, the resolution failed for OID 1.2.840.10006.300.43.1.2.1 dot3adAggPortTable.

2017-10-11 21:37:33,110 pysnmp: resolving ('1', '2', '840', '10006', '300', '43', '1', '2', '1') as OID or label
2017-10-11 21:37:33,110 pysnmp [DEBUG] resolving ('1', '2', '840', '10006', '300', '43', '1', '2', '1') as OID or label
2017-10-11 21:37:33,112 pysnmp: getNodeNameByOid: resolved :1.2.840.10006.300.43.1.2.1 -> ('iso',).2.840.10006.300.43.1.2.1
2017-10-11 21:37:33,112 pysnmp [DEBUG] getNodeNameByOid: resolved :1.2.840.10006.300.43.1.2.1 -> ('iso',).2.840.10006.300.43.1.2.1
2017-10-11 21:37:33,112 pysnmp: resolved (('1', '2', '840', '10006', '300', '43', '1', '2', '1'),) into prefix ObjectName('1') and suffix ObjectName('2.840.10006.300.43.1.2.1')
2017-10-11 21:37:33,112 pysnmp [DEBUG] resolved (('1', '2', '840', '10006', '300', '43', '1', '2', '1'),) into prefix ObjectName('1') and suffix ObjectName('2.840.10006.300.43.1.2.1')
2017-10-11 21:37:33,112 pysnmp: getNodeNameByOid: resolved :1 -> ('iso',).()
2017-10-11 21:37:33,112 pysnmp [DEBUG] getNodeNameByOid: resolved :1 -> ('iso',).()
2017-10-11 21:37:33,113 pysnmp: resolved prefix ObjectName('1') into MIB node MibTree((1,), None)
2017-10-11 21:37:33,113 pysnmp [DEBUG] resolved prefix ObjectName('1') into MIB node MibTree((1,), None)
2017-10-11 21:37:33,113 pysnmp: resolved indices are (ObjectName('2.840.10006.300.43.1.2.1'),)
2017-10-11 21:37:33,113 pysnmp [DEBUG] resolved indices are (ObjectName('2.840.10006.300.43.1.2.1'),)

I checked in /root/.pysnmp/mibs/IEEE8023-LAG-MIB.my and see the following lines for

dot3adAggPortTable = MibTable((1, 2, 840, 802, 10006, 300, 43, 1, 2, 1), )
if mibBuilder.loadTexts: dot3adAggPortTable.setReference('6.3.2')
if mibBuilder.loadTexts: dot3adAggPortTable.setStatus('current')
dot3adAggPortEntry = MibTableRow((1, 2, 840, 802, 10006, 300, 43, 1, 2, 1, 1), ).setIndexNames((0, "IEEE8023-LAG-MIB", "dot3adAggPortIndex"))
if mibBuilder.loadTexts: dot3adAggPortEntry.setStatus('current')
dot3adAggPortIndex = MibTableColumn((1, 2, 840, 802, 10006, 300, 43, 1, 2, 1, 1, 1), InterfaceIndex())

The MIB speaks about 840.10006. In the IEEE8023-LAG-MIB.my, there is 840, 802, 10006.

Any ideas how 802 got there?

greenpau commented 7 years ago

Once I did :%s/840, 802, 10006/840, 10006/g the resolution works.

etingof commented 7 years ago

This is interesting, but I can't reproduce this problem. Here is what I do:

$ pip install pysmi
Collecting pysmi
  Using cached pysmi-0.1.3-py2.py3-none-any.whl
Requirement already satisfied: ply in ./pysmi/venv34/lib/python3.4/site-packages (from pysmi)
Installing collected packages: pysmi
Successfully installed pysmi-0.1.3
$
$ mibdump.py --generate-mib-texts --destination-format=pysnmp  --rebuild IEEE8023-LAG-MIB
Source MIB repositories: file:///usr/share/snmp/mibs, http://mibs.snmplabs.com/asn1/@mib@
Borrow missing/failed MIBs from: http://mibs.snmplabs.com/pysnmp/fulltexts/@mib@
Existing/compiled MIB locations: pysnmp.smi.mibs, pysnmp_mibs
Compiled MIBs destination directory: /home/user/.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: IEEE8023-LAG-MIB
Destination format: pysnmp
Parser grammar cache directory: not used
Also compile all relevant MIBs: yes
Rebuild MIBs regardless of age: yes
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: yes
Keep original texts layout: no
Try various file names while searching for MIB module: yes
Created/updated MIBs: IEEE8023-LAG-MIB
Pre-compiled MIBs borrowed: 
Up to date MIBs: SNMPv2-CONF, SNMPv2-SMI, SNMPv2-TC
Missing source MIBs: 
Ignored MIBs: 
Failed MIBs: 
$
$ grep 'dot3adAggPortTable = ' ~/.pysnmp/mibs/IEEE8023-LAG-MIB.py 
dot3adAggPortTable = MibTable((1, 2, 840, 10006, 300, 43, 1, 2, 1), )
$ 

What pysmi version are you using?

Can you make sure that IEEE8023-LAG-MIB.my that gets compiled has the correct OID in the first place? You can see the ASN.1 MIBs being loaded by enabling pysmi debugging:

from pysmi import debug

debug.setLogger(debug.Debug('all'))
greenpau commented 7 years ago

Can you make sure that IEEE8023-LAG-MIB.my that gets compiled has the correct OID in the first place?

@etingof, will do that.

Here are some details about the system. It is a regular RHEL 7.3 build. Based on the output you provided, you are using Python 3.4.

# hostnamectl
...
  Operating System: Red Hat Enterprise Linux Server 7.3 (Maipo)
       CPE OS Name: cpe:/o:redhat:enterprise_linux:7.3:GA:server
            Kernel: Linux 3.10.0-514.21.1.el7.x86_64
      Architecture: x86-64

# pip list | grep pysnmp
pysnmp (4.3.10)

# python -V
Python 2.7.5
etingof commented 7 years ago

@greenpau

Just in case, make sure you are running reasonably fresh pysmi package:

$ python -c 'import pysmi; print(pysmi.__version__)'
0.1.3

I just re-run the same test with Python 2.7 - it still works:

$ pip install pysmi
You are using pip version 6.0.8, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting pysmi
  Using cached pysmi-0.1.3-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): ply in ./pysmi/venv27/lib/python2.7/site-packages (from pysmi)
Installing collected packages: pysmi
Successfully installed pysmi-0.1.3
(venv27)$ mibdump.py --generate-mib-texts --destination-format=pysnmp  --rebuild IEEE8023-LAG-MIB
Source MIB repositories: file:///usr/share/snmp/mibs, http://mibs.snmplabs.com/asn1/@mib@
Borrow missing/failed MIBs from: http://mibs.snmplabs.com/pysnmp/fulltexts/@mib@
Existing/compiled MIB locations: pysnmp.smi.mibs, pysnmp_mibs
Compiled MIBs destination directory: /home/user/.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: IEEE8023-LAG-MIB
Destination format: pysnmp
Parser grammar cache directory: not used
Also compile all relevant MIBs: yes
Rebuild MIBs regardless of age: yes
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: yes
Keep original texts layout: no
Try various file names while searching for MIB module: yes
Created/updated MIBs: IEEE8023-LAG-MIB
Pre-compiled MIBs borrowed: 
Up to date MIBs: SNMPv2-CONF, SNMPv2-SMI, SNMPv2-TC
Missing source MIBs: 
Ignored MIBs: 
Failed MIBs: 
(venv27)$ grep 'dot3adAggPortTable = ' ~/.pysnmp/mibs/IEEE8023-LAG-MIB.py 
dot3adAggPortTable = MibTable((1, 2, 840, 10006, 300, 43, 1, 2, 1), )

Based on the reporting coming from the mibdump.py --debug reader ... invocation, I'm getting the IEEE8023-LAG-MIB from http://mibs.snmplabs.com/asn1/IEEE8023-LAG-MIB:

2017-10-12 16:34:28,894 pysmi: looking for MIB IEEE8023-LAG-MIB
2017-10-12 16:34:28,894 pysmi: trying to fetch MIB from http://mibs.snmplabs.com:80/asn1/IEEE8023-LAG-MIB
2017-10-12 16:34:29,636 pysmi: HTTP response 200
2017-10-12 16:34:29,647 pysmi: fetching source MIB /asn1/IEEE8023-LAG-MIB, mtime Tue, 05 May 2015 18:22:29 GMT
greenpau commented 7 years ago

Just in case, make sure you are running reasonably fresh pysmi package:

@etingof , here is mine.

# python -c 'import pysmi; print(pysmi.__version__)'
0.1.3

Compiled per your suggestion, I deleted the py* files from .pysnmp dir and rebuilt:

# python mibdump.py --generate-mib-texts --destination-format=pysnmp  --rebuild IEEE8023-LAG-MIB
Source MIB repositories: file:///usr/share/snmp/mibs, http://mibs.snmplabs.com/asn1/@mib@
Borrow missing/failed MIBs from: http://mibs.snmplabs.com/pysnmp/fulltexts/@mib@
Existing/compiled MIB locations: pysnmp.smi.mibs, pysnmp_mibs
Compiled MIBs destination directory: /root/.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: IEEE8023-LAG-MIB
Destination format: pysnmp
Parser grammar cache directory: not used
Also compile all relevant MIBs: yes
Rebuild MIBs regardless of age: yes
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: yes
Keep original texts layout: no
Try various file names while searching for MIB module: yes
Created/updated MIBs: BRIDGE-MIB, IANAifType-MIB, IEEE8023-LAG-MIB, IF-MIB, P-BRIDGE-MIB, Q-BRIDGE-MIB, RFC1271-MIB, RMON-MIB, RMON2-MIB, SNMPv2-MIB, TOKEN-RING-RMON-MIB
Pre-compiled MIBs borrowed:
Up to date MIBs: RFC-1212, RFC-1215, RFC1155-SMI, RFC1213-MIB, SNMP-FRAMEWORK-MIB, SNMPv2-CONF, SNMPv2-SMI, SNMPv2-TC
Missing source MIBs:
Ignored MIBs:
Failed MIBs:

Once compiled, I still see the 802:

dot3adAggPort = MibIdentifier((1, 2, 840, 802, 10006, 300, 43, 1, 2))

The thing is that when I do snmpwalk everything works and resolves. In your output you fetch the MIB from mibs.snmplabs.com. Perhaps, the issue is in the difference between MIBs.

I am using MIBs from https://github.com/robison/snmp-config

etingof commented 7 years ago

You are right - that looks like a bug in pysmi parser. It shows up with the latest MIB version.

I will look into the code and report back here.

etingof commented 7 years ago

OK, commit 2e6b9e8a0b8b379c1faed034ad1300441f0b0341 should fix this.

I can make a release if current pysmi master works for you.

greenpau commented 7 years ago

OK, commit 2e6b9e8a0b8b379c1faed034ad1300441f0b0341 should fix this.

@etingof , kudos for the fix! 👍 For now, I manually fixed it. Will wait for the next release in pypi 😄

Thank you very much! Спасибо что посмотрел! Удач!

etingof commented 7 years ago

Released pysmi 0.1.4 on PyPI and updated MIBs at http://mibs.snmplabs.com/asn1/