Last Modified : 08 August 2026
Custom Trigger
The Custom Trigger runs an external command or script and uses its output to determine whether an event occurred. This allows you to integrate any monitoring logic that can be expressed as a command-line program.
Configuration
| Option | Type | Description |
|---|---|---|
| Command | String |
The shell command or script to execute. The previous state
is provided in stdin buffer. The working
directory is the Scripts Directory set in app
settings.
|
| Timeout (ms) | Integer | Maximum execution time in milliseconds. |
Command Contract
The command receives the previous state (Base64-encoded) as an argument. It must output a JSON object on stdout with the following format:
{
"data": "<base64-encoded UTF-8 event data>",
"newState": "<base64-encoded UTF-8 new state>"
}
- data: The event payload if an event occurred. Leave empty if no event.
- newState: The new state to persist for the next execution.
If the command exits without printing anything (or prints invalid JSON), no event is emitted.
Example
A simple bash script that fires an event with data
"Hello World #{num}" where num is the current count:
#!/usr/bin/env python3
"""
always.py - A custom trigger that always returns an event with "Hello World" data.
This script simulates a trigger that always finds an event.
"""
import json
import base64
import sys
import os
def main():
# Read previous state from stdin (if any)
prev_state = sys.stdin.read().strip()
if len(prev_state) == 0:
prev_state = "0"
num = int(prev_state) + 1
# Create sample data
data_string = f"Hello World #{num}"
# Encode data in base64 for JSON transport
encoded_data = base64.b64encode(data_string.encode('utf-8')).decode('utf-8')
encoded_new_state = base64.b64encode(str(num).encode('utf-8')).decode('utf-8')
# Create result JSON
result = {
"data": encoded_data,
"newState": encoded_new_state
}
# Output JSON to stdout
print(json.dumps(result))
# For debugging, write to stderr (will be captured in logs)
print(f"Trigger executed. Previous state: '{prev_state}'", file=sys.stderr)
if __name__ == "__main__":
main()
Return Values
| Key | Value |
|---|---|
data |
The returned data from the command / script. |
newState |
The returned newState from the command / script |