summaryrefslogtreecommitdiff
path: root/statuspage
diff options
context:
space:
mode:
Diffstat (limited to 'statuspage')
-rwxr-xr-xstatuspage/checks/pf.sh32
1 files changed, 30 insertions, 2 deletions
diff --git a/statuspage/checks/pf.sh b/statuspage/checks/pf.sh
index 47b2acd..ef39268 100755
--- a/statuspage/checks/pf.sh
+++ b/statuspage/checks/pf.sh
@@ -11,6 +11,34 @@ set -eu
DIR=$(dirname "$0")
. "$DIR/../lib/common.sh"
+# abbreviate_rule RULE
+# Best-effort compression of pfctl's verbose rule syntax so rows fit a
+# narrow column without wrapping mid-word. Not a semantic parser - just
+# strips/replaces the tokens that are near-universal boilerplate on this
+# ruleset (quick, flags S/SA, proto/from-to-port verbosity) and swaps
+# in/out for arrows. Uses only the Arrows block (confirmed present in
+# the scientifica font); avoids Dingbats (✓/✗) since that block isn't
+# shipped. A rule shape this doesn't recognize just passes through
+# unshortened - still correct, just longer.
+abbreviate_rule() {
+ printf '%s' "$1" | sed -E \
+ -e 's/ in / → /' \
+ -e 's/ out / ← /' \
+ -e 's/ quick//' \
+ -e 's/ on / /' \
+ -e 's/ flags [A-Za-z\/]+//' \
+ -e 's/ modulate state/ [state]/' \
+ -e 's/ keep state/ [state]/' \
+ -e 's/ proto (tcp|udp|icmp)/ \1/' \
+ -e 's/ from any to any port = ([a-zA-Z0-9]+)/ :\1/' \
+ -e 's/ inet / /' \
+ -e 's/ round-robin//' \
+ -e 's/ all$//' \
+ -e 's/ all / /' \
+ -e 's/ +/ /g' \
+ -e 's/^ +//' -e 's/ +$//'
+}
+
INFO=$(pfctl -si 2>/dev/null) || INFO=""
ENABLED=$(printf '%s\n' "$INFO" | awk -F'[ :]+' '/^Status:/{print $2; exit}')
@@ -40,10 +68,10 @@ 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"
+ json_line "pf" " $(abbreviate_rule "$rule")" "" "info"
done
pfctl -sn 2>/dev/null | while IFS= read -r rule; do
[ -n "$rule" ] || continue
- json_line "pf" " nat: $rule" "" "info"
+ json_line "pf" " nat: $(abbreviate_rule "$rule")" "" "info"
done