From f9fa5fe26a5be00e95190d0f0341438103338a27 Mon Sep 17 00:00:00 2001 From: Stefan Date: Tue, 19 Mar 2024 18:43:09 +0100 Subject: [PATCH] Naming changes --- main.go | 29 ++++++++++++++--------------- outages.go | 37 ------------------------------------- types.go | 2 +- unifi.go | 2 +- unms.go | 18 +++++++++--------- 5 files changed, 25 insertions(+), 63 deletions(-) delete mode 100644 outages.go diff --git a/main.go b/main.go index da8ee78..6aa0332 100644 --- a/main.go +++ b/main.go @@ -55,27 +55,30 @@ func processAPIs() error { var nodes []node var links []link - if conf.Unms.Enabled { - log.Println("Processing UNMS") - unmsNodes, unmsLinks, err := processUNMSAPI() + if conf.UISP.Enabled { + log.Println("Processing UISP") + //Process UISP RiFu Nodes + uispNodes, uispLinks, err := processUISPRiFu() if err != nil { return err } - unmsRouters, err := processUNMSAPIRouter() + //Process UISP Routers (like EDGE Router) + uispRouters, err := processUISPRouter() if err != nil { return err } - nodes = append(nodes, unmsNodes...) - nodes = append(nodes, unmsRouters...) - links = append(links, unmsLinks...) + nodes = append(nodes, uispNodes...) + nodes = append(nodes, uispRouters...) + links = append(links, uispLinks...) } if conf.Unifi.Enabled { log.Println("Processing Unifi") - ucNodes, _, err := processUcAPIs() + //Process Unifi Nodes + unifiNodes, _, err := processUnifiAPI() if err != nil { return err } - nodes = append(nodes, ucNodes...) + nodes = append(nodes, unifiNodes...) } if conf.Meshviewer.Enabled { log.Println("Processing Meshviewer") @@ -85,6 +88,7 @@ func processAPIs() error { } if conf.Gateways.Enabled { log.Println("Processing Gateways") + //Process Static Gateways from Json gwNodes := processGateways() nodes = append(nodes, gwNodes...) } @@ -101,12 +105,7 @@ func processAPIs() error { if err := o.writeToFile(); err != nil { log.Fatalln(err) } - // get outages to serve as .csv - l := getUNMSLogs() - err := writeOutagesToCSV(l) - if err != nil { - log.Println("Error writing outages.csv") - } + // we're done here log.Println("...done") return nil diff --git a/outages.go b/outages.go deleted file mode 100644 index c4a1143..0000000 --- a/outages.go +++ /dev/null @@ -1,37 +0,0 @@ -package main - -import ( - "encoding/csv" - "log" - "os" -) - -func getUNMSLogs() UNMSLogResponse { - - var l UNMSLogResponse - log.Println("Get Outages from UNMS") - err := UnmsCallAPI("/outages?count=100&page=1&type=outage", &l) - if err != nil { - log.Fatalln("Error calling Outages API") - } - return l -} - -func writeOutagesToCSV(l UNMSLogResponse) error { - csvFile, err := os.Create("output/outages.csv") - if err != nil { - return err - } - writer := csv.NewWriter(csvFile) - - for _, o := range l.Items { - var row []string - row = append(row, o.StartTime.Format("02.01.2006 15:04:05")) - row = append(row, o.EndTime.Format("02.01.2006 15:04:05")) - row = append(row, o.Site.Name) - row = append(row, o.Device.DisplayName) - writer.Write(row) - } - writer.Flush() - return nil -} diff --git a/types.go b/types.go index a63de51..4ec914a 100644 --- a/types.go +++ b/types.go @@ -16,7 +16,7 @@ type config struct { ProxmoxInfluxPort string `json:"proxmox_influx_port"` InfluxURL string `json:"influx_url"` } - Unms struct { + UISP struct { Enabled bool `json:"enabled"` UnmsAPIURL string `json:"unmsAPIUrl"` APItoken string `json:"APItoken"` diff --git a/unifi.go b/unifi.go index bb58616..9d0463b 100644 --- a/unifi.go +++ b/unifi.go @@ -15,7 +15,7 @@ import ( ) // Unifi Controller API processing -func processUcAPIs() ([]node, []link, error) { +func processUnifiAPI() ([]node, []link, error) { //get list of Unifi devices to display var nodes []node var links []link diff --git a/unms.go b/unms.go index fa6bcce..52ec7cc 100644 --- a/unms.go +++ b/unms.go @@ -17,12 +17,12 @@ import ( ) // UNMS API processing (Richtfunk) -func processUNMSAPI() ([]node, []link, error) { +func processUISPRiFu() ([]node, []link, error) { // Variables for runtime var links []link var nodes []node - d := getDevices(conf.Unms.DevicesURL) + d := getDevices(conf.UISP.DevicesURL) // API CALL 1 (get Device overview) log.Println("Starting UISP API Crawler for Rifu devices") @@ -103,10 +103,10 @@ func processUNMSAPI() ([]node, []link, error) { return nodes, links, nil } -func processUNMSAPIRouter() ([]node, error) { +func processUISPRouter() ([]node, error) { // Variables for runtime var nodes []node - d := getDevices(conf.Unms.RouterURL) + d := getDevices(conf.UISP.RouterURL) // API CALL 1, get all devices list from UNMS log.Println("Get all Routers from UISP") @@ -234,16 +234,16 @@ func processUNMSAPIRouter() ([]node, error) { } func UnmsCallAPI(url string, i any) error { - request, err := http.NewRequest(http.MethodGet, conf.Unms.UnmsAPIURL+url, nil) + request, err := http.NewRequest(http.MethodGet, conf.UISP.UnmsAPIURL+url, nil) if err != nil { - return errors.New(fmt.Sprint("can't set request", conf.Unms.UnmsAPIURL+url)) + return errors.New(fmt.Sprint("can't set request", conf.UISP.UnmsAPIURL+url)) } - log.Println(conf.Unms.UnmsAPIURL + url) - request.Header.Set("x-auth-token", conf.Unms.APItoken) + log.Println(conf.UISP.UnmsAPIURL + url) + request.Header.Set("x-auth-token", conf.UISP.APItoken) client := &http.Client{} response, err := client.Do(request) if err != nil { - return fmt.Errorf("can't get request %s with x-auth-token %s", conf.Unms.UnmsAPIURL+url, conf.Unms.APItoken) + return fmt.Errorf("can't get request %s with x-auth-token %s", conf.UISP.UnmsAPIURL+url, conf.UISP.APItoken) } if response.StatusCode != 200 { log.Fatalln("Can't call UNMS API, check token and URL. HTTP Status: ", response.StatusCode)