diff options
| author | batsumaru <> | 2026-07-01 15:38:51 +0900 |
|---|---|---|
| committer | batsumaru <> | 2026-07-01 15:38:51 +0900 |
| commit | dfec6df2fb876fadb20d24a5bd8f4b4400a0f659 (patch) | |
| tree | 3fc126f5bbaeef31b3a7a6d3e2afda968473c9b9 /statuspage/lib/common.sh | |
Split monolithic status check.sh into modular check scripts
Replace the single-file prototype with independently-addable check
scripts (checks/*.sh) that each emit JSONL rows, a shared helper lib,
and one orchestrator/renderer (render.sh) that groups rows by section
and writes the static status page. A broken check script now shows up
as a down/warn row instead of crashing the whole render.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Diffstat (limited to 'statuspage/lib/common.sh')
| -rw-r--r-- | statuspage/lib/common.sh | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/statuspage/lib/common.sh b/statuspage/lib/common.sh new file mode 100644 index 0000000..d063e07 --- /dev/null +++ b/statuspage/lib/common.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# lib/common.sh +# Shared helpers for statuspage check scripts. Source this, don't execute it. +# +# . "$(dirname "$0")/../lib/common.sh" + +# json_line SECTION LABEL VALUE STATUS +# Emits one JSONL row on stdout. Escapes double quotes and backslashes in +# LABEL/VALUE so a stray '"' in e.g. `zpool status` output can't break the +# line for the renderer's parser. +json_line() { + section=$1 + label=$2 + value=$3 + status=$4 + + # Order matters: backslashes first, then quotes, then newlines (zpool + # status output can be multi-line when a pool is degraded) so a JSONL + # line always stays exactly one line. + label=$(printf '%s' "$label" | sed 's/\\/\\\\/g; s/"/\\"/g' | tr '\n' '\1' | sed 's/\x01/\\n/g') + value=$(printf '%s' "$value" | sed 's/\\/\\\\/g; s/"/\\"/g' | tr '\n' '\1' | sed 's/\x01/\\n/g') + + printf '{"section": "%s", "label": "%s", "value": "%s", "status": "%s"}\n' \ + "$section" "$label" "$value" "$status" +} + +# svc_status NAME +# Prints "ok" or "down" depending on `service NAME status`. +svc_status() { + service "$1" status >/dev/null 2>&1 && echo "ok" || echo "down" +} + +# wg_status IFACE +# Prints "ok" or "down" depending on whether wg reports handshakes for IFACE. +wg_status() { + wg show "$1" latest-handshakes >/dev/null 2>&1 && echo "ok" || echo "down" +} + +# port_check IP PORT +# Prints "ok" or "down" depending on TCP connect success. +port_check() { + nc -z -w2 "$1" "$2" >/dev/null 2>&1 && echo "ok" || echo "down" +} + +# jail_status NAME +# Prints "ok" or "down" depending on whether the jail is running. +jail_status() { + jls -j "$1" >/dev/null 2>&1 && echo "ok" || echo "down" +} |
