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 {
|
type Node struct {
|
||||||
Firstseen jsontime.Time `json:"firstseen"`
|
Firstseen jsontime.Time `json:"firstseen"`
|
||||||
Lastseen jsontime.Time `json:"lastseen"`
|
Lastseen jsontime.Time `json:"lastseen"`
|
||||||
IsOnline bool `json:"is_online"`
|
IsOnline bool `json:"is_online"`
|
||||||
IsGateway bool `json:"is_gateway"`
|
IsGateway bool `json:"is_gateway"`
|
||||||
Clients uint32 `json:"clients"`
|
Clients uint32 `json:"clients"`
|
||||||
ClientsWifi24 uint32 `json:"clients_wifi24"`
|
ClientsWifi24 uint32 `json:"clients_wifi24"`
|
||||||
ClientsWifi5 uint32 `json:"clients_wifi5"`
|
ClientsWifi5 uint32 `json:"clients_wifi5"`
|
||||||
ClientsOthers uint32 `json:"clients_other"`
|
ClientsOthers uint32 `json:"clients_other"`
|
||||||
RootFSUsage float64 `json:"rootfs_usage"`
|
RootFSUsage float64 `json:"rootfs_usage"`
|
||||||
LoadAverage float64 `json:"loadavg"`
|
LoadAverage float64 `json:"loadavg"`
|
||||||
MemoryUsage *float64 `json:"memory_usage,omitempty"`
|
MemoryUsage *float64 `json:"memory_usage,omitempty"`
|
||||||
Uptime jsontime.Time `json:"uptime,omitempty"`
|
Uptime jsontime.Time `json:"uptime,omitempty"`
|
||||||
GatewayNexthop string `json:"gateway_nexthop,omitempty"`
|
GatewayNexthop string `json:"gateway_nexthop,omitempty"`
|
||||||
GatewayIPv4 string `json:"gateway,omitempty"`
|
GatewayIPv4 string `json:"gateway,omitempty"`
|
||||||
GatewayIPv6 string `json:"gateway6,omitempty"`
|
GatewayIPv6 string `json:"gateway6,omitempty"`
|
||||||
NodeID string `json:"node_id"`
|
NodeID string `json:"node_id"`
|
||||||
MAC string `json:"mac"`
|
MAC string `json:"mac"`
|
||||||
Addresses []string `json:"addresses"`
|
Addresses []string `json:"addresses"`
|
||||||
SiteCode string `json:"-"`
|
SiteCode string `json:"-"`
|
||||||
DomainCode string `json:"domain"`
|
DomainCode string `json:"domain"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname"`
|
||||||
Owner string `json:"owner,omitempty"`
|
Owner string `json:"owner,omitempty"`
|
||||||
Location *Location `json:"location,omitempty"`
|
Location *Location `json:"location,omitempty"`
|
||||||
Firmware Firmware `json:"firmware,omitempty"`
|
Firmware Firmware `json:"firmware,omitempty"`
|
||||||
Autoupdater Autoupdater `json:"autoupdater"`
|
Autoupdater Autoupdater `json:"autoupdater"`
|
||||||
Nproc int `json:"nproc"`
|
Nproc int `json:"nproc"`
|
||||||
Model string `json:"model,omitempty"`
|
Model string `json:"model,omitempty"`
|
||||||
|
CustomFields map[string]interface{} `json:"custom_fields,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Firmware out of software
|
// Firmware out of software
|
||||||
|
@ -154,6 +155,12 @@ func NewNode(nodes *runtime.Nodes, n *runtime.Node) *Node {
|
||||||
node.GatewayIPv6 = statistic.GatewayIPv6
|
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
|
// fix site to domain - if empty
|
||||||
if node.DomainCode == "" {
|
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)
|
||||||
assert.NotNil(node.Addresses)
|
assert.NotNil(node.Addresses)
|
||||||
|
@ -66,4 +70,6 @@ func TestRegister(t *testing.T) {
|
||||||
assert.Equal(13.3, node.Location.Longitude)
|
assert.Equal(13.3, node.Location.Longitude)
|
||||||
assert.Equal(8.7, node.Location.Latitude)
|
assert.Equal(8.7, node.Location.Latitude)
|
||||||
assert.Equal(0.74, *node.MemoryUsage)
|
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