Objects of session class

Each of the methods described in this chapter may raise exceptions (listed in the previous chapter) if either distant SNMP process reported an error or SNMP engine failed for whatever reason.

The instances of session class have the following methods:

encode_integer (value)
encode_ipaddr (value)
encode_timeticks (value)
encode_string (value)
encode_oid (value)

Return BER encoded value (as string) from plain value.

Type of value depends of method used.

str2nums (objid)

Return a list of integers representing SNMP Object ID objid passed in string representation (e.g. '1.3.6.1.2.1.1.1.0').

encode_request (type, encoded_objids, encoded_vals)

Return BER encoded SNMP message (as string) of specified type (string constant) loaded with BER encoded_objids and encoded_vals.

The following SNMP message types are known:

The encoded_objids and encoded_vals arguments must be lists of BER encoded SNMP Object IDs and their associated values respectively.

decode_response (message[, type])

Decode SNMP message of request type and return a tuple of two lists -- a list of BER encoded SNMP Object IDs and a list of associated values from SNMP response message.

See encode_request() section for valid request types. The default for type value is set to `GETRESPONSE'.

decode_value (encoded_value)

Return plain value from BER encoded_value. The type of return value depends of the ASN.1 type of data item encapsulated in encoded_value.

If encoded_value carries data item of ASN.1 type:

nums2str (objid)

Return a string representing SNMP Object ID objid passed as a list of integers (e.g. [1, 3, 6, 1, 2, 1, 1, 1, 0]).

send_and_receive (message)

Attempt to send SNMP message and receive SNMP response from SNMP agent. Return BER encoded SNMP message (as string) as received from SNMP agent.

open ()

Create and return connected socket object to be further used for sending SNMP request to SNMP agent.

send (message)

Attempt to send SNMP message to SNMP agent.

receive ()

Return SNMP response message as received from SNMP agent or times out in timeout.

close ()

Destroy socket object used for talking to SNMP agent.

The objects of session class have the following public instance variables:

port

Specify the UDP port of remote SNMP process. The port variable is of type integer.

The default value for UDP port is 161.

timeout

Specify for how many seconds to wait for response from SNMP agent. The timeout attribute is of floating point type.

The default is 1.0 second.

retries

Specify the number of request re-transmissions. The retries attribute is of integer type.

The default is 3 retries.

iface

Specify the IP number of local interface SNMP engine is to bind to. All SNMP requests would be originated from the interfaces SNMP engine binds to.

The iface attribute should be a list of strings where each string should represent either FQDN or IP number of desired local interface.

The default value is None what means to bind to all the local interfaces and originate SNMP request from primary system interface.

XXX: current implementation binds ONLY to the first interface of the list.


ilya@glas.net