145 lines
3.7 KiB
Go
145 lines
3.7 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
type device struct {
|
|
Name string `json:"name"`
|
|
MAC string `json:"mac"`
|
|
GatewayNexthop string `json:"gateway_nexthop"`
|
|
Gateway string `json:"gateway"`
|
|
Domain string `json:"domain"`
|
|
Location struct {
|
|
Longitude float64 `json:"longitude"`
|
|
Latitude float64 `json:"latitude"`
|
|
} `json:"location"`
|
|
}
|
|
type devices struct {
|
|
Devices []device `json:"devices"`
|
|
}
|
|
|
|
type unifiAPIResponse struct {
|
|
Identification struct {
|
|
ID string `json:"id"`
|
|
MAC string `json:"mac"`
|
|
Started time.Time `json:"started"`
|
|
} `json:"identification"`
|
|
Overview struct {
|
|
LastSeen time.Time `json:"lastSeen"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
Status string `json:"status"`
|
|
} `json:"overview"`
|
|
}
|
|
|
|
type unifiAPIDetails struct {
|
|
Identification struct {
|
|
Name string `json:"name"`
|
|
Model string `json:"model"`
|
|
} `json:"identification"`
|
|
Firmware struct {
|
|
Current string `json:"current"`
|
|
} `json:"firmware"`
|
|
Overview struct {
|
|
CPU float64 `json:"cpu"`
|
|
RAM float64 `json:"ram"`
|
|
} `json:"overview"`
|
|
IPAddress string `json:"ipAddress"`
|
|
}
|
|
|
|
type unifiAPIAirmax struct {
|
|
DeviceIdentification struct {
|
|
MAC string `json:"mac"`
|
|
} `json:"deviceidentification"`
|
|
Statistics struct {
|
|
LinkScore float64 `json:"linkScore"`
|
|
} `json:"statistics"`
|
|
}
|
|
|
|
type link struct {
|
|
Type string `json:"type"`
|
|
Source string `json:"source"`
|
|
Target string `json:"target"`
|
|
SourceTQ float64 `json:"source_tq"`
|
|
TargetTQ float64 `json:"target_tq"`
|
|
SourceAddr string `json:"source_addr"`
|
|
TargetAddr string `json:"target_addr"`
|
|
}
|
|
|
|
type node struct {
|
|
Firstseen string `json:"firstseen"`
|
|
Lastseen string `json:"lastseen"`
|
|
IsOnline bool `json:"is_online"`
|
|
IsGateway bool `json:"is_gateway"`
|
|
Clients int `json:"clients"`
|
|
ClientsWifi24 int `json:"clients_wifi24"`
|
|
ClientsWifi5 int `json:"clients_wifi5"`
|
|
ClientsOther int `json:"clients_other"`
|
|
RootFSUsage int `json:"rootfs_usage"`
|
|
LoadAVG float64 `json:"loadavg"`
|
|
MemoryUsage float64 `json:"memory_usage"`
|
|
Uptime string `json:"uptime"`
|
|
GatewayNexthop string `json:"gateway_nexthop"`
|
|
Gateway string `json:"gateway"`
|
|
Location struct {
|
|
Longitude float64 `json:"longitude"`
|
|
Latitude float64 `json:"latitude"`
|
|
} `json:"location"`
|
|
NodeID string `json:"node_id"`
|
|
MAC string `json:"mac"`
|
|
Adresses []string `json:"addresses"`
|
|
Domain string `json:"domain"`
|
|
Hostname string `json:"hostname"`
|
|
Owner string `json:"owner"`
|
|
Firmware firmware `json:"firmware"`
|
|
Autoupdater autoupdater `json:"autoupdater"`
|
|
NProc int `json:"nproc"`
|
|
Model string `json:"model"`
|
|
}
|
|
|
|
type firmware struct {
|
|
Base string `json:"base"`
|
|
Release string `json:"release"`
|
|
}
|
|
|
|
type autoupdater struct {
|
|
Enabled bool `json:"enabled"`
|
|
Branch string `json:"branch"`
|
|
}
|
|
|
|
type output struct {
|
|
Timestamp string `json:"timestamp"`
|
|
Nodes []node `json:"nodes"`
|
|
Links []link `json:"links"`
|
|
}
|
|
|
|
func (o *output) writeToFile() error {
|
|
file, err := json.MarshalIndent(o, "", " ")
|
|
if err != nil {
|
|
return fmt.Errorf("can't marshal to json: %+v", o)
|
|
}
|
|
|
|
// write to file
|
|
if _, err := os.Stat("output"); os.IsNotExist(err) {
|
|
err = os.Mkdir("output", 0755)
|
|
if err != nil {
|
|
return fmt.Errorf("can't create output folder")
|
|
}
|
|
}
|
|
err = ioutil.WriteFile("output/meshviewer.json", file, 0644)
|
|
if err != nil {
|
|
return fmt.Errorf("can't write to json file meshviewer.json")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type apiResponse struct {
|
|
StatusCode int `json:"statusCode"`
|
|
Error string `json:"error"`
|
|
Message string `json:"message"`
|
|
}
|