lextudio / pysnmp

Python SNMP library
https://www.pysnmp.com/pysnmp/
BSD 2-Clause "Simplified" License
77 stars 19 forks source link

AttributeError: 'ObjectGroup' object has no attribute 'setReference' #11

Open mofikus opened 1 year ago

mofikus commented 1 year ago

I've compiled a bunch of mibs, and have them stored in a folder. When running something like the following to get OIDs and descriptions from compiled MIBs, with the CISCO-ENHANCED-IPSEC-FLOW-MIB I get an error.

The code I'm running:

from pysnmp.smi import builder, view, error
mibBuilder = builder.MibBuilder()
mibBuilder.loadTexts = True
mibBuilder.addMibSources(builder.DirMibSource("C:\\Users\\mmiller\\Documents\\tools_etc\\python_projects\\testingMIBS\\temp\\"))
mibBuilder.loadModules(*['CISCO-ENHANCED-IPSEC-FLOW-MIB'])
mibView = view.MibViewController(mibBuilder)
oid, oid_name, _ = mibView.getFirstNodeName()
while True:
    try:
        mib_name, oid_name, suffix = mibView.getNodeLocation(oid)
        oid_info, = mibBuilder.importSymbols(mib_name, oid_name)
        print(oid, oid_name, getattr(oid_info,'description',""))
        oid, oid_name, suffix = mibView.getNextNodeName(oid)
    except error.NoSuchObjectError:
        break

The exception I get:

Traceback (most recent call last):
  File "C:\testing\python_projects\testingMIBS\venv\lib\site-packages\pysnmp\smi\builder.py", line 357, in loadModule
    exec(codeObj, g)
  File ".pysnmp-mibs\CISCO-ENHANCED-IPSEC-FLOW-MIB.py", line 806, in <module>
    if mibBuilder.loadTexts: ciscoEnhIPsecFlowActivityGroup.setReference('rfc2408, rfc2407; rfc2409 section 5.5')
AttributeError: 'ObjectGroup' object has no attribute 'setReference'

I've attached a zip with the original MIB file and the compiled .py mib file.

Thanks

issue.zip

lextm commented 1 year ago

Thanks for the report.

There are a few things you might check,

The Python packages you are using

We are using the latest Python packages from our own, https://github.com/etingof/pysnmp/issues/429 So, you need mibdump from pysmi-lextudio 1.1.13 and then the compiled .py for the MIB document can work with pysnmp-lextudio 5.0.25.

This repo does not support any other distribution of PySNMP bits as part of our support policies.

The MIB document to test

We cannot reproduce the issue with the MIB document from https://raw.githubusercontent.com/lextudio/mibs.pysnmp.com/master/asn1/CISCO-ENHANCED-IPSEC-FLOW-MIB

Due to our support policies, we didn't test the copy you provided, but feel free to let us know if the issue remains after you switch to our supported Python packages.

mofikus commented 1 year ago

I am using the lextudio packages. I just tried to uninstall pysnmp and pysmi and get:

(venv) C:\testing\python_projects\testingMIBS>pip3 uninstall pysnmp
WARNING: Skipping pysnmp as it is not installed.

(venv) C:\testing\python_projects\testingMIBS>pip3 uninstall pysmi
WARNING: Skipping pysmi as it is not installed.

But uninstalling the lextudio packages works:

(venv) C:\testing\python_projects\testingMIBS>pip3 uninstall pysnmp-lextudio
Found existing installation: pysnmp-lextudio 5.0.25
Uninstalling pysnmp-lextudio-5.0.25:
  Would remove:
    C:\testing\python_projects\testingmibs\venv\lib\site-packages\pysnmp\*
    C:\testing\python_projects\testingmibs\venv\lib\site-packages\pysnmp_lextudio-5.0.25.dist-info\*
Proceed (Y/n)? y
  Successfully uninstalled pysnmp-lextudio-5.0.25
(venv) C:\testing\python_projects\testingMIBS>pip3 uninstall pysmi-lextudio
Found existing installation: pysmi-lextudio 1.1.13
Uninstalling pysmi-lextudio-1.1.13:
  Would remove:
    C:\testing\python_projects\testingmibs\venv\lib\site-packages\pysmi\*
    C:\testing\python_projects\testingmibs\venv\lib\site-packages\pysmi_lextudio-1.1.13.dist-info\*
    C:\testing\python_projects\testingmibs\venv\scripts\mibcopy.exe
    C:\testing\python_projects\testingmibs\venv\scripts\mibdump.exe
Proceed (Y/n)? y
  Successfully uninstalled pysmi-lextudio-1.1.13

I've now re-installed the packages and the issue still occurs.

If I add the following to the ObjectGroup class in pysnmp > smi > mibs > SNMPv2-CONF.py then I no longer face the issue:

    def getReference(self):
        return self.reference

    def setReference(self, v):
        self.reference = v
        return self

I'm not sure if this is correct but it stops the issue. The same is true for the NotificationGroup class in that file also.