inputs.pf: fails to parse pfctl -s info output with 2-space indentation ("searches" field not found)
Telegraf version: 1.39.1 OS: 26.7.3_11, FreeBSD-basiert
Steps to reproduce:
- Enable inputs.pf in a Telegraf config on OPNsense (via os-telegraf plugin)
- Observe repeated errors in Telegraf logs: E! [inputs.pf] Error in plugin: struct data for tag "searches" not found in pfctl output
Expected behavior: pf_searches (and related State Table metrics) should be collected without error.
Actual pfctl -s info output (relevant excerpt, note the 2-space indentation before each field): State Table Total Rate current entries 250 searches 92810970 1789.5/s inserts 64126 1.2/s removals 63876 1.2/s
Root cause: plugins/inputs/pf/pf.go matches State Table lines with:
stateTableRE = regexp.MustCompile(^ (.*?)\s+(\d+))
This regex expects exactly one leading space before the field name. On this system, pfctl -s info indents State Table fields with two spaces. Because the capture group (.*?) is non-greedy but the regex only consumes one literal leading space explicitly, the second leading space becomes part of the captured field name (e.g. " searches" instead of "searches"), which then fails to match the plugin's internal stateTable name list, producing the "not found" error.
Suggested fix: Relax the regex to tolerate variable leading whitespace, e.g.:
stateTableRE = regexp.MustCompile(^\s+(.*?)\s+(\d+))
(with a trim on the captured group, since (.*?) non-greedy behavior should still work correctly against variable-width leading whitespace)
Additional context: Same root cause likely also breaks the "current entries" line (no rate value present, single numeric field), though this wasn't the field named in the error.
Source: influxdata/telegraf