diff options
| author | batsumaru <> | 2026-07-01 17:46:33 +0900 |
|---|---|---|
| committer | batsumaru <> | 2026-07-01 17:46:33 +0900 |
| commit | 018f92b5a0d7ee97747720e28d48bdf8b0134f2e (patch) | |
| tree | a942df578f85d1f955447e84bf66d03d52f3f534 /statuspage/checks/pf.sh | |
| parent | df56450813b04c09cd24783c6ae3093f189c4519 (diff) | |
Abbreviate pf rule text so rows fit the column without wrapping
pfctl's verbose syntax (flags S/SA, quick, from any to any port = X,
proto tcp/udp/icmp) was overflowing the .section column width and
wrapping mid-rule. abbreviate_rule() in pf.sh strips the near-
universal boilerplate tokens on this ruleset and swaps in/out for
arrows - cuts each rule to roughly 35-45% of its original length.
Deliberately not a real pf syntax parser: it's a handful of targeted
sed substitutions, so a rule shape it doesn't recognize just passes
through unshortened rather than mangling. Only uses the Arrows block
(confirmed shipped in the scientifica font) - avoided Dingbats
(checkmark/X) since that block isn't included in this font.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Diffstat (limited to 'statuspage/checks/pf.sh')
| -rwxr-xr-x | statuspage/checks/pf.sh | 32 |
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 |
