55 lines
1.6 KiB
Bash
55 lines
1.6 KiB
Bash
|
|
#!/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
|