summaryrefslogtreecommitdiff
path: root/statuspage/checks/pf.sh
diff options
context:
space:
mode:
authorbatsumaru <>2026-07-01 16:52:22 +0900
committerbatsumaru <>2026-07-01 16:52:22 +0900
commita034c6724381b172ba4b6d36357682c44f18b8de (patch)
treeacb122f89c9432d56f3964c9a29d99ee1cf8647e /statuspage/checks/pf.sh
parentbb3567aa4bd5d03fcd0fa74eea42381f159227b0 (diff)
Add pf visibility and a wg-quick watcher check, add a neutral row status
checks/pf.sh reports pf enabled/disabled, state table usage (warn/down as it nears the configured limit), and the loaded filter/nat rule count, then lists each active rule as its own row for at-a-glance visibility into what's actually being enforced. Those rule rows use a new "info" status (gray square) rather than "ok" - they're not a health check on any individual rule, so a green square there would misleadingly imply otherwise. render.sh maps info -> gray; anything else still falls back to red. checks/wg-watcher.sh checks the route-monitor process wg-quick spawns to react to WAN interface/address changes - it isn't rc.d-managed, so there's no `service status` for it, hence the new proc_running helper in lib/common.sh (pgrep -f based). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Diffstat (limited to 'statuspage/checks/pf.sh')
-rwxr-xr-xstatuspage/checks/pf.sh49
1 files changed, 49 insertions, 0 deletions
diff --git a/statuspage/checks/pf.sh b/statuspage/checks/pf.sh
new file mode 100755
index 0000000..47b2acd
--- /dev/null
+++ b/statuspage/checks/pf.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+# checks/pf.sh
+# pf health summary (enabled, state table usage, rule count), plus the
+# actual active filter and nat/rdr rules listed as rows below. The rule
+# rows use status "info" (a neutral gray square) rather than "ok" -
+# they're informational, not a health signal, and a green square there
+# would wrongly imply each individual rule was itself being health-
+# checked.
+set -eu
+
+DIR=$(dirname "$0")
+. "$DIR/../lib/common.sh"
+
+INFO=$(pfctl -si 2>/dev/null) || INFO=""
+
+ENABLED=$(printf '%s\n' "$INFO" | awk -F'[ :]+' '/^Status:/{print $2; exit}')
+if [ "$ENABLED" = "Enabled" ]; then
+ json_line "pf" "pf" "" "ok"
+else
+ json_line "pf" "pf" "${ENABLED:-unknown}" "down"
+fi
+
+CURRENT=$(printf '%s\n' "$INFO" | awk '/current entries/{print $NF; exit}')
+LIMIT=$(pfctl -sm 2>/dev/null | awk '/^states/{print $NF; exit}')
+
+if [ -n "$CURRENT" ] && [ -n "$LIMIT" ] && [ "$LIMIT" -gt 0 ] 2>/dev/null; then
+ PCT=$((CURRENT * 100 / LIMIT))
+ if [ "$PCT" -ge 90 ]; then
+ SSTATUS=down
+ elif [ "$PCT" -ge 75 ]; then
+ SSTATUS=warn
+ else
+ SSTATUS=ok
+ fi
+ json_line "pf" "state table" "${CURRENT}/${LIMIT} (${PCT}%)" "$SSTATUS"
+fi
+
+RULE_COUNT=$(pfctl -sr 2>/dev/null | grep -c .) || RULE_COUNT=0
+json_line "pf" "filter rules loaded" "$RULE_COUNT" "ok"
+
+pfctl -sr 2>/dev/null | while IFS= read -r rule; do
+ [ -n "$rule" ] || continue
+ json_line "pf" " $rule" "" "info"
+done
+
+pfctl -sn 2>/dev/null | while IFS= read -r rule; do
+ [ -n "$rule" ] || continue
+ json_line "pf" " nat: $rule" "" "info"
+done