GithubHelp home page GithubHelp logo

carlkidcrypto / ezsnmp Goto Github PK

View Code? Open in Web Editor NEW
8.0 8.0 0.0 3.2 MB

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

Python 39.35% C 4.78% Makefile 0.28% Batchfile 0.30% C++ 55.15% Shell 0.14%
easysnmp ezsnmp net-snmp py-snmp snmp

ezsnmp's People

Contributors

carlkidcrypto avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ezsnmp's Issues

cibuildwheel [Tests]

Attempt to also run the pytests either before or after the cibuildwheel process.

Ensure MacOS Tests Work

Ensure that the MacOS tests run without seg faulting.
This can be a code issue or just a test issue.

cibuildwheel [Build]

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.

PyPi

Configure PyPi credentials to work for prod and non-prod.

Move to C++17

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 Sphinx Build works

Ensure that the GitHub workflow for the Sphinx build works.
This means it should work locally and in GA.

[Question] move from easysnmp fails with Auth errors

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}")

[BUG] v3 multi-threading fails due to user cache

EzSNMP release version OR commit number
1.0.0c

Operating System and Version

  • OS: Ubuntu
  • Version 22

Net-SNMP Library Version

  • 5.9.1

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.

[BUG] snmpv3 usmStatsNotInTimeWindows

EzSNMP release version OR commit number
1.0.0

Operating System and Version

  • OS: Ubuntu
  • Version 22

Net-SNMP Library Version

  • 5.9.1

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.