TwistedSNMP

TwistedSNMP is a set of SNMP protocol implementations for Python's Twisted Matrix networking framework using the PySNMP project.  It provides the following:

Eventual goals of the system:

You can download TwistedSNMP from the project page.  If you have feedback, feel free to contact the author.

Installation

TwistedSNMP is distributed as a Python distutils package.  You can install it by unpacking the source distribution and running:

setup.py install

In the top level of the install directory.  You will need both Twisted and PySNMP 3.x or PySNMP-SE installed.  The PySNMP-SE package (available from the TwistedSNMP download page) allows for faster scanning, but returns tuple-based OIDs.  PySNMP-SE is recommended for use for all new TwistedSNMP development.

Documentation

At the moment, most of the documentation for the module is in the form of the auto-generated PyDoc reference API, which includes auto-generated documentation for PySNMP.  You can find usage examples in the test sub-directory of the distribution.

Usage

TwistedSNMP is designed to provide natural APIs for dealing with remote SNMP Agents under the assumption that the code will be used to implement Manager-side applications.  At the moment, it does not support Trap handling.

For manager-side operations, we can use the port function in the snmpprotocol module to create a new Twisted port object with an attached SNMPProtocol object.  With this, we can create any number of AgentProxy objects which provide the API we use for querying the SNMP Agent.

port = snmpprotocol.port()
proxy = agentproxy.AgentProxy(
ipAddress, 161,
community = sys.argv[2],
snmpVersion = 'v2',
protocol = port.protocol,
allowCache = True,
)

Once we have the AgentProxy, we have three major entry-points.  The first is "get", which retrieves single oid values.  You can see a full usage example in simpleget.py:

df = proxy.get(
oids, timeout=.25, retryCount=5
)

the deferred object returned from the get method will fire with a dictionary mapping { OID: value } for each oid in oids.  OIDs which were not present on the agent will return None for their value.  If the Agent does not return a value, or returns an error, then the deferred will fire it's errback chain with the returned error.

The second entry-point is "getTable", which retrieves all sub-oids for each oid in the list of oids passed in.  You can see a full usage example in simplegettable.py:

df = proxy.getTable(
oids, timeout=.25, retryCount=5
)

the deferred object returned from the getTable method will fire with a dictionary mapping { rootOID: { OID : value} } for each rootOID in oids.  rootOIDs which were not present on the agent will return None instead of the dictionary of { OID : value} pairs.  If the Agent does not return a value, or returns an error, then the deferred will fire it's errback chain with the returned error.

The third entry-point is "set", which takes a dictionary of { OID : value} pairs and uploads the values to the Agent.  Usage example in simpleset.py:

df = proxy.set(
oidSet, timeout=.25, retryCount=5
)

At the moment the return value for the deferred object is just the raw SNMP message returned from the agent.  This may be changed to be something useful at some point.

For Agent-side operations, hopefully the simpleserver.py sample will get you started on how to set up testing agents (keep in mind that the goal for these agents in the current codebase is solely to test the Manager-side implementations, so they are rather primitive).  There are bisect (in-memory) and BSDDB-based OIDStores available.

Changes

Version 0.3.12

Version 0.3.11

Version 0.3.10

Version 0.3.9

Version 0.3.8

Version 0.3.7

Version 0.3.6

Version 0.3.5

Version 0.3.0

Version 0.2.15

Version 0.2.14

Version 0.2.13

Version 0.2.12

Version 0.2.11

Version 0.2.10

Version 0.2.9

Version 0.2.8

Version 0.2.7

Version 0.2.6

Version 0.2.5

Version 0.2.4

Version 0.2.3

Version 0.2.2

Version 0.2.1

Version 0.2.0

Version 0.1.5

Version 0.1.4

Version 0.1.3

Version 0.1.2

Version 0.1.1

Version 0.1