[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
|
// 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"`
|
||||||
Fastd struct {
|
Fastd *struct {
|
||||||
Enabled bool `json:"enabled,omitempty"`
|
Enabled bool `json:"enabled,omitempty"`
|
||||||
Version string `json:"version,omitempty"`
|
Version string `json:"version,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"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ type Statistics struct {
|
||||||
Running uint32 `json:"running"`
|
Running uint32 `json:"running"`
|
||||||
} `json:"processes,omitempty"`
|
} `json:"processes,omitempty"`
|
||||||
MeshVPN *MeshVPN `json:"mesh_vpn,omitempty"`
|
MeshVPN *MeshVPN `json:"mesh_vpn,omitempty"`
|
||||||
Traffic struct {
|
Traffic *struct {
|
||||||
Tx *Traffic `json:"tx"`
|
Tx *Traffic `json:"tx"`
|
||||||
Rx *Traffic `json:"rx"`
|
Rx *Traffic `json:"rx"`
|
||||||
Forward *Traffic `json:"forward"`
|
Forward *Traffic `json:"forward"`
|
||||||
|
|
|
@ -24,7 +24,7 @@ func createTestNodes() *runtime.Nodes {
|
||||||
|
|
||||||
nodeData := &data.ResponseData{
|
nodeData := &data.ResponseData{
|
||||||
Statistics: &data.Statistics{
|
Statistics: &data.Statistics{
|
||||||
Clients: data.Clients{
|
Clients: &data.Clients{
|
||||||
Total: 23,
|
Total: 23,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -32,6 +32,12 @@ func createTestNodes() *runtime.Nodes {
|
||||||
Hardware: data.Hardware{
|
Hardware: data.Hardware{
|
||||||
Model: "TP-Link 841",
|
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"
|
nodeData.NodeInfo.Software.Firmware.Release = "2016.1.6+entenhausen1"
|
||||||
|
@ -39,7 +45,7 @@ func createTestNodes() *runtime.Nodes {
|
||||||
|
|
||||||
nodes.Update("112233445566", &data.ResponseData{
|
nodes.Update("112233445566", &data.ResponseData{
|
||||||
Statistics: &data.Statistics{
|
Statistics: &data.Statistics{
|
||||||
Clients: data.Clients{
|
Clients: &data.Clients{
|
||||||
Total: 2,
|
Total: 2,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -63,8 +63,10 @@ func buildNodeStats(node *runtime.Node) (tags models.Tags, fields models.Fields)
|
||||||
}
|
}
|
||||||
// Hardware
|
// Hardware
|
||||||
tags.SetString("model", nodeinfo.Hardware.Model)
|
tags.SetString("model", nodeinfo.Hardware.Model)
|
||||||
tags.SetString("firmware_base", nodeinfo.Software.Firmware.Base)
|
if firmware := nodeinfo.Software.Firmware; firmware != nil {
|
||||||
tags.SetString("firmware_release", nodeinfo.Software.Firmware.Release)
|
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
|
// total is the sum of all protocols
|
||||||
fields["neighbours.total"] = batadv + lldp
|
fields["neighbours.total"] = batadv + lldp
|
||||||
}
|
}
|
||||||
|
if tr := stats.Traffic; tr != nil {
|
||||||
if t := stats.Traffic.Rx; t != nil {
|
if t := tr.Rx; t != nil {
|
||||||
fields["traffic.rx.bytes"] = int64(t.Bytes)
|
fields["traffic.rx.bytes"] = int64(t.Bytes)
|
||||||
fields["traffic.rx.packets"] = t.Packets
|
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.bytes"] = int64(t.Bytes)
|
||||||
fields["traffic.tx.packets"] = t.Packets
|
fields["traffic.tx.packets"] = t.Packets
|
||||||
fields["traffic.tx.dropped"] = t.Dropped
|
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.bytes"] = int64(t.Bytes)
|
||||||
fields["traffic.forward.packets"] = t.Packets
|
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.bytes"] = int64(t.Bytes)
|
||||||
fields["traffic.mgmt_rx.packets"] = t.Packets
|
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.bytes"] = int64(t.Bytes)
|
||||||
fields["traffic.mgmt_tx.packets"] = t.Packets
|
fields["traffic.mgmt_tx.packets"] = t.Packets
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, airtime := range stats.Wireless {
|
for _, airtime := range stats.Wireless {
|
||||||
suffix := airtime.FrequencyName()
|
suffix := airtime.FrequencyName()
|
||||||
|
|
|
@ -19,7 +19,7 @@ func TestToInflux(t *testing.T) {
|
||||||
Wireless: data.WirelessStatistics{
|
Wireless: data.WirelessStatistics{
|
||||||
&data.WirelessAirtime{Frequency: 5500},
|
&data.WirelessAirtime{Frequency: 5500},
|
||||||
},
|
},
|
||||||
Traffic: struct {
|
Traffic: &struct {
|
||||||
Tx *data.Traffic `json:"tx"`
|
Tx *data.Traffic `json:"tx"`
|
||||||
Rx *data.Traffic `json:"rx"`
|
Rx *data.Traffic `json:"rx"`
|
||||||
Forward *data.Traffic `json:"forward"`
|
Forward *data.Traffic `json:"forward"`
|
||||||
|
|
|
@ -37,7 +37,7 @@ type Statistics struct {
|
||||||
Running uint32 `json:"running"`
|
Running uint32 `json:"running"`
|
||||||
} `json:"processes,omitempty"`
|
} `json:"processes,omitempty"`
|
||||||
MeshVPN *data.MeshVPN `json:"mesh_vpn,omitempty"`
|
MeshVPN *data.MeshVPN `json:"mesh_vpn,omitempty"`
|
||||||
Traffic struct {
|
Traffic *struct {
|
||||||
Tx *data.Traffic `json:"tx"`
|
Tx *data.Traffic `json:"tx"`
|
||||||
Rx *data.Traffic `json:"rx"`
|
Rx *data.Traffic `json:"rx"`
|
||||||
Forward *data.Traffic `json:"forward"`
|
Forward *data.Traffic `json:"forward"`
|
||||||
|
|
|
@ -27,7 +27,7 @@ func createTestNodes() *runtime.Nodes {
|
||||||
|
|
||||||
nodeData := &data.ResponseData{
|
nodeData := &data.ResponseData{
|
||||||
Statistics: &data.Statistics{
|
Statistics: &data.Statistics{
|
||||||
Clients: data.Clients{
|
Clients: &data.Clients{
|
||||||
Total: 23,
|
Total: 23,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -35,6 +35,12 @@ func createTestNodes() *runtime.Nodes {
|
||||||
Hardware: data.Hardware{
|
Hardware: data.Hardware{
|
||||||
Model: "TP-Link 841",
|
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"
|
nodeData.NodeInfo.Software.Firmware.Release = "2016.1.6+entenhausen1"
|
||||||
|
@ -42,7 +48,7 @@ func createTestNodes() *runtime.Nodes {
|
||||||
|
|
||||||
nodes.Update("112233445566", &data.ResponseData{
|
nodes.Update("112233445566", &data.ResponseData{
|
||||||
Statistics: &data.Statistics{
|
Statistics: &data.Statistics{
|
||||||
Clients: data.Clients{
|
Clients: &data.Clients{
|
||||||
Total: 2,
|
Total: 2,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -38,10 +38,12 @@ func NewGlobalStats(nodes *Nodes) (result *GlobalStats) {
|
||||||
}
|
}
|
||||||
if info := node.Nodeinfo; info != nil {
|
if info := node.Nodeinfo; info != nil {
|
||||||
result.Models.Increment(info.Hardware.Model)
|
result.Models.Increment(info.Hardware.Model)
|
||||||
|
if firmware := info.Software.Firmware; firmware != nil {
|
||||||
result.Firmwares.Increment(info.Software.Firmware.Release)
|
result.Firmwares.Increment(info.Software.Firmware.Release)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
nodes.Unlock()
|
nodes.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,9 +39,17 @@ func createTestNodes() *Nodes {
|
||||||
Hardware: data.Hardware{
|
Hardware: data.Hardware{
|
||||||
Model: "TP-Link 841",
|
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("abcdef012345", nodeData)
|
||||||
|
|
||||||
nodes.Update("112233445566", &data.ResponseData{
|
nodes.Update("112233445566", &data.ResponseData{
|
||||||
|
|
Loading…
Reference in New Issue