From 39abe553f5d517e4ea1c28235f0f006ea0488d08 Mon Sep 17 00:00:00 2001 From: yukkop Date: Sat, 25 Oct 2025 09:54:57 +0000 Subject: [PATCH] refactor(package): `sentinella`: +logging --- package/sentinèlla/default.nix | 6 +++++- package/sentinèlla/log.sh | 2 +- package/sentinèlla/router.sh | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/package/sentinèlla/default.nix b/package/sentinèlla/default.nix index 0df6393..24321c7 100644 --- a/package/sentinèlla/default.nix +++ b/package/sentinèlla/default.nix @@ -24,7 +24,11 @@ let inherit shell bashOptions; name = "router"; runtimeInputs = [ base64 gawk ]; - text = builtins.readFile ./router.sh; + text = '' + ${builtins.readFile ./log.sh} + ${builtins.readFile ./colors.sh} + ${builtins.readFile ./router.sh} + ''; }; sentinel = hectic.writeShellApplication { diff --git a/package/sentinèlla/log.sh b/package/sentinèlla/log.sh index 96ca706..306df6e 100644 --- a/package/sentinèlla/log.sh +++ b/package/sentinèlla/log.sh @@ -17,5 +17,5 @@ log() { # shellcheck disable=SC1003 fmt="$(printf "%s" "$1" | sed 's/\\033\[0m/''\'"$color"'/g')" shift - printf "%b\n" "$color$fmt$NC" "$@" + printf "%b\n" "$color$fmt$NC" "$@" >&2 } diff --git a/package/sentinèlla/router.sh b/package/sentinèlla/router.sh index 1025daf..4fa09cc 100644 --- a/package/sentinèlla/router.sh +++ b/package/sentinèlla/router.sh @@ -51,6 +51,7 @@ route_status() { tot=$((tot+1)) res=$(curl -sS -m "$TIMEOUT" -o /dev/null -w '%{http_code} %{time_total}' "$u" 2>/dev/null) || res="000 0" code=${res%% *}; ttot=${res#* } + log info "$u -> $code" case $code in 2*|3*) ok=true; okcnt=$((okcnt+1));; *) ok=false;; esac [ $first -eq 0 ] && printf ','; first=0 printf '{"url":"%s","code":%s,"time_s":%s,"ok":%s}' "$u" "$code" "$ttot" "$ok"