Rule usage
On the Security posture page the "Rule usage" table shows when each rule
last matched traffic. For this OPNexus reads the firewall's packet counters. Because these
start from zero on every change and every reboot, OPNexus remembers the time at which
a counter last grew (resolution: one observation, every 15 minutes). Immediately before every apply that OPNexus triggers
on a firewall (rules, NAT, aliases, VPN, network), OPNexus additionally reads the counters, because every apply resets them;
this way no hits are lost. The counters come from the firewall's ruleStats (already summed per rule; on older OPNsense versions from the loaded rule set). A rule counts
as unused if OPNexus has observed it for at least 30 days without seeing a hit;
until then it shows "Collecting data" (the observation period restarts when the rule is enabled or changed, and after a pf reload with a long gap in the counters), so that a new installation does not raise a false
alarm. Rules from the rule editor or the API are recorded, as well as not yet migrated rules in the legacy format (OPNsense's
automatic rules are not). Unused rules feed into the security posture as the finding "Rules in use".