PySNMP Project Logo

Project diary
Documentation
Examples
Download
Mailing lists
License
Obsolete

Projects using PySNMP
NOC Project


Relevant projects
PyNetSNMP
SNMPy
YAPSNMP
LibSMI

Support This Project
SourceForge Logo

SNMP message, version 1

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.

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.

exception Error

Exception raised on any error in the pysnmp.v1 module, as well as in its base (pysnmp.asn1) and derivative modules. This exception class is a subclass of the asn1.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 TypeError

Inappropriate type for an v1.* object value.

exception BadArgument

Inappropriate argument given.

exception BadVersion

Unsupported SNMP version.

exception BadEncoding

Malformed BER octet-stream.


Subsections


Need help? Try PySNMP mailing lists.