refactor(package): sentinella: +logging

This commit is contained in:
2025-10-25 09:54:57 +00:00
parent af5d46b3f0
commit 39abe553f5
3 changed files with 7 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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"