From 513252a60cfd4e1f8f7b136cb2685f06a6a6bc35 Mon Sep 17 00:00:00 2001 From: menzel Date: Wed, 15 Jul 2026 12:38:49 +0200 Subject: [PATCH] epics2sms: only send RESOLVED if an alarm message was sent this episode Guard the recovery notification on msg_count > 0, so a brief excursion that never produced an alarm message (e.g. recovered before any send, or all sends failed) does not emit a lone RESOLVED. Recovery is still logged. Co-Authored-By: Claude Opus 4.8 (1M context) --- EPICS2SMS.sh | 15 +++++++++------ README.md | 5 +++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/EPICS2SMS.sh b/EPICS2SMS.sh index aa4fece..215907e 100755 --- a/EPICS2SMS.sh +++ b/EPICS2SMS.sh @@ -183,12 +183,15 @@ monitor_loop() { else if (( in_alarm )); then mlog "$tag" "recovered to normal (avg=$avg) after $msg_count message(s)" - # Recovery notification: sent once, immediately (not throttled/capped). - body="RESOLVED: $text - now avg=$avg (last=$value) $(date '+%F %T')" - if send_alert "$body" "EPICS resolved"; then - mlog "$tag" "resolve notification sent" - else - mlog "$tag" "ERROR: resolve notification failed to send" + # Recovery notification: only if we actually alerted during this + # episode; sent once, immediately (not throttled/capped). + if (( msg_count > 0 )); then + body="RESOLVED: $text - now avg=$avg (last=$value) $(date '+%F %T')" + if send_alert "$body" "EPICS resolved"; then + mlog "$tag" "resolve notification sent" + else + mlog "$tag" "ERROR: resolve notification failed to send" + fi fi fi in_alarm=0 diff --git a/README.md b/README.md index 6107551..40ff8c2 100644 --- a/README.md +++ b/README.md @@ -63,8 +63,9 @@ Behaviour of one monitor: - while the average is in alarm, sends the first message immediately, then up to `n_msg` messages total, spaced at least `msg_delay_s` apart, then stays silent -- once the average returns to normal, it sends **one** recovery ("RESOLVED") - message and resets the message counter +- once the average returns to normal, it resets the message counter and — if + at least one alarm message was sent this episode — sends **one** recovery + ("RESOLVED") message - unreadable / non-numeric reads are logged and skipped (they do not enter the average and never trigger an alarm)