nodeinfo without empty values
This commit is contained in:
parent
92dd324f5f
commit
f4bad7d856
|
@ -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"`
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"`
|
||||
}{
|
||||
|
|
Loading…
Reference in New Issue