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)