mirror of
https://github.com/unpoller/unpoller.git
synced 2026-04-05 08:54:09 -04:00
Fix site name override for DPI clients, anomalies, and site metrics
- Apply site name override to DPI clients (ClientsDPI) in augmentMetrics - Apply site name override to client anomalies when collecting events - Apply site name override to sites (both Name and SiteName fields) when adding to metrics - Apply site name override to DPI sites, speed tests, and country traffic - Move applySiteNameOverride call to end of augmentMetrics to ensure all metrics are processed - This ensures all Prometheus metrics use console names instead of 'Default (default)' for Cloud Gateways
This commit is contained in:
@@ -3,6 +3,7 @@ package inputunifi
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unpoller/unifi/v5"
|
"github.com/unpoller/unifi/v5"
|
||||||
@@ -83,6 +84,14 @@ func (u *InputUnifi) collectAnomalies(logs []any, sites []*unifi.Site, c *Contro
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, e := range events {
|
for _, e := range events {
|
||||||
|
// Apply site name override for anomalies if configured
|
||||||
|
if c.DefaultSiteNameOverride != "" {
|
||||||
|
lower := strings.ToLower(e.SiteName)
|
||||||
|
if lower == "default" || strings.Contains(lower, "default") {
|
||||||
|
e.SiteName = c.DefaultSiteNameOverride
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logs = append(logs, e)
|
logs = append(logs, e)
|
||||||
|
|
||||||
webserver.NewInputEvent(PluginName, s.ID+"_anomalies", &webserver.Event{
|
webserver.NewInputEvent(PluginName, s.ID+"_anomalies", &webserver.Event{
|
||||||
|
|||||||
@@ -275,13 +275,6 @@ func (u *InputUnifi) augmentMetrics(c *Controller, metrics *Metrics) *poller.Met
|
|||||||
|
|
||||||
m, devices, bssdIDs := extractDevices(metrics)
|
m, devices, bssdIDs := extractDevices(metrics)
|
||||||
|
|
||||||
// Apply default_site_name_override to devices if configured.
|
|
||||||
// This allows us to use the console name for Cloud Gateways while keeping
|
|
||||||
// the actual site name ("default") for API calls.
|
|
||||||
if c.DefaultSiteNameOverride != "" {
|
|
||||||
applySiteNameOverride(m, c.DefaultSiteNameOverride)
|
|
||||||
}
|
|
||||||
|
|
||||||
// These come blank, so set them here.
|
// These come blank, so set them here.
|
||||||
for _, client := range metrics.Clients {
|
for _, client := range metrics.Clients {
|
||||||
if devices[client.Mac] = client.Name; client.Name == "" {
|
if devices[client.Mac] = client.Name; client.Name == "" {
|
||||||
@@ -295,6 +288,12 @@ func (u *InputUnifi) augmentMetrics(c *Controller, metrics *Metrics) *poller.Met
|
|||||||
client.ApName = devices[client.ApMac]
|
client.ApName = devices[client.ApMac]
|
||||||
client.GwName = devices[client.GwMac]
|
client.GwName = devices[client.GwMac]
|
||||||
client.RadioDescription = bssdIDs[client.Bssid] + client.RadioProto
|
client.RadioDescription = bssdIDs[client.Bssid] + client.RadioProto
|
||||||
|
|
||||||
|
// Apply site name override for clients if configured
|
||||||
|
if c.DefaultSiteNameOverride != "" && isDefaultSiteName(client.SiteName) {
|
||||||
|
client.SiteName = c.DefaultSiteNameOverride
|
||||||
|
}
|
||||||
|
|
||||||
m.Clients = append(m.Clients, client)
|
m.Clients = append(m.Clients, client)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,6 +306,12 @@ func (u *InputUnifi) augmentMetrics(c *Controller, metrics *Metrics) *poller.Met
|
|||||||
|
|
||||||
client.Name = RedactNamePII(client.Name, c.HashPII, c.DropPII)
|
client.Name = RedactNamePII(client.Name, c.HashPII, c.DropPII)
|
||||||
client.MAC = RedactMacPII(client.MAC, c.HashPII, c.DropPII)
|
client.MAC = RedactMacPII(client.MAC, c.HashPII, c.DropPII)
|
||||||
|
|
||||||
|
// Apply site name override for DPI clients if configured
|
||||||
|
if c.DefaultSiteNameOverride != "" && isDefaultSiteName(client.SiteName) {
|
||||||
|
client.SiteName = c.DefaultSiteNameOverride
|
||||||
|
}
|
||||||
|
|
||||||
m.ClientsDPI = append(m.ClientsDPI, client)
|
m.ClientsDPI = append(m.ClientsDPI, client)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,22 +322,52 @@ func (u *InputUnifi) augmentMetrics(c *Controller, metrics *Metrics) *poller.Met
|
|||||||
|
|
||||||
if *c.SaveSites {
|
if *c.SaveSites {
|
||||||
for _, site := range metrics.Sites {
|
for _, site := range metrics.Sites {
|
||||||
|
// Apply site name override for sites if configured
|
||||||
|
if c.DefaultSiteNameOverride != "" {
|
||||||
|
if isDefaultSiteName(site.Name) {
|
||||||
|
site.Name = c.DefaultSiteNameOverride
|
||||||
|
}
|
||||||
|
if isDefaultSiteName(site.SiteName) {
|
||||||
|
site.SiteName = c.DefaultSiteNameOverride
|
||||||
|
}
|
||||||
|
}
|
||||||
m.Sites = append(m.Sites, site)
|
m.Sites = append(m.Sites, site)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, site := range metrics.SitesDPI {
|
for _, site := range metrics.SitesDPI {
|
||||||
|
// Apply site name override for DPI sites if configured
|
||||||
|
if c.DefaultSiteNameOverride != "" && isDefaultSiteName(site.SiteName) {
|
||||||
|
site.SiteName = c.DefaultSiteNameOverride
|
||||||
|
}
|
||||||
m.SitesDPI = append(m.SitesDPI, site)
|
m.SitesDPI = append(m.SitesDPI, site)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, speedTest := range metrics.SpeedTests {
|
for _, speedTest := range metrics.SpeedTests {
|
||||||
|
// Apply site name override for speed tests if configured
|
||||||
|
if c.DefaultSiteNameOverride != "" && isDefaultSiteName(speedTest.SiteName) {
|
||||||
|
speedTest.SiteName = c.DefaultSiteNameOverride
|
||||||
|
}
|
||||||
m.SpeedTests = append(m.SpeedTests, speedTest)
|
m.SpeedTests = append(m.SpeedTests, speedTest)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, traffic := range metrics.CountryTraffic {
|
for _, traffic := range metrics.CountryTraffic {
|
||||||
|
// Apply site name override for country traffic if configured
|
||||||
|
// UsageByCountry has TrafficSite.SiteName, not SiteName directly
|
||||||
|
if c.DefaultSiteNameOverride != "" && isDefaultSiteName(traffic.TrafficSite.SiteName) {
|
||||||
|
traffic.TrafficSite.SiteName = c.DefaultSiteNameOverride
|
||||||
|
}
|
||||||
m.CountryTraffic = append(m.CountryTraffic, traffic)
|
m.CountryTraffic = append(m.CountryTraffic, traffic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply default_site_name_override to all metrics if configured.
|
||||||
|
// This must be done AFTER all metrics are added to m, so everything is included.
|
||||||
|
// This allows us to use the console name for Cloud Gateways while keeping
|
||||||
|
// the actual site name ("default") for API calls.
|
||||||
|
if c.DefaultSiteNameOverride != "" {
|
||||||
|
applySiteNameOverride(m, c.DefaultSiteNameOverride)
|
||||||
|
}
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user