meshviewer-ffrgb output: add custom fields
This will include all configured custom fields in the meshviewer-ffrgb output under the "custom_fields" key.
This commit is contained in:
parent
1a1163aaa1
commit
70cdb53b49
|
@ -14,33 +14,34 @@ type Meshviewer struct {
|
|||
}
|
||||
|
||||
type Node struct {
|
||||
Firstseen jsontime.Time `json:"firstseen"`
|
||||
Lastseen jsontime.Time `json:"lastseen"`
|
||||
IsOnline bool `json:"is_online"`
|
||||
IsGateway bool `json:"is_gateway"`
|
||||
Clients uint32 `json:"clients"`
|
||||
ClientsWifi24 uint32 `json:"clients_wifi24"`
|
||||
ClientsWifi5 uint32 `json:"clients_wifi5"`
|
||||
ClientsOthers uint32 `json:"clients_other"`
|
||||
RootFSUsage float64 `json:"rootfs_usage"`
|
||||
LoadAverage float64 `json:"loadavg"`
|
||||
MemoryUsage *float64 `json:"memory_usage,omitempty"`
|
||||
Uptime jsontime.Time `json:"uptime,omitempty"`
|
||||
GatewayNexthop string `json:"gateway_nexthop,omitempty"`
|
||||
GatewayIPv4 string `json:"gateway,omitempty"`
|
||||
GatewayIPv6 string `json:"gateway6,omitempty"`
|
||||
NodeID string `json:"node_id"`
|
||||
MAC string `json:"mac"`
|
||||
Addresses []string `json:"addresses"`
|
||||
SiteCode string `json:"-"`
|
||||
DomainCode string `json:"domain"`
|
||||
Hostname string `json:"hostname"`
|
||||
Owner string `json:"owner,omitempty"`
|
||||
Location *Location `json:"location,omitempty"`
|
||||
Firmware Firmware `json:"firmware,omitempty"`
|
||||
Autoupdater Autoupdater `json:"autoupdater"`
|
||||
Nproc int `json:"nproc"`
|
||||
Model string `json:"model,omitempty"`
|
||||
Firstseen jsontime.Time `json:"firstseen"`
|
||||
Lastseen jsontime.Time `json:"lastseen"`
|
||||
IsOnline bool `json:"is_online"`
|
||||
IsGateway bool `json:"is_gateway"`
|
||||
Clients uint32 `json:"clients"`
|
||||
ClientsWifi24 uint32 `json:"clients_wifi24"`
|
||||
ClientsWifi5 uint32 `json:"clients_wifi5"`
|
||||
ClientsOthers uint32 `json:"clients_other"`
|
||||
RootFSUsage float64 `json:"rootfs_usage"`
|
||||
LoadAverage float64 `json:"loadavg"`
|
||||
MemoryUsage *float64 `json:"memory_usage,omitempty"`
|
||||
Uptime jsontime.Time `json:"uptime,omitempty"`
|
||||
GatewayNexthop string `json:"gateway_nexthop,omitempty"`
|
||||
GatewayIPv4 string `json:"gateway,omitempty"`
|
||||
GatewayIPv6 string `json:"gateway6,omitempty"`
|
||||
NodeID string `json:"node_id"`
|
||||
MAC string `json:"mac"`
|
||||
Addresses []string `json:"addresses"`
|
||||
SiteCode string `json:"-"`
|
||||
DomainCode string `json:"domain"`
|
||||
Hostname string `json:"hostname"`
|
||||
Owner string `json:"owner,omitempty"`
|
||||
Location *Location `json:"location,omitempty"`
|
||||
Firmware Firmware `json:"firmware,omitempty"`
|
||||
Autoupdater Autoupdater `json:"autoupdater"`
|
||||
Nproc int `json:"nproc"`
|
||||
Model string `json:"model,omitempty"`
|
||||
CustomFields map[string]interface{} `json:"custom_fields,omitempty"`
|
||||
}
|
||||
|
||||
// Firmware out of software
|
||||
|
@ -154,6 +155,12 @@ func NewNode(nodes *runtime.Nodes, n *runtime.Node) *Node {
|
|||
node.GatewayIPv6 = statistic.GatewayIPv6
|
||||
}
|
||||
}
|
||||
if customFields := n.CustomFields; customFields != nil {
|
||||
node.CustomFields = make(map[string]interface{})
|
||||
for fieldName, fieldValue := range customFields {
|
||||
node.CustomFields[fieldName] = fieldValue
|
||||
}
|
||||
}
|
||||
|
||||
// fix site to domain - if empty
|
||||
if node.DomainCode == "" {
|
||||
|
|
|
@ -58,6 +58,10 @@ func TestRegister(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
CustomFields: map[string]interface{}{
|
||||
"custom_fields": "are_custom",
|
||||
"custom_int": 3,
|
||||
},
|
||||
})
|
||||
assert.NotNil(node)
|
||||
assert.NotNil(node.Addresses)
|
||||
|
@ -66,4 +70,6 @@ func TestRegister(t *testing.T) {
|
|||
assert.Equal(13.3, node.Location.Longitude)
|
||||
assert.Equal(8.7, node.Location.Latitude)
|
||||
assert.Equal(0.74, *node.MemoryUsage)
|
||||
assert.Equal("are_custom", node.CustomFields["custom_fields"])
|
||||
assert.Equal(3, node.CustomFields["custom_int"])
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue