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
type Software struct {
Autoupdater struct {
Autoupdater *struct {
Enabled bool `json:"enabled,omitempty"`
Branch string `json:"branch,omitempty"`
} `json:"autoupdater,omitempty"`
BatmanAdv struct {
BatmanAdv *struct {
Version string `json:"version,omitempty"`
Compat int `json:"compat,omitempty"`
} `json:"batman-adv,omitempty"`
Babeld struct {
Babeld *struct {
Version string `json:"version,omitempty"`
} `json:"babeld,omitempty"`
Fastd struct {
Fastd *struct {
Enabled bool `json:"enabled,omitempty"`
Version string `json:"version,omitempty"`
PublicKey string `json:"public_key,omitempty"`
} `json:"fastd,omitempty"`
Firmware struct {
Firmware *struct {
Base string `json:"base,omitempty"`
Release string `json:"release,omitempty"`
} `json:"firmware,omitempty"`
StatusPage struct {
StatusPage *struct {
API int `json:"api"`
} `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.Autoupdater.Enabled = true
nodeData.Nodeinfo.Software.Autoupdater.Branch = "stable"
nodeData.Nodeinfo.Software.Firmware = &struct {
Base string `json:"base,omitempty"`
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(&runtime.Node{

View File

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

View File

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

View File

@ -39,7 +39,7 @@ func newNodePoint(n *runtime.Node) (point *geojson.Feature) {
point.Properties["model"] = nodeinfo.Hardware.Model
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
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(&runtime.Node{

View File

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

View File

@ -37,6 +37,16 @@ func TestRegister(t *testing.T) {
Longitude: 13.3,
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{
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(&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(&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(&runtime.Node{

View File

@ -92,8 +92,10 @@ func (s *GlobalStats) Add(node *Node) {
}
if info := node.Nodeinfo; info != nil {
s.Models.Increment(info.Hardware.Model)
s.Firmwares.Increment(info.Software.Firmware.Release)
if info.Software.Autoupdater.Enabled {
if info.Software.Firmware != nil {
s.Firmwares.Increment(info.Software.Firmware.Release)
}
if info.Software.Autoupdater != nil && info.Software.Autoupdater.Enabled {
s.Autoupdater.Increment(info.Software.Autoupdater.Branch)
} else {
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(&Node{
@ -110,7 +115,7 @@ func createTestNodes() *Nodes {
Model: "TP-Link 841",
},
Software: data.Software{
Autoupdater: struct {
Autoupdater: &struct {
Enabled bool `json:"enabled,omitempty"`
Branch string `json:"branch,omitempty"`
}{