summaryrefslogtreecommitdiff
path: root/statuspage/checks/wireguard.sh
diff options
context:
space:
mode:
authorbatsumaru <>2026-07-01 16:25:42 +0900
committerbatsumaru <>2026-07-01 16:25:42 +0900
commit358106287b28bffa8505b67fe623f77a3fbceae3 (patch)
tree8d0fe44894090313330685136b25c5e6b3083b9c /statuspage/checks/wireguard.sh
parentaa73d4e03d0905b884cde1ed3c2f0bdf35f5ef30 (diff)
Auto-discover jails and add WireGuard peer info to status page
Replace the per-jail check scripts with checks/jails.sh, which lists running jails via jls and resolves each one's IPv4 (falling back to jexec+ifconfig for VNET jails, which don't set the ip4.addr jail parameter). New jails now show up without adding a script; the trade-off is a stopped jail just disappears rather than showing down, since jls only lists what's running. checks/wireguard.sh now also reports each configured peer's allowed-IP and time since last handshake, parsed from `wg show wg0 dump`. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Diffstat (limited to 'statuspage/checks/wireguard.sh')
-rwxr-xr-xstatuspage/checks/wireguard.sh36
1 files changed, 36 insertions, 0 deletions
diff --git a/statuspage/checks/wireguard.sh b/statuspage/checks/wireguard.sh
index 3a899e5..2928e3e 100755
--- a/statuspage/checks/wireguard.sh
+++ b/statuspage/checks/wireguard.sh
@@ -1,6 +1,7 @@
#!/bin/sh
# checks/wireguard.sh
# wg0 interface: at least one recent handshake means the tunnel is alive.
+# Also lists each configured peer with time since its last handshake.
set -eu
DIR=$(dirname "$0")
@@ -8,3 +9,38 @@ DIR=$(dirname "$0")
STATUS=$(wg_status wg0)
json_line "host services" "wireguard (wg0)" "" "$STATUS"
+
+NOW=$(date +%s)
+TAB=$(printf '\t')
+
+wg show wg0 dump 2>/dev/null | tail -n +2 | while IFS="$TAB" read -r pubkey psk endpoint allowedips handshake rx tx keepalive; do
+ [ -n "$pubkey" ] || continue
+ peer_id=$(printf '%s' "$pubkey" | cut -c1-8)
+ label="peer $peer_id ($allowedips)"
+
+ if [ "$handshake" = "0" ]; then
+ json_line "wireguard peers" "$label" "never" "down"
+ continue
+ fi
+
+ age=$((NOW - handshake))
+ if [ "$age" -lt 180 ]; then
+ pstatus="ok"
+ elif [ "$age" -lt 600 ]; then
+ pstatus="warn"
+ else
+ pstatus="down"
+ fi
+
+ if [ "$age" -lt 60 ]; then
+ rel="${age}s ago"
+ elif [ "$age" -lt 3600 ]; then
+ rel="$((age / 60))m ago"
+ elif [ "$age" -lt 86400 ]; then
+ rel="$((age / 3600))h ago"
+ else
+ rel="$((age / 86400))d ago"
+ fi
+
+ json_line "wireguard peers" "$label" "$rel" "$pstatus"
+done