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

40 lines
1006 B
Go

package promunifi
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/unpoller/unifi/v6"
)
type portanomaly struct {
AnomalyCount *prometheus.Desc
AnomalyLastSeen *prometheus.Desc
}
func descPortAnomaly(ns string) *portanomaly {
labels := []string{"site_name", "source", "device_mac", "port_idx", "anomaly_type"}
nd := prometheus.NewDesc
return &portanomaly{
AnomalyCount: nd(ns+"port_anomaly_count", "Number of anomaly events on this port", labels, nil),
AnomalyLastSeen: nd(ns+"port_anomaly_last_seen", "Unix timestamp of the last anomaly event on this port", labels, nil),
}
}
func (u *promUnifi) exportPortAnomalies(r report, anomalies []*unifi.PortAnomaly) {
for _, a := range anomalies {
labels := []string{
a.SiteName,
a.SourceName,
a.DeviceMAC,
a.PortIdx.Txt,
a.AnomalyType,
}
r.send([]*metric{
{u.PortAnomaly.AnomalyCount, gauge, a.Count.Val, labels},
{u.PortAnomaly.AnomalyLastSeen, gauge, a.LastSeen.Val, labels},
})
}
}