Tidy things up

This commit is contained in:
Stefan Hoffmann 2023-04-28 15:20:42 +02:00
parent 926153b8e7
commit 16dd56e320
Signed by: stefan
GPG Key ID: 8EFC7042BF8D5CDD
3 changed files with 9 additions and 12 deletions

View File

@ -77,11 +77,8 @@ func processAPIs() {
} }
if conf.Unifi.Enabled { if conf.Unifi.Enabled {
log.Println("Processing Unifi") log.Println("Processing Unifi")
//ucNodes, ucLinks := processUcAPIs()
ucNodes, _ := processUcAPIs() ucNodes, _ := processUcAPIs()
nodes = append(nodes, ucNodes...) nodes = append(nodes, ucNodes...)
//links = append(links, ucLinks...)
//links = links
} }
if conf.Meshviewer.Enabled { if conf.Meshviewer.Enabled {
log.Println("Processing Meshviewer") log.Println("Processing Meshviewer")
@ -113,6 +110,7 @@ func processAPIs() {
} }
} }
// function to get file from meshviewer
func getFile(url string) []byte { func getFile(url string) []byte {
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {

View File

@ -2,7 +2,6 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt"
"log" "log"
) )
@ -17,7 +16,7 @@ func getMeshviewerJSON(url string) (mvDevices, error) {
// unmarshal to struct // unmarshal to struct
err := json.Unmarshal(jsonFile, &n) err := json.Unmarshal(jsonFile, &n)
if err != nil { if err != nil {
fmt.Println("can´t get Meshviewer Json file from " + url) log.Println("can´t get Meshviewer Json file from " + url)
log.Println(err) log.Println(err)
} }
return n, nil return n, nil

View File

@ -12,7 +12,7 @@ import (
"time" "time"
) )
//Unifi Controller API processing // Unifi Controller API processing
func processUcAPIs() ([]node, []link) { func processUcAPIs() ([]node, []link) {
//get list of Unifi devices to display //get list of Unifi devices to display
var nodes []node var nodes []node
@ -26,12 +26,12 @@ func processUcAPIs() ([]node, []link) {
//get all Sites from Controller //get all Sites from Controller
sites, err := ucAPI.ucGetSites() sites, err := ucAPI.ucGetSites()
if err != nil { if err != nil {
log.Fatalln(err) log.Println(err)
} }
//get all devices in all sites //get all devices in all sites
devices, err := ucAPI.ucGetDevices(sites) devices, err := ucAPI.ucGetDevices(sites)
if err != nil { if err != nil {
log.Fatalln(err) log.Println(err)
} }
//build nodes struct //build nodes struct
@ -40,7 +40,7 @@ func processUcAPIs() ([]node, []link) {
var currentDevice ucDevice var currentDevice ucDevice
var currentJSONDevice device var currentJSONDevice device
for _, device := range devices { for _, device := range devices {
if strings.ToUpper(device.Mac) == strings.ToUpper(jsonDevice.MAC) { if strings.EqualFold(device.Mac, jsonDevice.MAC) {
currentDevice = device currentDevice = device
currentJSONDevice = jsonDevice currentJSONDevice = jsonDevice
} }
@ -63,9 +63,9 @@ func processUcAPIs() ([]node, []link) {
load = 0 load = 0
} }
var model = lookupModels(currentDevice.Model) var model = lookupModels(currentDevice.Model)
var clients = currentDevice.Users var clients int
if conf.Unifi.DisplayUsers == false { if conf.Unifi.DisplayUsers {
clients = 0 clients = currentDevice.Users
} }
nodes = append(nodes, node{ nodes = append(nodes, node{
Firstseen: "0", Firstseen: "0",