Files
Cody Lee 65ad210f20 feat: add UniFi Protect device metrics (closes #1015)
Collects Protect device data (sensors, cameras, lights, bridges, link
stations, NVR) via the official Integration API and exports it through
Prometheus, InfluxDB, and DataDog. Opt-in via save_protect_devices,
gated by protect_api_key.

Bumps github.com/unpoller/unifi to v6, which added the Protect API
client (breaking change: FlexInt/FlexBool/FlexFloat replace nullable
pointers).
2026-08-19 15:14:43 -05:00

48 lines
899 B
Go

package influxunifi
import (
"github.com/unpoller/unifi/v6"
)
// 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})
}