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:
- version - SNMP protocol version being used (default 0)
- comminuty - SNMP community name (default 'public')
- request_id - SNMP request ID (default 0)
- error_status - SNMP error ID (default 0)
- error_index - position of errornous OID-value pair
(default 0)
- encoded_oids - a list of BER encoded ASN.1 Object ID's
(default [])
- encoded_vals - a list of BER encoded values (default [])
Instances of GETBULKREQUEST() class accept the following key/keyword arguments:
- version - SNMP protocol version being used (default 0)
- comminuty - SNMP community name (default 'public')
- non_repeaters - non-repeating Object IDs in
Object ID / value binding (default 0)
- max_repetitions - max repetitions of repeating Object IDs
in Object ID / value binding (default 0)
- encoded_oids - a list of BER encoded ASN.1 Object ID's
(default [])
- encoded_vals - a list of BER encoded values (default [])
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.