From e6583918c10f189fdf9f8c7ead1372de58d85d6b Mon Sep 17 00:00:00 2001 From: Stefan Hoffmann Date: Wed, 25 Sep 2024 18:33:41 +0200 Subject: [PATCH] Fixing ghost devices in Unifi --- unifi.go | 68 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/unifi.go b/unifi.go index f00a385..3739b0e 100644 --- a/unifi.go +++ b/unifi.go @@ -133,39 +133,41 @@ func processUnifiAPI(s int) ([]node, []link, error) { // INFLUX STOP //log.Println(currentDevice.Mac) - nodes = append(nodes, node{ - Firstseen: "0", - Lastseen: time.Unix(int64(currentDevice.LastSeen), 0).Format(iso8601), - IsOnline: itob(currentDevice.State), - IsGateway: false, - Clients: clients, - ClientsWifi24: 0, - ClientsWifi5: 0, - ClientsOther: clients, - RootFSUsage: 0, - LoadAVG: load / 100, - MemoryUsage: mem / 100, - Uptime: time.Now().Add(-1 * time.Second * time.Duration(currentDevice.Uptime)).Format(iso8601), - GatewayNexthop: currentJSONDevice.GatewayNexthop, - Gateway: currentJSONDevice.Gateway, - Location: ¤tJSONDevice.Location, - NodeID: strings.ReplaceAll(currentDevice.Mac, ":", ""), - MAC: currentDevice.Mac, - Adresses: []string{currentDevice.IP}, - Domain: currentJSONDevice.Domain, - Hostname: "[Unifi] " + currentDevice.Name, - Owner: "Freifunk Rhein-Sieg", - Firmware: firmware{ - Base: "Ubiquiti - Stock", - Release: currentDevice.Version, - }, - Autoupdater: autoupdater{ - Enabled: false, - Branch: "stable", - }, - NProc: 1, - Model: model, - }) + if currentDevice.Mac != "" { + nodes = append(nodes, node{ + Firstseen: "0", + Lastseen: time.Unix(int64(currentDevice.LastSeen), 0).Format(iso8601), + IsOnline: itob(currentDevice.State), + IsGateway: false, + Clients: clients, + ClientsWifi24: 0, + ClientsWifi5: 0, + ClientsOther: clients, + RootFSUsage: 0, + LoadAVG: load / 100, + MemoryUsage: mem / 100, + Uptime: time.Now().Add(-1 * time.Second * time.Duration(currentDevice.Uptime)).Format(iso8601), + GatewayNexthop: currentJSONDevice.GatewayNexthop, + Gateway: currentJSONDevice.Gateway, + Location: ¤tJSONDevice.Location, + NodeID: strings.ReplaceAll(currentDevice.Mac, ":", ""), + MAC: currentDevice.Mac, + Adresses: []string{currentDevice.IP}, + Domain: currentJSONDevice.Domain, + Hostname: "[Unifi] " + currentDevice.Name, + Owner: "Freifunk Rhein-Sieg", + Firmware: firmware{ + Base: "Ubiquiti - Stock", + Release: currentDevice.Version, + }, + Autoupdater: autoupdater{ + Enabled: false, + Branch: "stable", + }, + NProc: 1, + Model: model, + }) + } } return nodes, links, err }