Added output of Outages from UNMS
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
ff9558c3ee
commit
3f0d6fc3d4
48
main.go
48
main.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
@ -245,19 +246,19 @@ func processAPIs() {
|
||||
var links []link
|
||||
|
||||
if conf.Unms.Enabled == true {
|
||||
fmt.Println("Processing UNMS")
|
||||
log.Println("Processing UNMS")
|
||||
unmsNodes, unmsLinks := processUNMSAPI()
|
||||
nodes = append(nodes, unmsNodes...)
|
||||
links = append(links, unmsLinks...)
|
||||
}
|
||||
if conf.Unifi.Enabled == true {
|
||||
fmt.Println("Processing Unifi")
|
||||
log.Println("Processing Unifi")
|
||||
ucNodes, ucLinks := processUcAPIs()
|
||||
nodes = append(nodes, ucNodes...)
|
||||
links = append(links, ucLinks...)
|
||||
}
|
||||
if conf.Meshviewer.Enabled == true {
|
||||
fmt.Println("Processing Meshviewer")
|
||||
log.Println("Processing Meshviewer")
|
||||
mvNodes, mvLinks := getMeshviewer()
|
||||
nodes = append(nodes, mvNodes...)
|
||||
links = append(links, mvLinks...)
|
||||
@ -275,7 +276,12 @@ func processAPIs() {
|
||||
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")
|
||||
}
|
||||
@ -283,7 +289,7 @@ func processAPIs() {
|
||||
func getFile(url string) []byte {
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
fmt.Printf("error")
|
||||
log.Println("Error getting file from:", url)
|
||||
}
|
||||
data := resp.Body
|
||||
byteValue, _ := ioutil.ReadAll(data)
|
||||
@ -608,7 +614,7 @@ func getMeshviewer() ([]node, []link) {
|
||||
var links []link
|
||||
|
||||
for i := range conf.Meshviewer.Files {
|
||||
fmt.Println("Hole Meshviewer JSON von: ", conf.Meshviewer.Files[i].URL)
|
||||
log.Println("Hole Meshviewer JSON von: ", conf.Meshviewer.Files[i].URL)
|
||||
m, err := getMeshviewerJSON(conf.Meshviewer.Files[i].URL)
|
||||
if err != nil {
|
||||
return nodes, links
|
||||
@ -619,3 +625,33 @@ func getMeshviewer() ([]node, []link) {
|
||||
}
|
||||
return nodes, links
|
||||
}
|
||||
|
||||
func getUNMSLogs() UNMSLogResponse {
|
||||
|
||||
var l UNMSLogResponse
|
||||
log.Println("Get Outages from UNMS")
|
||||
err := callUnifiAPI("/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
|
||||
}
|
||||
|
18
types.go
18
types.go
@ -283,3 +283,21 @@ func lookupModels(model string) string {
|
||||
return "Unifi Gerät"
|
||||
}
|
||||
}
|
||||
|
||||
type UNMSLogResponse struct {
|
||||
Items []struct {
|
||||
ID string `json:"id"`
|
||||
StartTime time.Time `json:"startTimestamp"`
|
||||
EndTime time.Time `json:"endTimestamp"`
|
||||
Type string `json:"type"`
|
||||
|
||||
Site struct {
|
||||
Name string `json:"name"`
|
||||
} `json:"site"`
|
||||
Device struct {
|
||||
ModelName string `json:"modelName"`
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"displayName"`
|
||||
} `json:"device"`
|
||||
} `json:"items"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user