Event System
Scripts can register callbacks that fire when specific events occur on the Tuoni server. This enables reactive automation — auto-tagging agents on connect, logging command results, triggering follow-up actions, and more.
Registering Callbacks
Parameters:
| Parameter | Type | Description |
|---|---|---|
event_type |
str |
One of the event type strings listed below |
callback |
callable |
Function with signature (event, data) -> None |
Returns: BackgroundTask — call task.stop() to unsubscribe.
Callback arguments:
| Argument | Type | Description |
|---|---|---|
event |
Event | Event metadata (type, time, reference_type) |
data |
varies | Depends on the event's reference type (see table below) |
Script Lifecycle
Registering a callback creates a background task that keeps the script alive.
The script will not terminate until all background tasks are stopped.
Call task.stop() to unsubscribe and allow the script to exit.
Event Types
Agent Events
Callback receives: Agent
| Event Type | Description |
|---|---|
REGISTER_AGENT |
A new agent has connected to the server |
DEACTIVATE_AGENT |
An agent has been deactivated |
REACTIVATE_AGENT |
A previously deactivated agent has been reactivated |
BLOCK_AGENT |
An agent has been blocked |
UPDATE_AGENT_METADATA |
The agent reported updated metadata (e.g. new IPs, hostname change) |
MODIFY_AGENT_METADATA |
Agent metadata was modified by a user or script |
Command Events
Callback receives: CommandState
| Event Type | Description |
|---|---|
CREATE_COMMAND |
A command has been created |
SEND_COMMAND |
A command has been sent to an agent |
RECEIVE_COMMAND_RESULT |
A result (partial or final) has been received for a command |
CREATE_COMMAND_UPDATE |
A command update has been created |
CANCEL_COMMAND |
A command has been cancelled |
Partial Results
RECEIVE_COMMAND_RESULT fires for every result, including partial (ongoing) results.
Check cmd.result.is_finished() to determine if the command has fully completed.
Discovery Events
Host Events
Callback receives: DetailedDiscoveredHost
| Event Type | Description |
|---|---|
CREATE_DISCOVERED_HOST |
A new host was added to discovery |
EDIT_DISCOVERED_HOST |
A discovered host was modified |
ARCHIVE_DISCOVERED_HOST |
A discovered host was archived |
RESTORE_DISCOVERED_HOST |
An archived host was restored |
Service Events
Callback receives: DetailedDiscoveredService
| Event Type | Description |
|---|---|
CREATE_DISCOVERED_SERVICE |
A new service was added to discovery |
EDIT_DISCOVERED_SERVICE |
A discovered service was modified |
ARCHIVE_DISCOVERED_SERVICE |
A discovered service was archived |
RESTORE_DISCOVERED_SERVICE |
An archived service was restored |
Credential Events
Callback receives: DetailedDiscoveredCredential
| Event Type | Description |
|---|---|
CREATE_DISCOVERED_CREDENTIAL |
A new credential was added to discovery |
EDIT_DISCOVERED_CREDENTIAL |
A discovered credential was modified |
ARCHIVE_DISCOVERED_CREDENTIAL |
A discovered credential was archived |
RESTORE_DISCOVERED_CREDENTIAL |
An archived credential was restored |
Job Events
Callback receives: JobState
| Event Type | Description |
|---|---|
CREATE_JOB |
A new job (e.g. script execution) was created |
UPDATE_JOB |
A job's status or messages changed |
Settings Events
| Event Type | Description |
|---|---|
CHANGE_SETTINGS |
A server setting was changed |
Patterns
One-Shot Listener
Listen for a single event, then stop:
Variable Scope
The task variable must be accessible inside the callback. Define it at module scope (as shown above), not inside a function.
Long-Running Listener
Listen indefinitely — the script stays alive as long as the task is active:
Event-Driven Command Execution
Combine events with direct command sending:
Auto-Tagging Agents
Tag agents automatically based on their metadata when they connect:
Monitoring Command Results
Log all command results across all agents: