fix(package): sentinèlla: use ip(8) for local-IP detection (inetutils hostname lacks -I); harden numeric parsing
This commit is contained in:
@@ -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
|
let
|
||||||
shell = "${dash}/bin/dash";
|
shell = "${dash}/bin/dash";
|
||||||
bashOptions = [
|
bashOptions = [
|
||||||
@@ -36,7 +36,7 @@ let
|
|||||||
watcher = hectic.writeShellApplication {
|
watcher = hectic.writeShellApplication {
|
||||||
inherit shell bashOptions;
|
inherit shell bashOptions;
|
||||||
name = "watcher";
|
name = "watcher";
|
||||||
runtimeInputs = [ curl jq gawk inetutils getent bind.dnsutils ];
|
runtimeInputs = [ curl jq gawk iproute2 getent bind.dnsutils ];
|
||||||
text = ''
|
text = ''
|
||||||
${builtins.readFile ./log.sh}
|
${builtins.readFile ./log.sh}
|
||||||
${builtins.readFile ./colors.sh}
|
${builtins.readFile ./colors.sh}
|
||||||
|
|||||||
@@ -61,7 +61,10 @@ local_ips() {
|
|||||||
printf '%s' "$SELF"
|
printf '%s' "$SELF"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
hostname -I 2>/dev/null || true
|
# ip -o -4 addr show: "<idx>: <iface> inet <ip>/<prefix> ..."
|
||||||
|
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
|
# is_local_ip(ip) — returns 0 if ip belongs to this node
|
||||||
@@ -151,8 +154,15 @@ while :; do
|
|||||||
|
|
||||||
ok="down"; total=0; good=0
|
ok="down"; total=0; good=0
|
||||||
if [ "$code" = "200" ]; then
|
if [ "$code" = "200" ]; then
|
||||||
summary=$(printf '%s' "$body" | parse_summary || true)
|
summary=$(printf '%s' "$body" | parse_summary 2>/dev/null || true)
|
||||||
[ -n "$summary" ] && { total=${summary%% *}; good=${summary#* }; }
|
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"
|
[ "$total" -eq "$good" ] && ok="up"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user