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

get("1.3.6.1.2.1.2.1.0") good; get(OID("1.3.6.1.2.1.2.1.0")) throws exception #110

Open
mmaney opened this issue Feb 16, 2023 · 1 comment

Comments

@mmaney
Copy link

mmaney commented Feb 16, 2023

It seems that despite many of the examples showing it this way, get() (at least) does NOT accept an ObjectIdentifier object - it wants that string and nothing else, raising

AttributeError: 'ObjectIdentifier' object has no attribute 'startswith'

just as OID(OID("1.3.6.1.2.1.2.1.0")) does.

Although most (?) of the puresnmp code appears to pass the oid value around without worrying much about what it is, it all goes wrong when "oid" is an ObjectIdentifier rather than a string like so:

File "/home/snmpmon/rrd/pst2.py", line 8, in example
output = await client.get(oid)
File "/home/snmpmon/.local/lib/python3.9/site-packages/puresnmp/api/pythonic.py", line 68, in get
oid_internal = ObjectIdentifier(oid)
File "/home/snmpmon/.local/lib/python3.9/site-packages/x690/types.py", line 738, in init
and value.startswith(".")

It would seem that mypy OUGHT to be raising heck about passing an ObjectIdentifier into x690's ObjectIdentifier() - does it just not understand the X690Type[str] annotation, perhaps?

Freshly pip installed, x690.version = '1.0.0.post1', puresnmp.version = '2.0.0.post1' on Debian Bullseye with Py3.9

@mmaney
Copy link
Author

mmaney commented Feb 19, 2023

Apparently all my confusion was caused by all (?) the examples being the "docs" for raw Client, but the advice being to use PyWrapper(Client), which of course I did, so of course OID arguments make it go boom. And this is a problem because the docs are really just method signatures, augmented by those examples. Great practical example of why code makes poor documentation. :-/

For example: Does multiget() always return exactly one value for each OID in exactly the same order? I'd like to be able to assume that, as it's not very useful if it doesn't, but nothing says so. The latter seems to be empirically true, but I haven't tested the former assumption. But at least I can just check len(output) == len(oids) for that possible breakdown. And it's only a further guess that it returns None for oids that don't receive an answer. Hmmm, what if the whole inquiry goes unanswered?

Or I could dive into the code far enough to figure it out, but then I'm back where I was with net-snmp years ago... without the MIB complications, at least.

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

1 participant