Files
unpoller-unpoller-4/pkg/influxunifi/firewall_policies.go
Cody Lee 6b33b6b97b feat: firewall policy metrics across all output plugins (closes #928) (#979)
* feat(promunifi): add firewall policy metrics (closes #928)

Bump unifi client to v5.22.0 and wire up firewall policy data end-to-end:

- poller.Metrics: add FirewallPolicies []any slice
- inputunifi: collect GetFirewallPolicies() per poll cycle; apply
  DefaultSiteNameOverride; augment into poller.Metrics
- promunifi: export per-rule (rule_enabled, rule_index) and per-site
  aggregate metrics (rules_total, rules_enabled, rules_disabled,
  rules_by_action, rules_predefined, rules_custom, rules_logging_enabled)

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

* feat: export firewall policies to influx, datadog, and otel outputs

Extends firewall policy support (PR #979) to all remaining output plugins:

- influxunifi: batchFirewallPolicy() writes measurement "firewall_policy"
  with tags (rule_name, action, protocol, ip_version, source/dest zone,
  site_name, source) and fields (enabled, index, predefined, logging)
- datadogunifi: batchFirewallPolicy() emits the same data as Datadog gauges
  under the "firewall_policy.*" namespace
- otelunifi: exportFirewallPolicies() emits per-rule gauges
  (unifi_firewall_rule_enabled, unifi_firewall_rule_index) and per-site
  aggregates (rules_total, rules_enabled, rules_disabled, rules_by_action,
  rules_predefined, rules_custom, rules_logging_enabled)

Also rebases onto master to pick up the otelunifi plugin (PR #978).

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 18:26:27 -05:00

48 lines
899 B
Go

package influxunifi
import (
"github.com/unpoller/unifi/v5"
)
// batchFirewallPolicy generates a firewall policy datapoint for InfluxDB.
func (u *InfluxUnifi) batchFirewallPolicy(r report, p *unifi.FirewallPolicy) {
if p == nil {
return
}
tags := map[string]string{
"rule_name": p.Name,
"action": p.Action,
"protocol": p.Protocol,
"ip_version": p.IPVersion,
"source_zone": p.Source.ZoneID,
"dest_zone": p.Destination.ZoneID,
"site_name": p.SiteName,
"source": p.SourceName,
}
enabled := 0
if p.Enabled.Val {
enabled = 1
}
predefined := 0
if p.Predefined.Val {
predefined = 1
}
logging := 0
if p.Logging.Val {
logging = 1
}
fields := map[string]any{
"enabled": enabled,
"index": p.Index.Val,
"predefined": predefined,
"logging": logging,
}
r.send(&metric{Table: "firewall_policy", Tags: tags, Fields: fields})
}