Coder Social home page Coder Social logo

gufolabs / gufo_snmp Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 0.0 1.06 MB

Gufo SNMP is the accelerated Python SNMP library

License: Other

Dockerfile 0.22% Shell 1.33% Rust 68.25% Python 30.19%
async gufo networking pypi python rust snmp typed pyo3 snmpv3

gufo_snmp's Introduction

Gufo SNMP

The accelerated Python SNMP client library.

PyPi version Python Versions License Build Sponsors Ruff


Documentation: https://docs.gufolabs.com/gufo_snmp/

Source Code: https://github.com/gufolabs/gufo_snmp/


Gufo SNMP is the accelerated Python SNMP client library supporting both async and synchronous mode. It consists of a clean Python API for high-efficient BER parser and socket IO, implemented in the Rust language with PyO3 wrapper.

The querying of the single MIB key is a simple task:

from gufo.snmp import SnmpSession

async with SnmpSession(addr="127.0.0.1", community="public") as session:
    r = await session.get("1.3.6.1.2.1.1.3.0")

And the blocking mode shares virtually the same API:

from gufo.snmp.sync_client import SnmpSession

with SnmpSession(addr="127.0.0.1", community="public") as session:
    r = session.get("1.3.6.1.2.1.1.3.0")

Multiple keys can be queried by one request too:

async with SnmpSession(addr="127.0.0.1", community="public") as session:
    r = await session.get_many(["1.3.6.1.2.1.1.3.0", "1.3.6.1.2.1.1.2.0"])

The querying of the MIB parts is also available with GetNext request:

async with SnmpSession(addr="127.0.0.1", community="public") as session:
    async for oid, value in  session.getnext("1.3.6.1.2.1.1"):
        ...

And with GetBulk request:

async with SnmpSession(addr="127.0.0.1", community="public") as session:
    async for oid, value in  session.getbulk("1.3.6.1.2.1.1"):
        ...

The .fetch() method allows to choose between .getnext() and .getbulk() automatically:

async with SnmpSession(addr="127.0.0.1", community="public") as session:
    async for oid, value in  session.fetch("1.3.6.1.2.1.1"):
        ...

SNMPv3 shares same API and semantics:

async with SnmpSession(
    addr="127.0.0.1",
    user=User(
        "user1",
        auth_key=Sha1Key(b"12345678"),
        priv_key=Aes128Key(b"87654321")
    )
) as session:
    r = await session.get("1.3.6.1.2.1.1.3.0")

Gufo SNMP also allows to limit rate of outgoing requests to protect equipment from overloading:

async with SnmpSession(addr="127.0.0.1", community="public", limit_rps=10) as session:
    async for oid, value in  session.fetch("1.3.6.1.2.1.1"):
        ...

Gufo SNMP offers various tools for developers, including a wrapper to run a local instance of SNMP daemon:

async with Snmpd(), SnmpSession(addr="127.0.0.1", port=10161) as session:
    r = await session.get("1.3.6.1.2.1.1.3.0")

Features

  • Clean async and blocking API.
  • SNMP v1/v2c/v3 support.
  • SNMP v3 User Security Model:
    • Authentication: HMAC-MD5-96, HMAC-SHA-96.
    • Privacy: DES, AES128.
    • Engine ID discovery.
  • High-performance.
  • Built with security in mind.
  • Zero-copy BER parsing.
  • Query rate limiting.
  • Full Python typing support.
  • Editor completion.
  • Well-tested, battle-proven code.
  • Thoroughly check compatibility with various network equipment.

Further Roadmap

  • SHA2 family of hashes.
  • AES256 encryption.
  • SNMP Trap and Inform collector.
  • Incorporation of the NOC's Compiled MIB infrastructure.

On Gufo Stack

This product is a part of Gufo Stack - the collaborative effort led by Gufo Labs. Our goal is to create a robust and flexible set of tools to create network management software and automate routine administration tasks.

To do this, we extract the key technologies that have proven themselves in the NOC and bring them as separate packages. Then we work on API, performance tuning, documentation, and testing. The NOC uses the final result as the external dependencies.

Gufo Stack makes the NOC better, and this is our primary task. But other products can benefit from Gufo Stack too. So we believe that our effort will make the other network management products better.

gufo_snmp's People

Contributors

dvolodin7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

gufo_snmp's Issues

BUG: install gufo-snmp on Mac (m3) fails on rust issue

Describe the issue:

tried installing the package on my MacBook Pro m3 pro laptop but it ran into a problem.
I have no issues on another laptop that runs ubuntu

Reproduce the code example:

pdm add gufo-snmp

Error message:

(inetutils-python-3.12) sh-3.2# pdm add gufo-snmp
Adding packages to default dependencies: gufo-snmp
๐Ÿ”’ Lock successful
Changes are written to pyproject.toml.
Synchronizing working set with resolved packages: 1 to add, 0 to update, 0 to remove

  โœ– Install gufo-snmp 0.5.0 failed
Retry failed jobs
  โœ– Install gufo-snmp 0.5.0 failed

ERRORS:
add gufo-snmp failed:
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/[email protected]/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nielsvanhooij/Library/Application Support/pdm/venv/lib/python3.12/site-packages/pdm/installers/synchronizers.py", line 285, in install_candidate
    self.manager.install(can)
  File "/Users/nielsvanhooij/Library/Application Support/pdm/venv/lib/python3.12/site-packages/pdm/installers/manager.py", line 34, in install
    dist_info = installer(str(prepared.build()), self.environment, prepared.direct_url())
                              ^^^^^^^^^^^^^^^^
  File "/Users/nielsvanhooij/Library/Application Support/pdm/venv/lib/python3.12/site-packages/pdm/models/candidates.py", line 418, in build
    self.wheel = Path(builder.build(build_dir, metadata_directory=self._metadata_dir))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nielsvanhooij/Library/Application Support/pdm/venv/lib/python3.12/site-packages/pdm/builders/wheel.py", line 28, in build
    filename = self._hook.build_wheel(out_dir, config_settings, metadata_directory)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nielsvanhooij/Library/Application Support/pdm/venv/lib/python3.12/site-packages/pyproject_hooks/_impl.py", line 209, in build_wheel
    return self._call_hook('build_wheel', {
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nielsvanhooij/Library/Application Support/pdm/venv/lib/python3.12/site-packages/pyproject_hooks/_impl.py", line 311, in _call_hook
    self._subprocess_runner(
  File "/Users/nielsvanhooij/Library/Application Support/pdm/venv/lib/python3.12/site-packages/pdm/builders/base.py", line 261, in subprocess_runner
    return log_subprocessor(cmd, cwd, extra_environ=env)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nielsvanhooij/Library/Application Support/pdm/venv/lib/python3.12/site-packages/pdm/builders/base.py", line 107, in log_subprocessor
    raise build_error(e) from None
pdm.exceptions.BuildError: Build backend raised error: Showing the last 10 lines of the build output:
adding license file 'LICENSE.md'
writing manifest file 'src/gufo_snmp.egg-info/SOURCES.txt'
running build_ext
running build_rust
cargo rustc --lib --message-format=json-render-diagnostics --manifest-path Cargo.toml --release -v --features pyo3/extension-module --crate-type cdylib -- -C link-args=-undefined dynamic_lookup -Wl,-install_name,@rpath/_fast.cpython-312-darwin.so
error: failed to parse manifest at `/private/tmp/pdm-build-bffi8i33/Cargo.toml`

Caused by:
  can't find `cri_decode` bench at `benches/cri_decode.rs` or `benches/cri_decode/main.rs`. Please specify bench.path if you want to use a non-default path.
error: `cargo rustc --lib --message-format=json-render-diagnostics --manifest-path Cargo.toml --release -v --features pyo3/extension-module --crate-type cdylib -- -C 'link-args=-undefined dynamic_lookup -Wl,-install_name,@rpath/_fast.cpython-312-darwin.so'` failed 
with code 101

Python version information

3.12

Gufo Ping version information

0.5.0

Operation system version

macOS Sonoma 14.3.1

BUG: Getting FileNotFoundError exception if multiple instances of SnmpSession were previously used

Describe the issue:

Getting a FileNotFoundError exception if multiple instances of SnmpSession were previously used.

Reproduce the code example:

import asyncio
from gufo.snmp import SnmpSession

async def run_multiple_sessions() -> None:
    for i in range(10):
        async with SnmpSession(
            addr="127.0.0.1",
            community="public"
        ) as session:
            async for _ in session.fetch("1.3.6.1.2.1.1"):
                pass

asyncio.run(run_multiple_sessions())

Error message:

Traceback (most recent call last):
  File "/opt/gufo-snmp/run-multiple.py", line 13, in <module>
    asyncio.run(run_multiple_sessions())
  File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/opt/gufo-snmp/run-multiple.py", line 10, in run_multiple_sessions
    async for _ in session.fetch("1.3.6.1.2.1.1"):
  File "/opt/gufo-snmp/venv/lib/python3.9/site-packages/gufo/snmp/getbulk.py", line 74, in __anext__
    loop.add_writer(self._fd, w_ev.set)
  File "/usr/lib/python3.9/asyncio/selector_events.py", line 346, in add_writer
    self._add_writer(fd, callback, *args)
  File "/usr/lib/python3.9/asyncio/selector_events.py", line 304, in _add_writer
    self._selector.modify(fd, mask | selectors.EVENT_WRITE,
  File "/usr/lib/python3.9/selectors.py", line 390, in modify
    self._selector.modify(key.fd, selector_events)
FileNotFoundError: [Errno 2] No such file or directory

Python version information

3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110

Gufo Ping version information

0.1.0

Operation system version

Debian GNU/Linux 11 (bullseye)

ENH: <sync version support>

Proposed new feature or change:

appreciate hardworking on this project. Is there any possible to support sync version rather that async only?

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.