Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

objectIdentity object not properly initialized #223

Open
CharlesJu1 opened this issue Nov 27, 2018 · 8 comments
Open

objectIdentity object not properly initialized #223

CharlesJu1 opened this issue Nov 27, 2018 · 8 comments

Comments

@CharlesJu1
Copy link

I installed pysnmp and tried examples from the website snmplabs.com. I got the following error:

cju@ubuntu-16:~$ python3
Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> 
>>> from pysnmp.hlapi import *
>>> x = ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)
>>> 
>>> tuple(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/cju/.local/lib/python3.5/site-packages/pysnmp/smi/rfc1902.py", line 606, in __len__
    raise SmiError('%s object not properly initialized' % self.__class__.__name__)
pysnmp.smi.error.SmiError: ObjectIdentity object not properly initialized

However, I could run the following example code ok.

>>> errorIndication, errorStatus, errorIndex, varBinds = next(
...     getCmd(SnmpEngine(),
...            CommunityData('public', mpModel=0),
...            UdpTransportTarget(('demo.snmplabs.com', 161)),
...            ContextData(),
...            ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)))
... )
>>> 
>>> if errorIndication:
...     print(errorIndication)
... elif errorStatus:
...     print('%s at %s' % (errorStatus.prettyPrint(),
...                         errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
... else:
...     for varBind in varBinds:
...         print(' = '.join([x.prettyPrint() for x in varBind]))
... 
SNMPv2-MIB::sysDescr.0 = Linux zeus 4.8.6.5-smp #2 SMP Sun Nov 13 14:58:11 CDT 2016 i686
@etingof
Copy link
Owner

etingof commented Nov 27, 2018

That's right, ObjectIdentity works lazily. If you want it to get resolved against a MIB you need to explicitly call .resolveWithMib() as noted in the docs.

You will also need the MibViewController object, just follow this example - the first three lines of that script seem to do what you are trying to do.

@CharlesJu1
Copy link
Author

Thanks etingof. It works following your reply. I now understand that pysnmp needs mibs to be installed as a python module named like mibname.py. Is there a command to install some other mibs besides the built-in mibs installed along with pysnmp? How to list what mibs are already installed?

@etingof
Copy link
Owner

etingof commented Nov 27, 2018

No need to compile MIB files into Python. If you configure the source of ASN.1 MIBs, the translation would happen behind the scene.

But you can also compile ASN.1 MIB(s) into Python with mibdump tool.

@CharlesJu1
Copy link
Author

If I configure the source of ASN.1 MIBs, it will download and translate the ASN.1 MIB on the fly. That may take some more time than a local copy of MIB. I noticed that SNMPv2-MIB.py exists both in ~/.pysnmp/mibs and ~/.local/lib/python3.5/site-packages/pysnmp/smi/mibs. However, IF-MIB.py only exists in ~/.pysnmp/mibs folder. Why is that?

@etingof
Copy link
Owner

etingof commented Nov 27, 2018

If I configure the source of ASN.1 MIBs, it will download and translate the ASN.1 MIB on the fly. That may take some more time than a local copy of MIB.

This downloading and translation happens just once and results in caching the translated module in ~/.pysnmp/mibs/. Once cached files are there, no more translation should occur.

I noticed that SNMPv2-MIB.py exists both in ~/.pysnmp/mibs and ~/.local/lib/python3.5/site-packages/pysnmp/smi/mibs. However, IF-MIB.py only exists in ~/.pysnmp/mibs folder. Why is that?

I am guessing that you played with MIB compiler at the moment when pysnmp was not available so the compiler tried to translate SNMPv2-MIB.py. Normally, you should use SNMPv2-MIB.py shipped with pysnmp because this is one of the core MIBs that are not fully translatable because they require some custom code on top of automatically generated code.

@CharlesJu1
Copy link
Author

Thanks etingof. When using mibdump.py to generate MIBs in pysnmp format, can I generate mib indices? Where is the indices file and how it is used?

@frsoto
Copy link

frsoto commented Jan 15, 2023

MibViewController

Hi.
the link no longer exists
I have the same doubt

Regards..

@lextm
Copy link

lextm commented Jan 16, 2023

@frsoto You can read #429 for more details. The domain snmplabs.com was lost so any connection to it today is risky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants