From 882dfd825499e80db55652963f2fcbca8bb36d23 Mon Sep 17 00:00:00 2001 From: operator-main Date: Sun, 4 Oct 2026 18:34:33 +0000 Subject: [PATCH] Add watchdog-alert-check.sh (box watchdog-alerts helper script) Self-contained FAILED-relaunch scanner for chromebox-watchdog.log with watermark at NETVM_ROOT/watchdog-alert-watermark.txt. Exits 0 quiet when clean, 1 with new lines printed when alerting. The box-ctl.py watchdog-alerts action (in 2db0d92) drives this script. Session: sidechat/chromebox-ops --- bin/watchdog-alert-check.sh | 54 +++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 bin/watchdog-alert-check.sh diff --git a/bin/watchdog-alert-check.sh b/bin/watchdog-alert-check.sh new file mode 100755 index 0000000..8dbbc1d --- /dev/null +++ b/bin/watchdog-alert-check.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# watchdog-alert-check.sh - Check for new failed browser relaunches. +# +# Scans /home/super/Projects/NetVM/chromebox-watchdog.log for +# "relaunch FAILED" lines newer than the watermark. +# +# Watermark: /home/super/Projects/NetVM/watchdog-alert-watermark.txt +# Holds the last reported log line (or is empty/missing on first run). +# +# Output contract: +# - No new failures: print nothing, exit 0. +# - New failures: print each new "relaunch FAILED" line, update the +# watermark to the newest line, exit 1. +# +# Self-contained: no arguments, no nested quoting. Safe to call from cron +# or from the box CLI. + +set -u + +LOG="/home/super/Projects/NetVM/chromebox-watchdog.log" +WATERMARK="/home/super/Projects/NetVM/watchdog-alert-watermark.txt" + +# No log file -> nothing to report. +[ -f "$LOG" ] || exit 0 + +# Gather all FAILED lines in chronological order. +mapfile -t failed < <(grep "relaunch FAILED" "$LOG" 2>/dev/null || true) +[ "${#failed[@]}" -gt 0 ] || exit 0 + +# Read the watermark (last reported line). Missing/empty = report everything. +watermark="" +[ -f "$WATERMARK" ] && watermark="$(cat "$WATERMARK")" + +# Collect lines strictly newer than the watermark. +new_lines=() +if [ -z "$watermark" ]; then + new_lines=("${failed[@]}") +else + seen_watermark=0 + for line in "${failed[@]}"; do + if [ "$seen_watermark" -eq 1 ]; then + new_lines+=("$line") + elif [ "$line" = "$watermark" ]; then + seen_watermark=1 + fi + done +fi + +[ "${#new_lines[@]}" -gt 0 ] || exit 0 + +# Report new failures and advance the watermark to the newest line. +printf '%s\n' "${new_lines[@]}" +printf '%s\n' "${failed[-1]}" > "$WATERMARK" +exit 1