nodeinfo without empty values

This commit is contained in:
Geno 2021-02-17 23:35:12 +01:00 committed by genofire
parent 92dd324f5f
commit f4bad7d856
13 changed files with 86 additions and 27 deletions

View File

@ -57,27 +57,27 @@ type Location struct {
// Software struct // Software struct
type Software struct { type Software struct {
Autoupdater struct { Autoupdater *struct {
Enabled bool `json:"enabled,omitempty"` Enabled bool `json:"enabled,omitempty"`
Branch string `json:"branch,omitempty"` Branch string `json:"branch,omitempty"`
} `json:"autoupdater,omitempty"` } `json:"autoupdater,omitempty"`
BatmanAdv struct { BatmanAdv *struct {
Version string `json:"version,omitempty"` Version string `json:"version,omitempty"`
Compat int `json:"compat,omitempty"` Compat int `json:"compat,omitempty"`
} `json:"batman-adv,omitempty"` } `json:"batman-adv,omitempty"`
Babeld struct { Babeld *struct {
Version string `json:"version,omitempty"` Version string `json:"version,omitempty"`
} `json:"babeld,omitempty"` } `json:"babeld,omitempty"`
Fastd struct { Fastd *struct {
Enabled bool `json:"enabled,omitempty"` Enabled bool `json:"enabled,omitempty"`
Version string `json:"version,omitempty"` Version string `json:"version,omitempty"`
PublicKey string `json:"public_key,omitempty"` PublicKey string `json:"public_key,omitempty"`
} `json:"fastd,omitempty"` } `json:"fastd,omitempty"`
Firmware struct { Firmware *struct {
Base string `json:"base,omitempty"` Base string `json:"base,omitempty"`
Release string `json:"release,omitempty"` Release string `json:"release,omitempty"`
} `json:"firmware,omitempty"` } `json:"firmware,omitempty"`
StatusPage struct { StatusPage *struct {
API int `json:"api"` API int `json:"api"`
} `json:"status-page,omitempty"` } `json:"status-page,omitempty"`
} }

View File

@ -134,9 +134,19 @@ func createTestNodes() *runtime.Nodes {
}, },
}, },
} }
nodeData.Nodeinfo.Software.Firmware.Release = "2016.1.6+entenhausen1" nodeData.Nodeinfo.Software.Firmware = &struct {
nodeData.Nodeinfo.Software.Autoupdater.Enabled = true Base string `json:"base,omitempty"`
nodeData.Nodeinfo.Software.Autoupdater.Branch = "stable" Release string `json:"release,omitempty"`
}{
Release: "2016.1.6+entenhausen1",
}
nodeData.Nodeinfo.Software.Autoupdater = &struct {
Enabled bool `json:"enabled,omitempty"`
Branch string `json:"branch,omitempty"`
}{
Enabled: true,
Branch: "stable",
}
nodes.AddNode(nodeData) nodes.AddNode(nodeData)
nodes.AddNode(&runtime.Node{ nodes.AddNode(&runtime.Node{

View File

@ -77,9 +77,11 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
// Hardware // Hardware
tags.SetString("model", nodeinfo.Hardware.Model) tags.SetString("model", nodeinfo.Hardware.Model)
fields["nproc"] = nodeinfo.Hardware.Nproc fields["nproc"] = nodeinfo.Hardware.Nproc
if nodeinfo.Software.Firmware != nil {
tags.SetString("firmware_base", nodeinfo.Software.Firmware.Base) tags.SetString("firmware_base", nodeinfo.Software.Firmware.Base)
tags.SetString("firmware_release", nodeinfo.Software.Firmware.Release) tags.SetString("firmware_release", nodeinfo.Software.Firmware.Release)
if nodeinfo.Software.Autoupdater.Enabled { }
if nodeinfo.Software.Autoupdater != nil && nodeinfo.Software.Autoupdater.Enabled {
tags.SetString("autoupdater", nodeinfo.Software.Autoupdater.Branch) tags.SetString("autoupdater", nodeinfo.Software.Autoupdater.Branch)
} else { } else {
tags.SetString("autoupdater", runtime.DISABLED_AUTOUPDATER) tags.SetString("autoupdater", runtime.DISABLED_AUTOUPDATER)

View File

@ -68,7 +68,7 @@ func TestToInflux(t *testing.T) {
}, },
}, },
Software: data.Software{ Software: data.Software{
Autoupdater: struct { Autoupdater: &struct {
Enabled bool `json:"enabled,omitempty"` Enabled bool `json:"enabled,omitempty"`
Branch string `json:"branch,omitempty"` Branch string `json:"branch,omitempty"`
}{ }{
@ -111,12 +111,18 @@ func TestToInflux(t *testing.T) {
Mac: "BAFF1E5", Mac: "BAFF1E5",
}, },
Software: data.Software{ Software: data.Software{
Autoupdater: struct { Autoupdater: &struct {
Enabled bool `json:"enabled,omitempty"` Enabled bool `json:"enabled,omitempty"`
Branch string `json:"branch,omitempty"` Branch string `json:"branch,omitempty"`
}{ }{
Enabled: false, Enabled: false,
}, },
Firmware: &struct {
Base string `json:"base,omitempty"`
Release string `json:"release,omitempty"`
}{
Base: "gluon",
},
}, },
}, },
Statistics: &data.Statistics{ Statistics: &data.Statistics{

View File

@ -39,7 +39,7 @@ func newNodePoint(n *runtime.Node) (point *geojson.Feature) {
point.Properties["model"] = nodeinfo.Hardware.Model point.Properties["model"] = nodeinfo.Hardware.Model
description.WriteString("Model: " + nodeinfo.Hardware.Model + "\n") description.WriteString("Model: " + nodeinfo.Hardware.Model + "\n")
} }
if fw := nodeinfo.Software.Firmware; fw.Release != "" { if fw := nodeinfo.Software.Firmware; fw != nil && fw.Release != "" {
point.Properties["firmware"] = fw.Release point.Properties["firmware"] = fw.Release
description.WriteString("Firmware: " + fw.Release + "\n") description.WriteString("Firmware: " + fw.Release + "\n")
} }

View File

@ -90,7 +90,12 @@ func createTestNodes() *runtime.Nodes {
}, },
}, },
} }
nodeData.Nodeinfo.Software.Firmware.Release = "2019.1~exp42" nodeData.Nodeinfo.Software.Firmware = &struct {
Base string `json:"base,omitempty"`
Release string `json:"release,omitempty"`
}{
Release: "2019.1~exp42",
}
nodes.AddNode(nodeData) nodes.AddNode(nodeData)
nodes.AddNode(&runtime.Node{ nodes.AddNode(&runtime.Node{

View File

@ -100,10 +100,14 @@ func NewNode(nodes *runtime.Nodes, n *runtime.Node) *Node {
Latitude: location.Latitude, Latitude: location.Latitude,
} }
} }
node.Firmware = nodeinfo.Software.Firmware if nodeinfo.Software.Firmware != nil {
node.Firmware = *nodeinfo.Software.Firmware
}
if autoupdater := nodeinfo.Software.Autoupdater; autoupdater != nil {
node.Autoupdater = Autoupdater{ node.Autoupdater = Autoupdater{
Enabled: nodeinfo.Software.Autoupdater.Enabled, Enabled: autoupdater.Enabled,
Branch: nodeinfo.Software.Autoupdater.Branch, Branch: autoupdater.Branch,
}
} }
node.Nproc = nodeinfo.Hardware.Nproc node.Nproc = nodeinfo.Hardware.Nproc
node.Model = nodeinfo.Hardware.Model node.Model = nodeinfo.Hardware.Model

View File

@ -37,6 +37,16 @@ func TestRegister(t *testing.T) {
Longitude: 13.3, Longitude: 13.3,
Latitude: 8.7, Latitude: 8.7,
}, },
Software: data.Software{
Autoupdater: &struct {
Enabled bool `json:"enabled,omitempty"`
Branch string `json:"branch,omitempty"`
}{},
Firmware: &struct {
Base string `json:"base,omitempty"`
Release string `json:"release,omitempty"`
}{},
},
}, },
Statistics: &data.Statistics{ Statistics: &data.Statistics{
Memory: data.Memory{ Memory: data.Memory{

View File

@ -38,7 +38,12 @@ func createTestNodes() *runtime.Nodes {
}, },
}, },
} }
nodeData.Nodeinfo.Software.Firmware.Release = "2016.1.6+entenhausen1" nodeData.Nodeinfo.Software.Firmware = &struct {
Base string `json:"base,omitempty"`
Release string `json:"release,omitempty"`
}{
Release: "2016.1.6+entenhausen1",
}
nodes.AddNode(nodeData) nodes.AddNode(nodeData)
nodes.AddNode(&runtime.Node{ nodes.AddNode(&runtime.Node{

View File

@ -32,7 +32,12 @@ func createTestNodes() *runtime.Nodes {
}, },
}, },
} }
nodeData.Nodeinfo.Software.Firmware.Release = "2016.1.6+entenhausen1" nodeData.Nodeinfo.Software.Firmware = &struct {
Base string `json:"base,omitempty"`
Release string `json:"release,omitempty"`
}{
Release: "2016.1.6+entenhausen1",
}
nodes.AddNode(nodeData) nodes.AddNode(nodeData)
nodes.AddNode(&runtime.Node{ nodes.AddNode(&runtime.Node{

View File

@ -32,7 +32,12 @@ func createTestNodes() *runtime.Nodes {
}, },
}, },
} }
nodeData.Nodeinfo.Software.Firmware.Release = "2016.1.6+entenhausen1" nodeData.Nodeinfo.Software.Firmware = &struct {
Base string `json:"base,omitempty"`
Release string `json:"release,omitempty"`
}{
Release: "2016.1.6+entenhausen1",
}
nodes.AddNode(nodeData) nodes.AddNode(nodeData)
nodes.AddNode(&runtime.Node{ nodes.AddNode(&runtime.Node{

View File

@ -92,8 +92,10 @@ func (s *GlobalStats) Add(node *Node) {
} }
if info := node.Nodeinfo; info != nil { if info := node.Nodeinfo; info != nil {
s.Models.Increment(info.Hardware.Model) s.Models.Increment(info.Hardware.Model)
if info.Software.Firmware != nil {
s.Firmwares.Increment(info.Software.Firmware.Release) s.Firmwares.Increment(info.Software.Firmware.Release)
if info.Software.Autoupdater.Enabled { }
if info.Software.Autoupdater != nil && info.Software.Autoupdater.Enabled {
s.Autoupdater.Increment(info.Software.Autoupdater.Branch) s.Autoupdater.Increment(info.Software.Autoupdater.Branch)
} else { } else {
s.Autoupdater.Increment(DISABLED_AUTOUPDATER) s.Autoupdater.Increment(DISABLED_AUTOUPDATER)

View File

@ -94,7 +94,12 @@ func createTestNodes() *Nodes {
}, },
}, },
} }
nodeData.Nodeinfo.Software.Firmware.Release = "2016.1.6+entenhausen1" nodeData.Nodeinfo.Software.Firmware = &struct {
Base string `json:"base,omitempty"`
Release string `json:"release,omitempty"`
}{
Release: "2016.1.6+entenhausen1",
}
nodes.AddNode(nodeData) nodes.AddNode(nodeData)
nodes.AddNode(&Node{ nodes.AddNode(&Node{
@ -110,7 +115,7 @@ func createTestNodes() *Nodes {
Model: "TP-Link 841", Model: "TP-Link 841",
}, },
Software: data.Software{ Software: data.Software{
Autoupdater: struct { Autoupdater: &struct {
Enabled bool `json:"enabled,omitempty"` Enabled bool `json:"enabled,omitempty"`
Branch string `json:"branch,omitempty"` Branch string `json:"branch,omitempty"`
}{ }{