Skip to content
vincentbernat edited this page Apr 30, 2011 · 1 revision

SNMP library for Twisted

Wiremaps contains a simple SNMP library for Twisted and written in C. It is similar in functionalities to PyNetSNMP (which was used before) but provides lighter memory footprint and does not rely on ctypes. Compared to TwistedSNMP, it provides the same basic functionalities without depending on additional Python libraries.

Features

This library is limited to those features:

  • GET, GETNEXT and GETBULK operations
  • SNMPv1 or SNMPv2

There is no:

  • MIB parsing
  • complex type handling
  • walk method (but look at proxy.py to see how to implement it)
  • SNMPv3

Usage example

import snmp
from twisted.python import failure
from twisted.internet import reactor

oids = ['.1.3.6.1.2.1.1.1.0',
        '.1.3.6.1.2.1.1.2.0',
        '.1.3.6.1.2.1.1.3.0',
        '.1.3.6.1.2.1.1.4.0',
       ]

def printResults(results):
    if reactor.running:
        reactor.stop()
    if isinstance(results, failure.Failure):
        raise results.value
    import pprint
    pprint.pprint(results)
    return results

proxy = snmp.AgentProxy(ip='127.0.0.1',
                   community='public',
                   version=2)
d = proxy.getbulk(oids)
d.addBoth(printResults)
reactor.run()

How to get it

If you are only interested in this SNMP library, just grab snmp.c. You can compile it with:

gcc -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.5 -c snmp.c -o snmp.o
gcc -shared -Wl,-O1 -Wl,-Bsymbolic-functions snmp.o -lnetsnmp -lcrypto -o snmp.so

This file is MIT/X11 licensed.