From 20b368f6f793324fc6b2b5d842d4f589c90ba246 Mon Sep 17 00:00:00 2001 From: Stefan Date: Thu, 11 May 2023 21:38:10 +0200 Subject: [PATCH] Add Static Gateway Configuration --- main.go | 5 +++++ staticDevices.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ types.go | 4 ++++ 3 files changed, 56 insertions(+) create mode 100644 staticDevices.go diff --git a/main.go b/main.go index ec3803b..c7d16b7 100644 --- a/main.go +++ b/main.go @@ -95,6 +95,11 @@ func processAPIs() error { nodes = append(nodes, mvNodes...) links = append(links, mvLinks...) } + if conf.Gateways.Enabled { + log.Println("Processing Gateways") + gwNodes := processGateways() + nodes = append(nodes, gwNodes...) + } // assemble final struct o := output{ Timestamp: time.Now().Format(iso8601), diff --git a/staticDevices.go b/staticDevices.go new file mode 100644 index 0000000..ec11dbb --- /dev/null +++ b/staticDevices.go @@ -0,0 +1,47 @@ +package main + +import ( + "log" + "strings" + "time" +) + +func processGateways() []node { + d := getDevices(conf.Gateways.GatewaysURL) + var nodes []node + for i := range d.Devices { + log.Println("Processing Static Device: ", d.Devices[i].Name) + nodes = append(nodes, node{ + Firstseen: time.Now().Format(iso8601), + Lastseen: time.Now().Format(iso8601), + IsOnline: true, + IsGateway: true, + Clients: 0, + ClientsWifi24: 0, + ClientsWifi5: 0, + ClientsOther: 0, + RootFSUsage: 0, + LoadAVG: 0, + MemoryUsage: 0, + Uptime: time.Now().Format(iso8601), + GatewayNexthop: "00:00:00:00:00", + Gateway: "00:00:00:00:00", + NodeID: strings.ReplaceAll(d.Devices[i].MAC, ":", ""), + MAC: d.Devices[i].MAC, + Domain: d.Devices[i].Domain, + Hostname: "[Gateway] " + d.Devices[i].Name, + Owner: "Freifunk Troisdorf", + Firmware: firmware{ + Base: "KVM", + Release: "Ubuntu 22.04", + }, + Autoupdater: autoupdater{ + Enabled: false, + Branch: "stable", + }, + NProc: 1, + Model: "KVM", + }) + } + return nodes +} diff --git a/types.go b/types.go index 14d7281..1fdd81b 100644 --- a/types.go +++ b/types.go @@ -32,6 +32,10 @@ type config struct { URL string `json:"URL"` } `json:"files"` } `json:"meshviewer"` + Gateways struct { + Enabled bool `json:"enabled"` + GatewaysURL string `json:"gatewaysurl"` + } `json:"gateways"` } type device struct {