--json-Modus + Doku HTTP-Endpunkt (192.168.0.250:8090) und Homepage-customapi-Widget

This commit is contained in:
wralto-user-1
2026-11-28 18:42:05 +01:00
parent 820e906926
commit b35f5ec483
2 changed files with 29 additions and 1 deletions

View File

@ -6,8 +6,11 @@
# Exit-Code 0 = alles ok, 1 = Auffaelligkeiten gefunden.
WARN=0
WARNLIST=()
JSON=0
[ "$1" = "--json" ] && JSON=1
say() { printf '%s\n' "$*"; }
flag() { say "!! $*"; WARN=1; }
flag() { say "!! $*"; WARN=1; WARNLIST+=("$*"); }
say "=== proxi-status $(date '+%d.%m.%Y %H:%M:%S') ==="
@ -72,4 +75,21 @@ systemctl is-active proxi-healthcheck.timer >/dev/null 2>&1 || flag "proxi-healt
say
if [ "$WARN" = "0" ]; then say "== ERGEBNIS: alles ok =="; else say "== ERGEBNIS: Auffaelligkeiten siehe '!!' =="; fi
if [ "$JSON" = "1" ]; then
OUT=/usr/local/share/proxi-status/status.json
mkdir -p "$(dirname "$OUT")"
{
printf '{"ok": %s, "ts": "%s", "summary": ' "$([ $WARN = 0 ] && echo true || echo false)" "$(date -Iseconds)"
if [ $WARN = 0 ]; then printf '"alles ok"'; else printf '"%d Auffaelligkeit(en)"' "${#WARNLIST[@]}"; fi
printf ', "warnings": ['
first=1
for w in "${WARNLIST[@]}"; do
[ $first = 1 ] || printf ', '
first=0
printf '"%s"' "$(printf '%s' "$w" | sed 's/"/\\"/g')"
done
printf ']}\n'
} > "$OUT.tmp" && mv "$OUT.tmp" "$OUT"
fi
exit $WARN