Kevin Veen-Birkenbach b90a2f6c87
sys-ctl-alm-{email,telegram}: unescape instance names before alerts
Use `systemd-escape --unescape` to restore human-readable unit identifiers in
Telegram and Email alerts. Also ensure Telegram messages are URL-encoded and
Email status checks try both raw and escaped forms for robustness.

Fixes issue where slashes were shown as dashes in notifications.

Context: see ChatGPT conversation
https://chatgpt.com/share/68a4c171-db08-800f-8399-7e07f237a441
2025-08-19 20:25:15 +02:00

19 lines
526 B
Django/Jinja

#!/bin/bash
set -u
# Make the instance text human readable again (reverse systemd escaping)
friendly="$(systemd-escape --unescape "$1")"
# determine host name: try hostname command, otherwise use $HOSTNAME
if command -v hostname &>/dev/null; then
host=$(hostname)
else
host="$HOSTNAME"
fi
# send the Telegram message
/usr/bin/curl -s -X POST \
"https://api.telegram.org/bot{{ telegram_bot_token }}/sendMessage" \
-d chat_id="{{ telegram_chat_id }}" \
--data-urlencode text="service ${friendly} on ${host} failed"