ruined every thing

This commit is contained in:
2025-10-20 17:17:08 +00:00
parent dbe4dfc2bc
commit b3041edbdc
4 changed files with 25 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
{ symlinkJoin, writeTextFile, socat, dash, hectic, curl, gawk }:
{ symlinkJoin, writeTextFile, socat, dash, hectic, curl, gawk, jq }:
let
shell = "${dash}/bin/dash";
bashOptions = [
@@ -30,7 +30,7 @@ let
sentinel = hectic.writeShellApplication {
inherit shell bashOptions;
name = "sentinel";
runtimeInputs = [ hectic.shellplot curl ];
runtimeInputs = [ hectic.shellplot curl jq ];
text = ''
${builtins.readFile ./log.sh}

View File

@@ -3,6 +3,7 @@
# router.sh — POSIX sh HTTP backend (for socat)
# usage: socat -T5 -t5 TCP-LISTEN:${port},reuseaddr,fork EXEC:"dash ${currentfile}"
# Routes:
# GET / -> {"status":...,"disk":...}
# GET /status -> check $URLS (0/0 if unset)
# GET /disk -> check $VOLUMES (all if unset)
# Env:
@@ -14,6 +15,10 @@
: "${TIMEOUT:=5}"
: "${VOLUMES:=$(df -P | awk 'NR>1{print $6}')}"
route_summary() {
printf '%s' '{"status":'"$(route_status)"',"disk":'"$(route_disk)"'}'
}
route_status() {
if [ -z "${URLS:-}" ]; then
printf '{"checks":[],"summary":{"total":0,"ok":0}}'
@@ -103,8 +108,9 @@ tmp=$(mktemp) || exit 1
trap 'rm -f "$tmp"' EXIT INT HUP
case "$req" in
"GET /status "*) route_status >"$tmp"; status='200 OK'; ctype='application/json' ;;
"GET /disk "*) route_disk >"$tmp"; status='200 OK'; ctype='application/json' ;;
"GET / "*) route_summary >"$tmp"; status='200 OK'; ctype='application/json' ;;
"GET /status "*) route_status >"$tmp"; status='200 OK'; ctype='application/json' ;;
"GET /disk "*) route_disk >"$tmp"; status='200 OK'; ctype='application/json' ;;
*) printf 'Not found\n' >"$tmp"; status='404 Not Found'; ctype='text/plain' ;;
esac

View File

@@ -75,6 +75,10 @@ list_failures() {
}
# --- main loop ---
# NOTE: remove temp response body on any exit
trap 'rm -f "$tmpb" 2> /dev/null' EXIT INT HUP
while :; do
log info "pooling ${WHITE}${POLLING_INTERVAL_SEC}${NC} sec"
i=1
@@ -83,7 +87,7 @@ while :; do
[ -n "${srv:-}" ] || break
tok=$(get_csv "$TOKENS" "$i") || tok="-"
url="${srv%/}/status"
url="${srv%/}"
auth_h=""
[ "${tok}" != "-" ] && [ -n "${tok}" ] && auth_h="-H Authorization: Basic\ $tok"