mirror of
https://github.com/unpoller/unpoller.git
synced 2026-04-05 08:54:09 -04:00
Collect port anomalies from the UniFi v2 API endpoint
/proxy/network/v2/api/site/{site}/ports/port-anomalies and export
them to all output plugins (Prometheus, InfluxDB, DataDog, OpenTelemetry).
Metrics exported per port:
- port_anomaly_count – number of anomaly events
- port_anomaly_last_seen – unix timestamp of last event
Labels: site_name, source, device_mac, port_idx, anomaly_type
Bumps github.com/unpoller/unifi/v5 to v5.24.0 which adds GetPortAnomalies.
Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
32 lines
656 B
Go
32 lines
656 B
Go
package datadogunifi
|
|
|
|
import (
|
|
"github.com/unpoller/unifi/v5"
|
|
)
|
|
|
|
// batchPortAnomaly generates port anomaly datapoints for Datadog.
|
|
func (u *DatadogUnifi) batchPortAnomaly(r report, a *unifi.PortAnomaly) {
|
|
if a == nil {
|
|
return
|
|
}
|
|
|
|
metricName := metricNamespace("port_anomaly")
|
|
|
|
tags := []string{
|
|
tag("site_name", a.SiteName),
|
|
tag("source", a.SourceName),
|
|
tag("device_mac", a.DeviceMAC),
|
|
tag("port_idx", a.PortIdx.Txt),
|
|
tag("anomaly_type", a.AnomalyType),
|
|
}
|
|
|
|
data := map[string]float64{
|
|
"count": a.Count.Val,
|
|
"last_seen": a.LastSeen.Val,
|
|
}
|
|
|
|
for name, value := range data {
|
|
_ = r.reportGauge(metricName(name), value, tags)
|
|
}
|
|
}
|