refactor(package): sentinella: +logging
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user