diff --git a/data/nodeinfo.go b/data/nodeinfo.go index 8a3b96f..ed936bc 100644 --- a/data/nodeinfo.go +++ b/data/nodeinfo.go @@ -50,23 +50,23 @@ 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"` - Fastd struct { + Fastd *struct { Enabled bool `json:"enabled,omitempty"` Version string `json:"version,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"` } diff --git a/data/statistics.go b/data/statistics.go index 916e23b..71a9fab 100644 --- a/data/statistics.go +++ b/data/statistics.go @@ -22,7 +22,7 @@ type Statistics struct { Running uint32 `json:"running"` } `json:"processes,omitempty"` MeshVPN *MeshVPN `json:"mesh_vpn,omitempty"` - Traffic struct { + Traffic *struct { Tx *Traffic `json:"tx"` Rx *Traffic `json:"rx"` Forward *Traffic `json:"forward"` diff --git a/database/influxdb/global_test.go b/database/influxdb/global_test.go index 946c134..f107ec3 100644 --- a/database/influxdb/global_test.go +++ b/database/influxdb/global_test.go @@ -24,7 +24,7 @@ func createTestNodes() *runtime.Nodes { nodeData := &data.ResponseData{ Statistics: &data.Statistics{ - Clients: data.Clients{ + Clients: &data.Clients{ Total: 23, }, }, @@ -32,6 +32,12 @@ func createTestNodes() *runtime.Nodes { Hardware: data.Hardware{ Model: "TP-Link 841", }, + Software: data.Software{ + Firmware: &struct { + Base string `json:"base,omitempty"` + Release string `json:"release,omitempty"` + }{}, + }, }, } nodeData.NodeInfo.Software.Firmware.Release = "2016.1.6+entenhausen1" @@ -39,7 +45,7 @@ func createTestNodes() *runtime.Nodes { nodes.Update("112233445566", &data.ResponseData{ Statistics: &data.Statistics{ - Clients: data.Clients{ + Clients: &data.Clients{ Total: 2, }, }, diff --git a/database/influxdb/node.go b/database/influxdb/node.go index 098b080..6cede03 100644 --- a/database/influxdb/node.go +++ b/database/influxdb/node.go @@ -63,8 +63,10 @@ func buildNodeStats(node *runtime.Node) (tags models.Tags, fields models.Fields) } // Hardware tags.SetString("model", nodeinfo.Hardware.Model) - tags.SetString("firmware_base", nodeinfo.Software.Firmware.Base) - tags.SetString("firmware_release", nodeinfo.Software.Firmware.Release) + if firmware := nodeinfo.Software.Firmware; firmware != nil { + tags.SetString("firmware_base", firmware.Base) + tags.SetString("firmware_release", firmware.Release) + } } @@ -99,27 +101,28 @@ func buildNodeStats(node *runtime.Node) (tags models.Tags, fields models.Fields) // total is the sum of all protocols fields["neighbours.total"] = batadv + lldp } - - if t := stats.Traffic.Rx; t != nil { - fields["traffic.rx.bytes"] = int64(t.Bytes) - fields["traffic.rx.packets"] = t.Packets - } - if t := stats.Traffic.Tx; t != nil { - fields["traffic.tx.bytes"] = int64(t.Bytes) - fields["traffic.tx.packets"] = t.Packets - fields["traffic.tx.dropped"] = t.Dropped - } - if t := stats.Traffic.Forward; t != nil { - fields["traffic.forward.bytes"] = int64(t.Bytes) - fields["traffic.forward.packets"] = t.Packets - } - if t := stats.Traffic.MgmtRx; t != nil { - fields["traffic.mgmt_rx.bytes"] = int64(t.Bytes) - fields["traffic.mgmt_rx.packets"] = t.Packets - } - if t := stats.Traffic.MgmtTx; t != nil { - fields["traffic.mgmt_tx.bytes"] = int64(t.Bytes) - fields["traffic.mgmt_tx.packets"] = t.Packets + if tr := stats.Traffic; tr != nil { + if t := tr.Rx; t != nil { + fields["traffic.rx.bytes"] = int64(t.Bytes) + fields["traffic.rx.packets"] = t.Packets + } + if t := tr.Tx; t != nil { + fields["traffic.tx.bytes"] = int64(t.Bytes) + fields["traffic.tx.packets"] = t.Packets + fields["traffic.tx.dropped"] = t.Dropped + } + if t := tr.Forward; t != nil { + fields["traffic.forward.bytes"] = int64(t.Bytes) + fields["traffic.forward.packets"] = t.Packets + } + if t := tr.MgmtRx; t != nil { + fields["traffic.mgmt_rx.bytes"] = int64(t.Bytes) + fields["traffic.mgmt_rx.packets"] = t.Packets + } + if t := tr.MgmtTx; t != nil { + fields["traffic.mgmt_tx.bytes"] = int64(t.Bytes) + fields["traffic.mgmt_tx.packets"] = t.Packets + } } for _, airtime := range stats.Wireless { diff --git a/database/influxdb/node_test.go b/database/influxdb/node_test.go index 3fa7f32..8516d0a 100644 --- a/database/influxdb/node_test.go +++ b/database/influxdb/node_test.go @@ -19,7 +19,7 @@ func TestToInflux(t *testing.T) { Wireless: data.WirelessStatistics{ &data.WirelessAirtime{Frequency: 5500}, }, - Traffic: struct { + Traffic: &struct { Tx *data.Traffic `json:"tx"` Rx *data.Traffic `json:"rx"` Forward *data.Traffic `json:"forward"` diff --git a/meshviewer/node.go b/meshviewer/node.go index 3e88166..18f0905 100644 --- a/meshviewer/node.go +++ b/meshviewer/node.go @@ -37,7 +37,7 @@ type Statistics struct { Running uint32 `json:"running"` } `json:"processes,omitempty"` MeshVPN *data.MeshVPN `json:"mesh_vpn,omitempty"` - Traffic struct { + Traffic *struct { Tx *data.Traffic `json:"tx"` Rx *data.Traffic `json:"rx"` Forward *data.Traffic `json:"forward"` diff --git a/meshviewer/nodes_test.go b/meshviewer/nodes_test.go index bd08d5e..01f681e 100644 --- a/meshviewer/nodes_test.go +++ b/meshviewer/nodes_test.go @@ -27,7 +27,7 @@ func createTestNodes() *runtime.Nodes { nodeData := &data.ResponseData{ Statistics: &data.Statistics{ - Clients: data.Clients{ + Clients: &data.Clients{ Total: 23, }, }, @@ -35,6 +35,12 @@ func createTestNodes() *runtime.Nodes { Hardware: data.Hardware{ Model: "TP-Link 841", }, + Software: data.Software{ + Firmware: &struct { + Base string `json:"base,omitempty"` + Release string `json:"release,omitempty"` + }{}, + }, }, } nodeData.NodeInfo.Software.Firmware.Release = "2016.1.6+entenhausen1" @@ -42,7 +48,7 @@ func createTestNodes() *runtime.Nodes { nodes.Update("112233445566", &data.ResponseData{ Statistics: &data.Statistics{ - Clients: data.Clients{ + Clients: &data.Clients{ Total: 2, }, }, diff --git a/runtime/stats.go b/runtime/stats.go index c50df78..63115b1 100644 --- a/runtime/stats.go +++ b/runtime/stats.go @@ -38,7 +38,9 @@ func NewGlobalStats(nodes *Nodes) (result *GlobalStats) { } if info := node.Nodeinfo; info != nil { result.Models.Increment(info.Hardware.Model) - result.Firmwares.Increment(info.Software.Firmware.Release) + if firmware := info.Software.Firmware; firmware != nil { + result.Firmwares.Increment(info.Software.Firmware.Release) + } } } } diff --git a/runtime/stats_test.go b/runtime/stats_test.go index b742b66..8143f1f 100644 --- a/runtime/stats_test.go +++ b/runtime/stats_test.go @@ -39,9 +39,17 @@ func createTestNodes() *Nodes { Hardware: data.Hardware{ Model: "TP-Link 841", }, + Software: data.Software{ + Firmware: &struct { + Base string `json:"base,omitempty"` + Release string `json:"release,omitempty"` + }{ + Base: "2016.1.6", + Release: "2016.1.6+entenhausen1", + }, + }, }, } - nodeData.NodeInfo.Software.Firmware.Release = "2016.1.6+entenhausen1" nodes.Update("abcdef012345", nodeData) nodes.Update("112233445566", &data.ResponseData{