Skip to main content

A blazingly fast and Pythonic SNMP library based on the official Net-SNMP bindings.

Project description

Python Code Style Black Pull Request Sphinx Docs Check PyPI Distributions TestPyPI Distributions Tests License

Ez SNMP Logo

Artwork courtesy of Open Clip Art Library

Introduction

Ez SNMP is a fork of Easy SNMP

Why Another Library?

  • Simple, because the maintainer of Easy SNMP seems to have abandoned the project and or isn’t actively working on it.

  • This version (Ez SNMP) will attempt to remain up to date with Python versions that are supported by Python and net-snmp versions that are supported by Net-SNMP

Quick Start

There are primarily two ways you can use the Ez SNMP library:

1. By using a Session object which is most suitable when you want to request multiple pieces of SNMP data from a source:

from ezsnmp import Session

# Create an SNMP session to be used for all our requests
session = Session(hostname='localhost', community='public', version=2)

# You may retrieve an individual OID using an SNMP GET
location = session.get('sysLocation.0')

# You may also specify the OID as a tuple (name, index)
# Note: the index is specified as a string as it can be of other types than
# just a regular integer
contact = session.get(('sysContact', '0'))

# And of course, you may use the numeric OID too
description = session.get('.1.3.6.1.2.1.1.1.0')

# Set a variable using an SNMP SET
session.set('sysLocation.0', 'The SNMP Lab')

# Perform an SNMP walk
system_items = session.walk('system')

# Each returned item can be used normally as its related type (str or int)
# but also has several extended attributes with SNMP-specific information
for item in system_items:
    print '{oid}.{oid_index} {snmp_type} = {value}'.format(
        oid=item.oid,
        oid_index=item.oid_index,
        snmp_type=item.snmp_type,
        value=item.value
    )

2. By using Ez SNMP via its simple interface which is intended for one-off operations (where you wish to specify all details in the request):

from ezsnmp import snmp_get, snmp_set, snmp_walk

# Grab a single piece of information using an SNMP GET
snmp_get('sysDescr.0', hostname='localhost', community='public', version=1)

# Perform an SNMP SET to update data
snmp_set(
    'sysLocation.0', 'My Cool Place',
    hostname='localhost', community='public', version=1
)

# Perform an SNMP walk
snmp_walk('system', hostname='localhost', community='public', version=1)

Documentation

Please check out the Ez SNMP documentation at. This includes installation instructions for various operating systems.

You may generate the documentation as follows:

# Install Sphinx
# See this website for install instructions https://www.sphinx-doc.org/en/master/usage/installation.html

# Build the documentation into static HTML pages
cd sphinx_docs_build
make html

Acknowledgments

I’d like to say thanks to the following folks who have made this project possible:

  • Giovanni Marzot: the original author

  • ScienceLogic, LLC: sponsored the initial development of this module

  • Wes Hardaker and the net-snmp-coders: for their hard work and dedication

  • fgimian and nnathan: the original contributors to this codebase

  • Kent Coble: who was the most recent maintainer. Easy SNMP

Running Tests

Tests use Pytest. You can run them with the following on Linux:

git clone https://github.com/ezsnmp/ezsnmp.git;
cd ezsnmp;
sudo apt update && sudo apt upgrade -y;
sudo apt install -y snmp snmpd libsnmp-dev libperl-dev snmp-mibs-downloader valgrind;
sudo apt install -y python3-pip python3-dev  python3-setuptools gdb -y;
sudo systemctl stop snmpd;
sudo mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig;
sudo cp tests/snmpd.conf /etc/snmp/snmpd.conf;
sudo download-mibs;
mkdir -p -m 0755 ~/.snmp;
echo 'mibs +ALL' > ~/.snmp/snmp.conf;
sudo systemctl start snmpd;
rm -drf build/ dist/ ezsnmp.egg-info;
python3 -m pip install -r requirements.txt;
python3 setup.py build && python3 -m pip install -e . && python3 -m pytest .;
# Bottom one for debug. Replace the top one with it if needed.
# python3 setup.py build && python3 -m pip install -e . && gdb -ex run -ex bt -ex quit --args python3 -m pytest .;
# Bottom one for valgrind. Replace the top one with it if needed.
# python3 setup.py build && python3 -m pip install -e . && valgrind --tool=memcheck --leak-check=full --show-leak-kinds=definite,indirect,possible python3 -m pytest .

On MacOS

git clone https://github.com/ezsnmp/ezsnmp.git;
cd ezsnmp;
mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig;
cp tests/snmpd.conf /etc/snmp/snmpd.conf;
launchctl unload /System/Library/LaunchDaemons/org.net-snmp.snmpd.plist;
launchctl load -w /System/Library/LaunchDaemons/org.net-snmp.snmpd.plist;
rm -drf build/ dist/ ezsnmp.egg-info;
python3 setup.py build && python3 -m pip install -e . && python3 -m pytest .;

Running cibuildwheels

For Linux builds on a Linux machine

clear && rm -drf wheelhouse/ build/ ezsnmp.egg-info/  && python3 -m cibuildwheel --output-dir wheelhouse --platform linux

For MacOS builds on a MacOS machine

clear && rm -drf wheelhouse/ build/ ezsnmp.egg-info/  && python3 -m cibuildwheel --output-dir wheelhouse --platform macos

License

Ez SNMP is released under the BSD license. Please see the LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ezsnmp-1.0.0rc1.tar.gz (49.6 kB view hashes)

Uploaded Source

Built Distributions

ezsnmp-1.0.0rc1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

ezsnmp-1.0.0rc1-pp310-pypy310_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (982.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

ezsnmp-1.0.0rc1-pp310-pypy310_pp73-macosx_10_9_x86_64.whl (2.0 MB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

ezsnmp-1.0.0rc1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

ezsnmp-1.0.0rc1-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (982.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

ezsnmp-1.0.0rc1-pp39-pypy39_pp73-macosx_10_9_x86_64.whl (2.0 MB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

ezsnmp-1.0.0rc1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

ezsnmp-1.0.0rc1-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (982.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

ezsnmp-1.0.0rc1-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (2.0 MB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

ezsnmp-1.0.0rc1-cp312-cp312-musllinux_1_1_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

ezsnmp-1.0.0rc1-cp312-cp312-musllinux_1_1_i686.whl (2.3 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

ezsnmp-1.0.0rc1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

ezsnmp-1.0.0rc1-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686

ezsnmp-1.0.0rc1-cp312-cp312-macosx_10_9_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

ezsnmp-1.0.0rc1-cp311-cp311-musllinux_1_1_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

ezsnmp-1.0.0rc1-cp311-cp311-musllinux_1_1_i686.whl (2.2 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

ezsnmp-1.0.0rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

ezsnmp-1.0.0rc1-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686

ezsnmp-1.0.0rc1-cp311-cp311-macosx_10_9_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

ezsnmp-1.0.0rc1-cp310-cp310-musllinux_1_1_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

ezsnmp-1.0.0rc1-cp310-cp310-musllinux_1_1_i686.whl (2.2 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

ezsnmp-1.0.0rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

ezsnmp-1.0.0rc1-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686

ezsnmp-1.0.0rc1-cp310-cp310-macosx_10_9_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

ezsnmp-1.0.0rc1-cp39-cp39-musllinux_1_1_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

ezsnmp-1.0.0rc1-cp39-cp39-musllinux_1_1_i686.whl (2.2 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

ezsnmp-1.0.0rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

ezsnmp-1.0.0rc1-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686

ezsnmp-1.0.0rc1-cp39-cp39-macosx_10_9_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

ezsnmp-1.0.0rc1-cp38-cp38-musllinux_1_1_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

ezsnmp-1.0.0rc1-cp38-cp38-musllinux_1_1_i686.whl (2.3 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

ezsnmp-1.0.0rc1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

ezsnmp-1.0.0rc1-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686

ezsnmp-1.0.0rc1-cp38-cp38-macosx_10_9_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page