developer / Custom Callbacks
No results for ""
Custom Callbacks
Overview
When Demyx detects an issue (container down, disk full, high load, etc.) it calls callback.sh if present at /demyx/custom/callback.sh. This lets you forward alerts to any service — Matrix, Slack, Discord, Telegram, PagerDuty, etc.
Callback Arguments
The callback receives up to 6 positional arguments:
| Position | Description |
|---|---|
$1 | Event type: healthcheck, error, monitor-on, monitor-off |
$2 | App domain or command string |
$3 | Log output / echo |
$4 | Server IP (healthcheck) / Execute string (error) |
$5 | Domain IP (healthcheck) / Stdout (error) |
$6 | Nameservers (healthcheck) / Timestamp (error) |
Example — Matrix Webhook
The included custom/example-callback.sh sends alerts to a Matrix room via matrix-webhook:
#!/bin/bash
set -euo pipefail
demyx_callback() {
local DEMYX_CALLBACK_ARG_1="${1:-}"
local DEMYX_CALLBACK_ARG_2="${2:-}"
local DEMYX_CALLBACK_ARG_3="ECHO: ${3:-}<br/>"
local DEMYX_CALLBACK_ARG_4="${4:-}"
local DEMYX_CALLBACK_ARG_5="${5:-}"
local DEMYX_CALLBACK_ARG_6="${6:-}"
local DEMYX_CALLBACK_DOMAIN=
DEMYX_CALLBACK_DOMAIN="$(echo "$DEMYX_CALLBACK_ARG_2" | tr '[:upper:]' '[:lower:]')"
local DEMYX_CALLBACK_KEY="your-matrix-key"
local DEMYX_CALLBACK_WEBHOOK="https://matrix.yourdomain.tld/!roomid:yourdomain.tld"
case "$DEMYX_CALLBACK_ARG_1" in
healthcheck)
demyx_callback_curl "Server IP: ${DEMYX_CALLBACK_ARG_4}\nDomain IP: ${DEMYX_CALLBACK_ARG_5}\nNameservers: ${DEMYX_CALLBACK_ARG_6}"
;;
error)
demyx_callback_curl "HOSTNAME: $DEMYX_HOSTNAME<br>ERROR: demyx ${DEMYX_CALLBACK_ARG_2}<br>${DEMYX_CALLBACK_ARG_3}"
;;
monitor-on)
demyx_callback_curl "$DEMYX_CALLBACK_DOMAIN: monitor turned on"
;;
monitor-off)
demyx_callback_curl "$DEMYX_CALLBACK_DOMAIN: monitor turned off"
;;
esac
}
demyx_callback_curl() {
local DEMYX_CALLBACK_CURL="${1:-}"
curl -X POST \
-H 'Content-Type: application/json' \
--data "{\"text\":\"$DEMYX_CALLBACK_CURL\",\"key\":\"$DEMYX_CALLBACK_KEY\"}" \
"$DEMYX_CALLBACK_WEBHOOK"
}
demyx_callback "$@"Adapting for Other Services
Slack
demyx_callback_curl() {
curl -X POST \
-H 'Content-Type: application/json' \
--data "{\"text\":\"${1:-}\"}" \
"https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
}Discord
demyx_callback_curl() {
curl -X POST \
-H 'Content-Type: application/json' \
--data "{\"content\":\"${1:-}\"}" \
"https://discord.com/api/webhooks/YOUR_WEBHOOK_URL"
}Activating
# Copy to custom directory
cp /demyx/custom/example-callback.sh /demyx/custom/callback.sh
# Edit with your webhook details
nano /demyx/custom/callback.sh
# Make executable
chmod +x /demyx/custom/callback.sh