Event System
The Script Engine can subscribe to live audit events and query stored event history. Subscriptions are background tasks, so a script remains active until its tasks are stopped or the script itself is stopped.
Subscribing by event type
Callbacks receive the Event and a sequence of referenced objects. Even when
an event normally references one object, handle the second argument as a
sequence.
Callbacks may run asynchronously and should return promptly. If work can take a long time, avoid blocking unrelated callbacks with shared locks or mutable global state.
Subscribing by reference type
Subscribe to every event associated with a resource category:
Event categories
Agent events
REGISTER_AGENTDEACTIVATE_AGENTREACTIVATE_AGENTBLOCK_AGENTUPDATE_AGENT_METADATAMODIFY_AGENT_METADATAAGENT_HEARTBEAT
Command events
CREATE_COMMANDSEND_COMMANDRECEIVE_COMMAND_RESULTCREATE_COMMAND_UPDATESEND_COMMAND_UPDATECANCEL_COMMAND
Discovery events
CREATE_DISCOVERED_HOST,EDIT_DISCOVERED_HOST,ARCHIVE_DISCOVERED_HOST,RESTORE_DISCOVERED_HOSTCREATE_DISCOVERED_SERVICE,EDIT_DISCOVERED_SERVICE,ARCHIVE_DISCOVERED_SERVICE,RESTORE_DISCOVERED_SERVICECREATE_DISCOVERED_CREDENTIAL,EDIT_DISCOVERED_CREDENTIAL,ARCHIVE_DISCOVERED_CREDENTIAL,RESTORE_DISCOVERED_CREDENTIAL
Other events
CREATE_JOB,UPDATE_JOBCHANGE_SETTINGS
Always pass enum members rather than raw strings:
Callback payload types
The subscription determines the resource sequence:
| Event category or reference type | Callback resources |
|---|---|
| Agent | Sequence[Agent] |
| Command | Sequence[Command] |
| Discovered host | Sequence[DiscoveredHost] |
| Discovered service | Sequence[DiscoveredService] |
| Discovered credential | Sequence[DiscoveredCredential] |
| Job | Sequence[Job] |
| Setting | Sequence[Setting] |
The Event object exposes:
| Property | Description |
|---|---|
id |
Event UUID |
type |
EventType |
reference_type |
ReferenceType |
reference_ids |
Identifiers referenced by the event |
time |
Timezone-aware event timestamp |
Subscription lifecycle
subscribe_by_event_type() and subscribe_by_reference_type() return a
Task. The active task keeps the script alive.
A task is also stopped when its script file is changed or deleted, or when the Tuoni Server shuts down.
Querying event history
Get one event by UUID:
Iterate through events for a referenced object:
Use the identifier type appropriate to the reference:
- UUID or UUID string for agents and discovery records
- integer for commands and jobs
- string key for settings
Queueing a command from a callback
Use the global command manager because an event callback has no alias context:
Long waits delay the callback. Use them only when that behavior is acceptable for the automation.
Updating an agent from a callback
Updating metadata emits further metadata events. Avoid subscribing to a metadata event and then unconditionally updating the same metadata, which can create an event loop.