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
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.
Attempt to also run the pytests either before or after the cibuildwheel process.
Ensure that the MacOS tests run without seg faulting.
This can be a code issue or just a test issue.
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.
Configure PyPi credentials to work for prod and non-prod.
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.
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}")
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.
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.
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.