puresnmp.pdu module

Models for SNMP PDUs (Request/Response messages).

PDUs all have a common structure, which is handled in the PDU class. The different (basic) PDU types only differ in their type identifier header (f.ex. b'\xa0' for a GetRequest).

A SNMP PDU contains the following elements:

request-id

A unique ID used to match requests with responses. Each reques/response pair share this value.

error-status

An integer defining an error-state. In puresnmp they are mapped to exceptions of the class puresnmp.exc.ErrorResponse.

error-index

If applicable, this identifies the Request OID that caused the error (1-indexed.)

varbinds

A key/value pair representing the payload of the PDU. For requests, the value should be x690.types.Null

class puresnmp.pdu.BulkGetRequest(request_id: int, non_repeaters: int, max_repeaters: int, *oids: ObjectIdentifier)

Bases: PDU

Represents a SNMP GetBulk request

TAG: int = 5

The tag for type-detection in x690

TYPECLASS: TypeClass = 'context'

The typeclass identifire for type-detection in x690

pretty(depth: int = 0) str

Returns a “prettified” string representing the SNMP message.

pyvalue: TWrappedPyType | _SENTINEL_UNINITIALISED

The decoded (or to-be encoded) Python value

class puresnmp.pdu.EndOfMibView(value: ~x690.types.TWrappedPyType | ~x690.types._SENTINEL_UNINITIALISED = <x690.types._SENTINEL_UNINITIALISED object>)

Bases: X690Type[None]

Sentinel value to detect the SNMP endOfMibView marker

NATURE = [TypeNature.PRIMITIVE]

The x690 “private/constructed” information

TAG: int = 2

The x690 identifier for the type

TYPECLASS: TypeClass = 'context'

The x690 type-class (universal, application or context)

pyvalue: TWrappedPyType | _SENTINEL_UNINITIALISED

The decoded (or to-be encoded) Python value

class puresnmp.pdu.GetNextRequest(value: ~x690.types.TWrappedPyType | ~x690.types._SENTINEL_UNINITIALISED = <x690.types._SENTINEL_UNINITIALISED object>)

Bases: GetRequest

Represents an SNMP GetNext Request.

TAG: int = 1

The tag for type-detection in x690

pyvalue: TWrappedPyType | _SENTINEL_UNINITIALISED

The decoded (or to-be encoded) Python value

class puresnmp.pdu.GetRequest(value: ~x690.types.TWrappedPyType | ~x690.types._SENTINEL_UNINITIALISED = <x690.types._SENTINEL_UNINITIALISED object>)

Bases: PDU

Represents an SNMP Get Request.

TAG: int = 0

The tag for type-detection in x690

pyvalue: TWrappedPyType | _SENTINEL_UNINITIALISED

The decoded (or to-be encoded) Python value

class puresnmp.pdu.GetResponse(value: ~x690.types.TWrappedPyType | ~x690.types._SENTINEL_UNINITIALISED = <x690.types._SENTINEL_UNINITIALISED object>)

Bases: PDU

Represents an SNMP basic response (this may be returned for other requests than GET as well).

TAG: int = 2

The tag for type-detection in x690

pyvalue: TWrappedPyType | _SENTINEL_UNINITIALISED

The decoded (or to-be encoded) Python value

class puresnmp.pdu.InformRequest(value: ~x690.types.TWrappedPyType | ~x690.types._SENTINEL_UNINITIALISED = <x690.types._SENTINEL_UNINITIALISED object>)

Bases: PDU

Represents an SNMP Inform request

TAG: int = 6

The tag for type-detection in x690

pyvalue: TWrappedPyType | _SENTINEL_UNINITIALISED

The decoded (or to-be encoded) Python value

class puresnmp.pdu.NoSuchInstance(value: ~x690.types.TWrappedPyType | ~x690.types._SENTINEL_UNINITIALISED = <x690.types._SENTINEL_UNINITIALISED object>)

Bases: X690Type[None]

Sentinel value to detect noSuchInstance

NATURE = [TypeNature.PRIMITIVE]

The x690 “private/constructed” information

TAG: int = 1

The x690 identifier for the type

TYPECLASS: TypeClass = 'context'

The x690 type-class (universal, application or context)

pyvalue: TWrappedPyType | _SENTINEL_UNINITIALISED

The decoded (or to-be encoded) Python value

class puresnmp.pdu.NoSuchObject(value: ~x690.types.TWrappedPyType | ~x690.types._SENTINEL_UNINITIALISED = <x690.types._SENTINEL_UNINITIALISED object>)

Bases: X690Type[None]

Sentinel value to detect noSuchObject

NATURE = [TypeNature.PRIMITIVE]

The x690 “private/constructed” information

TAG: int = 0

The x690 identifier for the type

TYPECLASS: TypeClass = 'context'

The x690 type-class (universal, application or context)

pyvalue: TWrappedPyType | _SENTINEL_UNINITIALISED

The decoded (or to-be encoded) Python value

class puresnmp.pdu.PDU(value: ~x690.types.TWrappedPyType | ~x690.types._SENTINEL_UNINITIALISED = <x690.types._SENTINEL_UNINITIALISED object>)

Bases: X690Type[PDUContent]

The superclass for SNMP Messages (GET, SET, GETNEXT, …)

TAG: int = 0

The tag for type-detection in x690

TYPECLASS: TypeClass = 'context'

The typeclass identifire for type-detection in x690

classmethod decode_raw(data: bytes, slc: slice = slice(None, None, None)) PDUContent

This method takes a bytes object and converts it to an application object. This is callable from each subclass of PDU.

encode_raw() bytes

Encodes this instance into raw x.690 bytes (excluding type & lenght)

pretty(depth: int = 0) str

Returns a “prettified” string representing the SNMP message.

pyvalue: TWrappedPyType | _SENTINEL_UNINITIALISED

The decoded (or to-be encoded) Python value

class puresnmp.pdu.PDUContent(request_id: int, varbinds: List[VarBind], error_status: int = 0, error_index: int = 0)

Bases: object

A helper class to wrap PDU data into a single “value” variable for x.690 types.

error_index: int = 0
error_status: int = 0
request_id: int
varbinds: List[VarBind]
class puresnmp.pdu.Report(value: ~x690.types.TWrappedPyType | ~x690.types._SENTINEL_UNINITIALISED = <x690.types._SENTINEL_UNINITIALISED object>)

Bases: PDU

Represents an SNMP report

TAG: int = 8

The tag for type-detection in x690

pyvalue: TWrappedPyType | _SENTINEL_UNINITIALISED

The decoded (or to-be encoded) Python value

class puresnmp.pdu.SetRequest(value: ~x690.types.TWrappedPyType | ~x690.types._SENTINEL_UNINITIALISED = <x690.types._SENTINEL_UNINITIALISED object>)

Bases: PDU

Represents an SNMP SET Request.

TAG: int = 3

The tag for type-detection in x690

pyvalue: TWrappedPyType | _SENTINEL_UNINITIALISED

The decoded (or to-be encoded) Python value

class puresnmp.pdu.Trap(*args: Any, **kwargs: Any)

Bases: PDU

Represents an SNMP Trap

TAG: int = 7

The tag for type-detection in x690

pyvalue: TWrappedPyType | _SENTINEL_UNINITIALISED

The decoded (or to-be encoded) Python value