carlkidcrypto / ezsnmp Goto Github PK
View Code? Open in Web Editor NEWAn unattached Fork of Easy SNMP. Built for Python3.8 and greater only. Using C++17.
Home Page: https://carlkidcrypto.github.io/ezsnmp/
License: Other
An unattached Fork of Easy SNMP. Built for Python3.8 and greater only. Using C++17.
Home Page: https://carlkidcrypto.github.io/ezsnmp/
License: Other
Ensure that the MacOS tests run without seg faulting.
This can be a code issue or just a test issue.
Add support for the https://github.com/net-snmp/net-snmp/blob/master/apps/snmpset.c application via a SWIG interface file.
Attempt to also run the pytests either before or after the cibuildwheel process.
For the V2.0.0 version, there will be breaking changes. We will be moving to making the python bindings using SWIG https://www.swig.org/. Rather than make our own interface we can reuse the code already written by the net-snmp team https://github.com/net-snmp/net-snmp/apps.
Use cibuildwheel to build as many wheels as we can. Let's try to use net-snmp 5.9.4 and build it from the source code.
This issue was observed in #44. When running under a multi-thread or multi-process application
V3 session will show
EzSNMPError: USM unknown security name (no such user exists)
errors.
This doesn't appear consistent. It appears random at this moment.
@mtuska opening this new issue to track the USM error.
Trying to use ezsnmp, in an application that uses relies quite heavily on easysnmp.
By installing via "pip3 install ezsnmp", and replacing all occurances, I get errors for anything using snmp v3 with devices that work with easysnmp:
"File "/opt/openl2m/venv/lib/python3.11/site-packages/ezsnmp/session.py", line 478, in bulkwalk
interface.bulkwalk(self, non_repeaters, max_repetitions, varlist)
ezsnmp.exceptions.EzSNMPError: Authentication failure (incorrect password, community or key)
"
Environment:
Ubuntu 22.04.4, fully patched, with Net-Snmp 5.9.1
Even a simple script fails. If using easysnmp, both v2c and v3 work, if using ezsnmp.Session(), v3 fails.
What am I missing ?
Johan
import ezsnmp
import easysnmp
system = ".1.3.6.1.2.1.1"
snmpv2 = ezsnmp.Session(
hostname="10.1.1.1",
version=2,
community="read_only",
)
items = snmpv2.bulkwalk(oids=system)
for item in items:
print(f"Found: {item}")
snmpv3 = ezsnmp.Session(
hostname="10.1.1.1",
version=3,
security_level=u"auth_without_privacy",
security_username=u"view",
auth_protocol=u"SHA",
auth_password=u"password",
)
items = snmpv3.bulkwalk(oids=system)
for item in items:
print(f"Found: {item}")
Currently, we don't build ARM for MacOS. https://github.com/carlkidcrypto/ezsnmp/blob/main/pyproject.toml#L36
It was broken and not working. Attempt to remove line 36 in the file linked above. See if it works now. It's possible the cibuildhweel containers and GA containers have been updated to work now.
Per https://devguide.python.org/versions/ Python 3.13 is prerelease. Let's add experimental support to start working out new kinks and issues.
Add support for it via the setup.cfg file.
Ensure all tests pass and smoke test on a local machine. Both MacOS and Linux.
EzSNMP release version OR commit number
1.0.0c
Operating System and Version
Net-SNMP Library Version
Describe the bug
When using multiple threads with snmpv3, the user cache will be cleared when one of the sessions is ended thus causing the other threads to fail.
To Reproduce
The pytest I've built to replicate this issue:
test_threading.py
from __future__ import unicode_literals
import platform
import re
import pytest
from ezsnmp.exceptions import (
EzSNMPError,
EzSNMPConnectionError,
EzSNMPTimeoutError,
EzSNMPNoSuchObjectError,
EzSNMPNoSuchInstanceError,
EzSNMPNoSuchNameError,
)
from ezsnmp.session import Session
import concurrent.futures
@pytest.mark.parametrize("workers", [1, 8, 16])
@pytest.mark.parametrize("jobs", [16])
def test_session_threaded(sess_args, workers, jobs):
def do_work(sess_args):
sess = Session(**sess_args)
res = sess.get([("sysUpTime", "0"), ("sysContact", "0"), ("sysLocation", "0")])
assert len(res) == 3
assert res[0].oid == "sysUpTimeInstance"
assert res[0].oid_index == ""
assert int(res[0].value) > 0
assert res[0].snmp_type == "TICKS"
assert res[1].oid == "sysContact"
assert res[1].oid_index == "0"
assert res[1].value == "G. S. Marzot <[email protected]>"
assert res[1].snmp_type == "OCTETSTR"
assert res[2].oid == "sysLocation"
assert res[2].oid_index == "0"
assert res[2].value == "my original location"
assert res[2].snmp_type == "OCTETSTR"
with concurrent.futures.ThreadPoolExecutor(max_workers=workers) as executor:
futures = [executor.submit(do_work, sess_args) for _ in range(jobs)]
for future in futures:
future.result()
When it's 1 worker it'll pass without issue, but the 8/16 workers will fail.
To remediate the issue, I was able to comment out the call to "__remove_user_from_cache" on line 1611 to have the test pass. Probably not the ideal fix, but seems to confirm the issue is related to the user caching.
Expected behavior
SNMPv3 sessions work in multiple threads.
Add support for the https://github.com/net-snmp/net-snmp/blob/master/apps/snmptrap.c application via a SWIG interface file.
The world has advanced and changed. Thus let's move to C++17 for now.
We can use smart pointers so we have "no" memory leaks.
Ensure that the GitHub workflow for the Sphinx build works.
This means it should work locally and in GA.
What's on your mind?
I'm very confused with SNMPVariableList
in variables.py
? is this object only a simple shortcut for List[SNMPVariable]
?
varbinds
method in class definition only return itself and it's inherited from list.
how the varbinds work?
Per https://devguide.python.org/versions/ Python 3.8 is EOL at the end of October 2024.
Drop Support for it via the setup.cfg file
**Is your feature request related to a problem? No
Thanks for the great forking version.
Since it's not very clear for return type or params type for basic api and lack of IDE autocompletions.
Iโm not familar with C++ code, but I can make some contributions for python part to improve type hint.
EzSNMP release version OR commit number
1.0.0
Operating System and Version
Net-SNMP Library Version
Describe the bug
When connecting to multiple devices via multithreading, the net-snmp user caching will also cache the engine id, boots, time with the user. Thus as it connects to multiple different devices can cause either blocking or interrupting with error "usmStatsNotInTimeWindows".
To Reproduce
Haven't worked extensively with snmpd so not sure if you could create multiple engines with differing time/boots/engineids.
Expected behavior
Each thread gets it's own caching/memory to avoid clashing.
Additional context
To bypass this issue within python, have switched to using multi-processing in python instead to give each their own space. Not sure how feasible it would be to correct the issue on the same process.
Use the latest version of MacPorts https://github.com/macports/macports-base/releases/tag/v2.10.1.
Update the pyproject.toml
files' URL.
Investigate if we can automate this via the Github dependabot tool.
Configure PyPi credentials to work for prod and non-prod.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.