LINK="#0000bb" VLINK="#551a8b" ALINK="#ff0000">
The pysnmp collection of packages implements basic components of a SNMP (Simple Network Management Protocol) entity, such as SNMP manager or agent, purely in Python programming language. For more information on SNMP protocol, see RFC 1157, RFC 1155, RFC 1212 and RFC 1213 covering version 1, while RFC 1905, RFC 1902, RFC 1449, RFC 1907 and RFC 1908 are dedicated to version 2.
Most importantly, PySNMP includes SNMP message processing modules (currently implementing versions 1 and 2c of SNMP protocol) and UDP-based transport modules used for exchanging SNMP messages over the TCP/IP network.
As an additional benefit, a framework for implementing various ASN.1 (Abstract Syntax Notation One) data types is supplied with PySNMP among other sub-packages.
Here is an example on performing a SNMP GET request with PySNMP:
Python 1.5.2 (#3, Aug 25 1999, 19:14:24) [GCC 2.8.1] on sunos5 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> from pysnmp.proto import v1 >>> from pysnmp.mapping.udp import role >>> req = v1.GetRequest() >>> req['pdu']['get_request']['variable_bindings'].append(v1.VarBind(name=v1.ObjectName('220.127.116.11.18.104.22.168.0'))) >>> tr = role.manager(('router-1.glas.net', 161)) >>> (answer, src) = tr.send_and_receive(req.encode()) >>> rsp = v1.GetResponse() >>> rsp.decode(answer) >>> oids = map(lambda x: x['name'].get(), rsp['pdu']['get_response']['variable_bindings']) >>> print oids ['.22.214.171.124.126.96.36.199.0'] >>> vals = map(lambda x: x['value'], rsp['pdu']['get_response']['variable_bindings']) >>> print vals [BindValue('value'=ObjectSyntax(simple=SimpleSyntax('string'=OctetString('Cisco Internetwork Operating System Software \015\012IOS (tm) 5400 Software(C5400-JS-M), Version 12.2(11.8b), MAINTENANCE INTERIM SOFTWARE\015\012 Copyright (c) 1986-2002 by cisco Systems, Inc.\015\012Compiled Tue 30-Jul-02 19:02 by pwade'))))] >>>
A few notes on PySNMP software design should be given before going any further with this documentation.
This software has been designed with the following guidelines in mind:
Effectively, the PySNMP package is compised from the following components (actually, Python sub-packages):
[ pysnmp.asn1 ] [ pysnmp.asn1.ber ] | | | | ------------------- | | [ pysnmp.proto ] [ pysnmp.mapping.udp ] | | | | ---------------------- | | [ pysnmp.compat ]
On the above figure, the pysnmp.asn1 component implements a framework for building ASN.1 data types, while the pysnmp.asn1.ber sub-package, being mixed into the pysnmp.asn1, provides one of the possible data serialization techniques, BER (Basic Encoding Rules), which is used in SNMP.
The pysnmp.proto component is where SNMP-specific stuff is held. Basically, these are the implementations of the Structure of Management Information and Protocol Operations for various SNMP versions.
SNMP specifications define several possible network transports to be used for SNMP operations. One of these transports, for TCP/IP networks, is supplied with the pysnmp.mapping.udp sub-package.
The pysnmp.compat sub-package holds the compatibility APIs to a few popular SNMP implementations as well as to legacy PySNMP interfaces.
What follows is the documentation on all these PySNMP sub-packages.