Fixing ghost devices in Unifi

This commit is contained in:
Stefan Hoffmann 2024-09-25 18:33:41 +02:00
parent ff5cf755aa
commit e6583918c1

View File

@ -133,39 +133,41 @@ func processUnifiAPI(s int) ([]node, []link, error) {
// INFLUX STOP // INFLUX STOP
//log.Println(currentDevice.Mac) //log.Println(currentDevice.Mac)
nodes = append(nodes, node{ if currentDevice.Mac != "" {
Firstseen: "0", nodes = append(nodes, node{
Lastseen: time.Unix(int64(currentDevice.LastSeen), 0).Format(iso8601), Firstseen: "0",
IsOnline: itob(currentDevice.State), Lastseen: time.Unix(int64(currentDevice.LastSeen), 0).Format(iso8601),
IsGateway: false, IsOnline: itob(currentDevice.State),
Clients: clients, IsGateway: false,
ClientsWifi24: 0, Clients: clients,
ClientsWifi5: 0, ClientsWifi24: 0,
ClientsOther: clients, ClientsWifi5: 0,
RootFSUsage: 0, ClientsOther: clients,
LoadAVG: load / 100, RootFSUsage: 0,
MemoryUsage: mem / 100, LoadAVG: load / 100,
Uptime: time.Now().Add(-1 * time.Second * time.Duration(currentDevice.Uptime)).Format(iso8601), MemoryUsage: mem / 100,
GatewayNexthop: currentJSONDevice.GatewayNexthop, Uptime: time.Now().Add(-1 * time.Second * time.Duration(currentDevice.Uptime)).Format(iso8601),
Gateway: currentJSONDevice.Gateway, GatewayNexthop: currentJSONDevice.GatewayNexthop,
Location: &currentJSONDevice.Location, Gateway: currentJSONDevice.Gateway,
NodeID: strings.ReplaceAll(currentDevice.Mac, ":", ""), Location: &currentJSONDevice.Location,
MAC: currentDevice.Mac, NodeID: strings.ReplaceAll(currentDevice.Mac, ":", ""),
Adresses: []string{currentDevice.IP}, MAC: currentDevice.Mac,
Domain: currentJSONDevice.Domain, Adresses: []string{currentDevice.IP},
Hostname: "[Unifi] " + currentDevice.Name, Domain: currentJSONDevice.Domain,
Owner: "Freifunk Rhein-Sieg", Hostname: "[Unifi] " + currentDevice.Name,
Firmware: firmware{ Owner: "Freifunk Rhein-Sieg",
Base: "Ubiquiti - Stock", Firmware: firmware{
Release: currentDevice.Version, Base: "Ubiquiti - Stock",
}, Release: currentDevice.Version,
Autoupdater: autoupdater{ },
Enabled: false, Autoupdater: autoupdater{
Branch: "stable", Enabled: false,
}, Branch: "stable",
NProc: 1, },
Model: model, NProc: 1,
}) Model: model,
})
}
} }
return nodes, links, err return nodes, links, err
} }