SNMP message, version 2c (community based)

The pysnmp.v2c module implememts a set of tools aimed at handling SNMP messages of various types, as introduced by version 2c of SNMP protocol.

class GETREQUEST([kwargs])
class SETREQUEST([kwargs])
class GETNEXTREQUEST([kwargs])
class RESPONSE([kwargs])
class INFORMREQUEST([kwargs])
class TRAP([kwargs])
class REPORT([kwargs])
class GETBULKREQUEST([kwargs])

Instances of these classes represent SNMP message of corresponding type of SNMP protocol version 2c. The optional kwargs keyword arguments may be used to initialize arbitrary SNMP message components (read on).

Alternatively, a standard dictionary interface can be used against these objects for accessing particular message item, though only a fixed set of keys are allowed. Here is a brief illustration of this concept:

>>> from pysnmp import v2c
>>> req = v2c.GETREQUEST()
>>> req.keys()
['encoded_oids', 'encoded_vals', 'request_id', 'error_status', 'tag', 
'error_index', 'version', 'community']
>>> req['community'] = 'mycommunity'
>>> repr(req)
"GETREQUEST(encoded_oids=[], encoded_vals=[], request_id=0, error_status=0,
tag='GETREQUEST', error_index=0, version=1, community='mycommunity')"
>>>

As it can be seen from the above example, the following key/keyword values are allowed to instances of the GETREQUEST, SETREQUEST, GETNEXTREQUEST, TRAP, INFORMREQUEST and REPORT classes:

Instances of GETBULKREQUEST() class accept the following key/keyword arguments:

The encoded_oids and encoded_vals parameters can be handled by the instances of corresponding classes from SNMP subset of ASN.1 data types module. Here is an example of how this could be done:

>>> from pysnmp import asn1
>>> map(asn1.OBJECTID().encode, ['1.3.6.1.2.1.1.1.0'])
['\006\010+\006\001\002\001\001\001\000']
>>>

The Object IDs and their respective values are matched against each other by their positions in the encoded_oids and encoded_vals lists.

def decode(data)

The decode function takes SNMP message carried in a BER-encoded octet-stream data, and decodes it into a SNMP message object of matching type.

A tuple of (snmp_message_object, rest) is returned where snmp_message_object is an instance of a SNMP message class, matching SNMP message type, and the rest is the unprocessed part of input. The decode function also accepts SNMP messages of version 1 of SNMP protocol. In that case, an instance of corresponding v2c.* class is returned.

exception Error

Exception raised on any error in the pysnmp.v2c module, as well as in its base (pysnmp.v1) and derivative modules. This exception class is a subclass of the v1.Error class.

See documentation on the error.General base class for usage details.

The following exceptions are derived from this class:

exception BadPDUType

Unknown BER tag for in SNMP PDU.

exception BadVersion

Unsupported SNMP version.

exception BadEncoding

Malformed BER octet-stream.


Subsections


ilya@glas.net