puresnmp.adt module
This module contains simple “abstract data types” which are used for both type-hinting and to keep the code more expressive & readable.
- class puresnmp.adt.EncryptedMessage(version: Integer, header: HeaderData, security_parameters: bytes, scoped_pdu: OctetString | ScopedPDU)
Bases:
Message
A message whose PDU is encrypted
- header: HeaderData
Additional information wrapping the old-style PDU
- scoped_pdu: OctetString
The “old-style” PDU (either plain or encrypted)
- class puresnmp.adt.HeaderData(message_id: int, message_max_size: int, flags: V3Flags, security_model: int)
Bases:
object
Header information for an SNMPv3 message
- class puresnmp.adt.Message(version: Integer, header: HeaderData, security_parameters: bytes, scoped_pdu: OctetString | ScopedPDU)
Bases:
object
A complete SNMP message including all information needed by RFC 3411
Such a message contains an “old-style” PDU (as was defined in SNMPv2) plus some meta-data. The meta-data consists of a version identifier to identify the proper “message-processing-model” using a IANA registered value.
See also
- RFC definition
The MIB definition of an SNMPv3 message
- Example Message Format
A simple visual representation of the byte-structure of an SNMPv3 message
- IANA Message Processing Models
Oficially registered message “version” identifiers
- static decode(data: bytes) PlainMessage | EncryptedMessage
Construct a new SNMPv3 message from a bytes object
>>> from puresnmp.pdu import GetRequest, PDUContent >>> from x690.types import ObjectIdentifier as OID >>> pdu = ScopedPDU( ... OctetString(b"engine"), ... OctetString(b"context"), ... GetRequest(PDUContent(42, [])), ... ) >>> msg = PlainMessage( ... version=Integer(3), ... header=HeaderData(42, 65000, V3Flags(False, False, False), 3), ... security_parameters=b"", ... scoped_pdu=pdu ... ) >>> result = Message.decode(bytes(msg)) >>> result == msg True
- classmethod from_sequence(seq: Sequence) TMessageType
Construct a Message instance from an X.690 Sequence
- header: HeaderData
Additional information wrapping the old-style PDU
- pretty(depth: int = 0) str
Return a prettyfied string of this object.
This prettyfied string is useful for debugging and introspection.
- Parameters:
depth – How many levels of indentation to apply. This is used internally for nested structures.
- scoped_pdu: OctetString | ScopedPDU
The “old-style” PDU (either plain or encrypted)
- class puresnmp.adt.PlainMessage(version: Integer, header: HeaderData, security_parameters: bytes, scoped_pdu: OctetString | ScopedPDU)
Bases:
Message
A message whose PDU is not encrypted
- header: HeaderData
Additional information wrapping the old-style PDU
- class puresnmp.adt.ScopedPDU(context_engine_id: OctetString, context_name: OctetString, data: PDU)
Bases:
object
A data-structure wrapping the different values from a SNMPv3 “Scoped PDU”
- context_engine_id: OctetString
- context_name: OctetString
- static decode(data: bytes, slc: slice = slice(None, None, None)) ScopedPDU
Create a ScopedPDU instance from an x.690 bytes object
- Parameters:
bytes – the bytes object which contains the PDU.
slc – The slice at which the object is located. If left to the default, it will assume that the object is located in the beginning of the bytes object.
>>> from puresnmp.pdu import GetRequest, PDUContent, VarBind >>> from x690.types import ObjectIdentifier as OID >>> pdu = ScopedPDU( ... OctetString(b"engine"), ... OctetString(b"context"), ... GetRequest(PDUContent(42, [])), ... ) >>> result = ScopedPDU.decode(bytes(pdu)) >>> pdu == result True
- class puresnmp.adt.V3Flags(auth: bool = False, priv: bool = False, reportable: bool = False)
Bases:
object
This class represents the SNMP message flags.
At the time of this writing, this only contains the flags auth, priv and reportable. The remaining bytes are (as of this state) reserved by the SNMP standard.
- static decode(blob: OctetString) V3Flags
Converts an OctetString instance into a more pythonic instance
>>> V3Flags.decode(OctetString(b"\x00")) V3Flags(auth=False, priv=False, reportable=False) >>> V3Flags.decode(OctetString(b"\x07")) V3Flags(auth=True, priv=True, reportable=True)