The pysnmp.v1 module implements a set of tools aimed at handling SNMP
messages of various types, as introduced by version 1 of SNMP protocol.
- class GETREQUEST([kwargs])
- class SETREQUEST([kwargs])
- class GETNEXTREQUEST([kwargs])
- class GETRESPONSE([kwargs])
- class TRAPREQUEST([kwargs])
-
Instances of these classes represent SNMP message of corresponding type
of SNMP protocol version 1. 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 v1
>>> req = v1.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=0, 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 and
GETRESPONSE 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 TRAPREQUEST() class accept the following key/keyword arguments:
- version - SNMP protocol version being used (default 0)
- comminuty - SNMP community name (default 'public')
- generic_trap - generic trap ID (default 0)
- specific_trap - specific trap ID (default 0)
- agent_address - IP address of the agent (default '0.0.0.0')
- time_stamp - time stamp (default time.time())
- 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.