Naming changes

This commit is contained in:
Stefan Hoffmann 2024-03-19 18:43:09 +01:00
parent 73166fcedc
commit f9fa5fe26a
Signed by: stefan
GPG Key ID: 230E4E5FC468C133
5 changed files with 25 additions and 63 deletions

29
main.go
View File

@ -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

View File

@ -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
}

View File

@ -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"`

View File

@ -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

18
unms.go
View File

@ -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)