From 23196eafed4661d9a6268faa92eb18214939e202 Mon Sep 17 00:00:00 2001 From: ergosteur <1992147+ergosteur@users.noreply.github.com> Date: Thu, 6 Aug 2026 15:49:16 +0000 Subject: [PATCH] Move watchdog alert address into conf/ Both watchdogs hardcoded the notification address. Read it from conf/watchdog.conf instead, matching the pattern used for the other credentials, so the repo carries no real contact details. If the config is absent the watchdogs still run and log; sendAlert notes the missing address and skips the mail rather than invoking mail(1) with an empty recipient. Co-Authored-By: Claude Opus 5 --- conf/watchdog.conf.example | 11 +++++++++++ lxc-watchdog.sh | 16 +++++++++++++++- vm-watchdog.sh | 16 +++++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 conf/watchdog.conf.example diff --git a/conf/watchdog.conf.example b/conf/watchdog.conf.example new file mode 100644 index 0000000..4d79457 --- /dev/null +++ b/conf/watchdog.conf.example @@ -0,0 +1,11 @@ +# Alert destination for vm-watchdog.sh and lxc-watchdog.sh. +# +# Copy to conf/watchdog.conf next to the scripts: +# cp conf/watchdog.conf.example conf/watchdog.conf +# +# The scripts look for it relative to their own location, so this works both in a +# checkout and deployed at /opt/ergosteur. Override with WATCHDOG_CONFIG. +# +# If the file is absent the watchdogs still run and log; they just skip the email. + +WATCHDOG_EMAIL=alerts@example.com diff --git a/lxc-watchdog.sh b/lxc-watchdog.sh index 2ce2e5e..74ecc08 100755 --- a/lxc-watchdog.sh +++ b/lxc-watchdog.sh @@ -13,7 +13,17 @@ declare -A Containers=( ) logFile="/var/log/proxmox_lxc_watchdog.log" -email="your_email@example.com" + +# Alert address comes from conf/watchdog.conf (see conf/watchdog.conf.example), +# resolved relative to this script so it works from a checkout or /opt/ergosteur. +SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) +CONFIG=${WATCHDOG_CONFIG:-$SCRIPT_DIR/conf/watchdog.conf} +email="" +if [[ -r "$CONFIG" ]]; then + # shellcheck source=/dev/null + . "$CONFIG" + email="${WATCHDOG_EMAIL:-}" +fi # Log function log () { @@ -26,6 +36,10 @@ log () { sendAlert () { subject="[Proxmox LXC WatchDog] $1" body="$2" + if [[ -z "$email" ]]; then + log "No WATCHDOG_EMAIL configured in $CONFIG; skipping alert: $subject" + return + fi echo -e "$body" | mail -s "$subject" "$email" } diff --git a/vm-watchdog.sh b/vm-watchdog.sh index 58d98f4..b48424e 100755 --- a/vm-watchdog.sh +++ b/vm-watchdog.sh @@ -11,7 +11,17 @@ declare -A VMs=( ) logFile="/var/log/proxmox_watchdog.log" -email="alerts@example.com" + +# Alert address comes from conf/watchdog.conf (see conf/watchdog.conf.example), +# resolved relative to this script so it works from a checkout or /opt/ergosteur. +SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) +CONFIG=${WATCHDOG_CONFIG:-$SCRIPT_DIR/conf/watchdog.conf} +email="" +if [[ -r "$CONFIG" ]]; then + # shellcheck source=/dev/null + . "$CONFIG" + email="${WATCHDOG_EMAIL:-}" +fi # Log function log () { @@ -24,6 +34,10 @@ log () { sendAlert () { subject="[Proxmox WatchDog] $1" body="$2" + if [[ -z "$email" ]]; then + log "No WATCHDOG_EMAIL configured in $CONFIG; skipping alert: $subject" + return + fi echo -e "$body" | mail -s "$subject" "$email" }