diff --git a/roles/sys-ctl-alm-email/templates/script.sh.j2 b/roles/sys-ctl-alm-email/templates/script.sh.j2 index e6c17a73..deba180f 100644 --- a/roles/sys-ctl-alm-email/templates/script.sh.j2 +++ b/roles/sys-ctl-alm-email/templates/script.sh.j2 @@ -1,19 +1,23 @@ #!/bin/bash set -u +# Reverse systemd escaping for human-readable mail subject/body +friendly="$(systemd-escape --unescape "$1")" +# Try status with given arg; if empty, also try the escaped version STATUS_OUT="$(systemctl status --full "$1" 2>/dev/null | head -n 30)" if [ -z "$STATUS_OUT" ]; then - STATUS_OUT="(no matching systemd unit found for: $1)" + esc="$(systemd-escape "$1")" + STATUS_OUT="$(systemctl status --full "$esc" 2>/dev/null | head -n 30)" fi /usr/bin/sendmail -t < -Subject: $1 +Subject: ${friendly} Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 -A problem with the service $1 occurred: +A problem with the service ${friendly} occurred: $STATUS_OUT diff --git a/roles/sys-ctl-alm-telegram/templates/script.sh.j2 b/roles/sys-ctl-alm-telegram/templates/script.sh.j2 index 80956896..6520344e 100644 --- a/roles/sys-ctl-alm-telegram/templates/script.sh.j2 +++ b/roles/sys-ctl-alm-telegram/templates/script.sh.j2 @@ -1,4 +1,8 @@ #!/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 @@ -11,4 +15,4 @@ fi /usr/bin/curl -s -X POST \ "https://api.telegram.org/bot{{ telegram_bot_token }}/sendMessage" \ -d chat_id="{{ telegram_chat_id }}" \ - -d text="service $1 on ${host} failed" + --data-urlencode text="service ${friendly} on ${host} failed"