fix: health --send is notification-only; listener @quiet prefix kills double reply

This commit is contained in:
Your Name
2026-08-07 14:15:33 -04:00
parent 81ac553590
commit 7dff27206b
6 changed files with 52 additions and 8 deletions
+27 -2
View File
@@ -30,6 +30,10 @@ Commands:
Config: $CONFIG_FILE (TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID)
Map: $MAP_FILE — one '/cmd=bash command' per line
Prefix a map value with '@quiet ' to run the command without replying —
for commands that already send their own notification, so you don't get it
twice (e.g. '/status=@quiet pos system health --send').
The listener only reacts to the owner chat (TELEGRAM_CHAT_ID). Commands run
as your user, so 'sudo' inside them needs a NOPASSWD rule. The interactive
editor runs 'bash -n' to syntax-check commands before saving.
@@ -125,7 +129,7 @@ map_cmds_list() {
}
check_syntax() {
bash -n -c "$1" 2>&1
bash -n -c "$(strip_quiet "$1")" 2>&1
}
# ── interactive editor ──────────────────────────────────────────
@@ -149,8 +153,24 @@ ui_pick() {
echo "$idx"
}
# Map entries may be prefixed with '@quiet ' to run the command without
# replying — for commands that deliver their own notification (e.g. the
# health check's --send). The marker is stripped before running and before
# the editor's bash -n syntax check.
QUIET_PREFIX="@quiet"
strip_quiet() {
local value="$1"
if [ "${value#"$QUIET_PREFIX "}" != "$value" ]; then
printf '%s' "${value#"$QUIET_PREFIX "}"
else
printf '%s' "$value"
fi
}
ui_run_command() {
local value="$1" output rc
value="$(strip_quiet "$value")"
echo
echo "--- running: $value"
if output="$(timeout 60 bash -c "$value" 2>&1)"; then
@@ -334,7 +354,7 @@ reply() {
}
handle_message() {
local text="$1" msg_id="$2" value output rc
local text="$1" msg_id="$2" value output rc quiet=0
case "$text" in
/help|/start)
reply "Mapped commands: $(map_cmds_list)" "$msg_id"
@@ -345,12 +365,17 @@ handle_message() {
reply "Unknown command: $text (send /help)" "$msg_id"
return
fi
if [ "${value#"$QUIET_PREFIX "}" != "$value" ]; then
quiet=1
value="${value#"$QUIET_PREFIX "}"
fi
log "exec: $text"
if output="$(timeout 60 bash -c "$value" 2>&1)"; then
rc=0
else
rc=$?
fi
[ "$quiet" -eq 1 ] && return
if [ -z "$output" ]; then
output="OK"
fi
+12 -1
View File
@@ -20,7 +20,9 @@ Host health dashboard: disk, RAM/swap, failed systemd units, backup age,
fail2ban, docker containers. Exits 1 if any check FAILs.
Flags:
--send Send the summary via the configured notify platform(s)
--send Send the summary via the configured notify platform(s) and do
NOT print the dashboard (notification-only — for cron/timers or
wrappers like the Telegram listener that reply with output)
(uses lib/notify.sh; see NOTIFY_PLATFORM below)
--markdown Same as --send, with markdown parse mode
-h, --help Show this help
@@ -56,6 +58,13 @@ if [ "$MARKDOWN" -eq 1 ]; then
SEND=1
fi
# --send is notification-only: suppress the dashboard output (so a wrapper
# such as the Telegram listener doesn't echo it back as a duplicate reply).
if [ "$SEND" -eq 1 ]; then
exec 3>&1
exec 1>/dev/null
fi
FAILURES=0
WARNINGS=0
REPORT=()
@@ -227,6 +236,7 @@ else
fi
if [ "$SEND" -eq 1 ]; then
exec 1>&3 3>&-
msg="POS Health — ${host}
Verdict: ${verdict}"
for line in "${REPORT[@]}"; do
@@ -238,6 +248,7 @@ ${line}"
else
notify_send "$msg"
fi
echo "sent: POS Health — ${host} (${verdict})"
fi
[ "$FAILURES" -eq 0 ]