Events¶
Info
For event log usage, see Event Log.
The client records an event log of resolutions, mutations, and notices that happen in-between requests for complex queries and other operations. Typically, such events are things like CNAME and PTR resolution that happen when resolving Host or host records.
The client exposes its event log via client.events (an EventLog).
The size of the log is controlled by the event_log_size argument to MregClient.
EventLog
¶
Append-only event log with querying and optional subscriber callbacks.
When max_size is set, the oldest event is evicted when the limit is reached so memory use stays bounded.
__init__
¶
__init__(max_size: int | None = 100) -> None
Initialise the log with an optional maximum size.
get
¶
get(
subject: ObjectRef | None = None,
kind: EventKind | None = None,
level: EventLevel | None = None,
min_level: EventLevel | None = None,
where: Callable[[Event], bool] | None = None,
) -> list[Event]
Return all recorded events, optionally filtered by subject, kind, or level.
Multiple filters can be applied at once, and only events matching all provided filters will be returned.
More complex filtering can be done by providing a callable to the
where parameter, which will be called with each event record,
and should return True if it should be included in the results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject
|
ObjectRef | None
|
If given, return only events where this object is the subject or involved. |
None
|
kind
|
EventKind | None
|
If given, return only events of this kind. |
None
|
level
|
EventLevel | None
|
If given, return only events with exactly this level. |
None
|
min_level
|
EventLevel | None
|
If given, return only events with this level or higher. |
None
|
where
|
Callable[[Event], bool] | None
|
A predicate function that returns True if the event should be included. |
None
|
Returns:
| Type | Description |
|---|---|
list[Event]
|
A list of events matching the specified filters. |
get_at_or_above
¶
get_at_or_above(level: EventLevel) -> list[Event]
Return all events at or above the given severity level.
get_by_level
¶
get_by_level(level: EventLevel) -> list[Event]
Return all events with exactly the given level.
get_for
¶
Return all events where ref is the subject or an involved object.
record
¶
record(event: Event) -> None
Record an event, evicting the oldest entry if max_size is reached.
Calls all registered handlers with the new event as the argument.
subscribe
¶
Register a callback invoked for every new event.
Event
dataclass
¶
Structured record of something that happened to or around an MREG API object.
correlation_id
class-attribute
instance-attribute
¶
correlation_id: str = ''
Client correlation ID active at the time the event was emitted.
level
class-attribute
instance-attribute
¶
level: EventLevel = EventLevel.INFO
Primary object this event concerns.
EventKind
¶
Bases: StrEnum
Classification of an event.
MUTATION
class-attribute
instance-attribute
¶
Object was created, patched, or deleted.
RESOLUTION
class-attribute
instance-attribute
¶
Object found via an alias or redirect (e.g. CNAME, PTR override).
TRUNCATION
class-attribute
instance-attribute
¶
A query matched more objects than the limit allowed; the extra results were dropped.
EventLevel
¶
Bases: IntEnum
Severity level of an event.
Handlers can use this to filter which events to react to.
ObjectRef
dataclass
¶
Lightweight reference to an MREG API object, used for event correlation.
type is the model class name (e.g. "Host", "MX").
value is always a string. Field values are converted to strings.
field is the specific field within the object that the value pertains to.