[TASK] make all struct with omitempty to ref
This commit is contained in:
parent
3973e17b9b
commit
031efd69ac
|
@ -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"`
|
||||
}
|
||||
|
|
|
@ -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"`
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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,28 +101,29 @@ 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 {
|
||||
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 := stats.Traffic.Tx; t != nil {
|
||||
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 := stats.Traffic.Forward; t != nil {
|
||||
if t := tr.Forward; t != nil {
|
||||
fields["traffic.forward.bytes"] = int64(t.Bytes)
|
||||
fields["traffic.forward.packets"] = t.Packets
|
||||
}
|
||||
if t := stats.Traffic.MgmtRx; t != nil {
|
||||
if t := tr.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 {
|
||||
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 {
|
||||
suffix := airtime.FrequencyName()
|
||||
|
|
|
@ -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"`
|
||||
|
|
|
@ -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"`
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -38,10 +38,12 @@ func NewGlobalStats(nodes *Nodes) (result *GlobalStats) {
|
|||
}
|
||||
if info := node.Nodeinfo; info != nil {
|
||||
result.Models.Increment(info.Hardware.Model)
|
||||
if firmware := info.Software.Firmware; firmware != nil {
|
||||
result.Firmwares.Increment(info.Software.Firmware.Release)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
nodes.Unlock()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
|
Loading…
Reference in New Issue