From f158a80492cb9175a58abd17c45a04d4194cb9e7 Mon Sep 17 00:00:00 2001 From: yukkop Date: Mon, 27 Apr 2026 17:21:00 +0000 Subject: [PATCH] =?UTF-8?q?fix(`package`):=20`sentin=C3=A8lla`:=20use=20ip?= =?UTF-8?q?(8)=20for=20local-IP=20detection=20(inetutils=20hostname=20lack?= =?UTF-8?q?s=20-I);=20harden=20numeric=20parsing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package/sentinèlla/default.nix | 4 ++-- package/sentinèlla/watcher.sh | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/package/sentinèlla/default.nix b/package/sentinèlla/default.nix index f1aed70..a845a96 100644 --- a/package/sentinèlla/default.nix +++ b/package/sentinèlla/default.nix @@ -1,4 +1,4 @@ -{ symlinkJoin, writeTextFile, socat, dash, hectic, curl, gawk, jq, inetutils, getent, bind }: +{ symlinkJoin, writeTextFile, socat, dash, hectic, curl, gawk, jq, iproute2, getent, bind }: let shell = "${dash}/bin/dash"; bashOptions = [ @@ -36,7 +36,7 @@ let watcher = hectic.writeShellApplication { inherit shell bashOptions; name = "watcher"; - runtimeInputs = [ curl jq gawk inetutils getent bind.dnsutils ]; + runtimeInputs = [ curl jq gawk iproute2 getent bind.dnsutils ]; text = '' ${builtins.readFile ./log.sh} ${builtins.readFile ./colors.sh} diff --git a/package/sentinèlla/watcher.sh b/package/sentinèlla/watcher.sh index bd5678a..96729b1 100644 --- a/package/sentinèlla/watcher.sh +++ b/package/sentinèlla/watcher.sh @@ -61,7 +61,10 @@ local_ips() { printf '%s' "$SELF" return fi - hostname -I 2>/dev/null || true + # ip -o -4 addr show: ": inet / ..." + ip -o addr show 2>/dev/null \ + | awk '$3 ~ /^inet6?$/ { sub(/\/.*/, "", $4); print $4 }' \ + | tr '\n' ' ' } # is_local_ip(ip) — returns 0 if ip belongs to this node @@ -151,8 +154,15 @@ while :; do ok="down"; total=0; good=0 if [ "$code" = "200" ]; then - summary=$(printf '%s' "$body" | parse_summary || true) - [ -n "$summary" ] && { total=${summary%% *}; good=${summary#* }; } + summary=$(printf '%s' "$body" | parse_summary 2>/dev/null || true) + if [ -n "$summary" ]; then + _total=${summary%% *} + _good=${summary#* } + case "$_total" in ''|*[!0-9]*) _total=0 ;; esac + case "$_good" in ''|*[!0-9]*) _good=0 ;; esac + total=$_total + good=$_good + fi [ "$total" -eq "$good" ] && ok="up" fi