Skip to main content

A minimal SNMP implementation

Project description


I began work on this project in late 2017 or early 2018 in hopes of making a library that is easy and intuitive to use. I worked through multiple preliminary drafts throughout 2018, scrapping each when I discovered shortcomings inherent in the design. The GitHub repository contains a notes.txt file, in which I documented my thoughts as I worked through the several iterations. In short, I find the most popular libraries to be unnecessarily complex or even buggy, (I must say, however, that I actually find Snimpy to be quite elegant, and any slight distaste I have for it is probably a sign that I think too much like a C programmer). I have decided to publish this package in its infancy, both to motivate myself to continue to improve it, and to encourage other budding contributors to the open source community to tear it apart and make it better. I have found myself frustrated in my attempts to contribute to other projects because they were simply too large for me to wrap my head around. Hopefully, such a small, simple project will become a magnet for others like me who want to contribute.

This package is written specifically for Python 3. There is no guarantee of correct operation for Python 2.

Version 0.0.3

This version constitutes a minimum viable product in the truest sense. It is hard-coded to support only unauthenticated SNMPv1 on UDP port 161, but the structure of the software is hopefully flexible enough that it can be massaged into supporting more recent versions as well. All OID's must be provided as dot-separated numbers, as there is no support for parsing MIB files. As indicated in the notes.txt file, basic operation is seen as a priority. Fancier features will hopefully be available in future releases.

Usage is meant to be quite simple. All requests are handled by an object of type Manager, and return an object of type VarBindList. This object contains entries of type VarBind, which may be accessed by numerical indices or by iteration. VarBind objects have two attributes: name, which is an OID object, and value, which may be any type. All of the aforementioned types (with the exception of the Manager) are defined in snmp.types, and inherit from a base class called ASN1. INTEGER, OCTET_STRING, NULL, and OID types, as well as any subclasses, are decoded into python primitives with the .value attribute. Note that OCTET_STRINGs are always stored as bytes, and never as str, as this can cause UnicodeDecodeErrors for non-ASCII data. The following example code retrieves IF-MIB::ifDescr.1 from localhost:

from snmp import Manager

manager = Manager()
variable_list = manager.get("", "", community=b"public")
oid = variable_list[0].name
ifDescr = variable_list[0].value
print("{}: {}".format(oid.value, ifDescr.value))

The output should look something like this: b'lo'

Project details

Download files

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

Files for snmp, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size snmp-0.0.3.tar.gz (6.8 kB) File type Source Python version None Upload date Hashes View
Filename, size snmp-0.0.3-py3-none-any.whl (19.9 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page