raw output: add custom fields

This will include all configured custom fields in the raw output
under the "custom_fields" key.
This commit is contained in:
nrbffs 2019-11-17 14:55:26 +01:00 committed by genofire
parent 70cdb53b49
commit 9a70560cfb
1 changed files with 14 additions and 12 deletions

View File

@ -8,12 +8,13 @@ import (
// Node struct // Node struct
type RawNode struct { type RawNode struct {
Firstseen jsontime.Time `json:"firstseen"` Firstseen jsontime.Time `json:"firstseen"`
Lastseen jsontime.Time `json:"lastseen"` Lastseen jsontime.Time `json:"lastseen"`
Online bool `json:"online"` Online bool `json:"online"`
Statistics *data.Statistics `json:"statistics"` Statistics *data.Statistics `json:"statistics"`
Nodeinfo *data.Nodeinfo `json:"nodeinfo"` Nodeinfo *data.Nodeinfo `json:"nodeinfo"`
Neighbours *data.Neighbours `json:"neighbours"` Neighbours *data.Neighbours `json:"neighbours"`
CustomFields map[string]interface{} `json:"custom_fields"`
} }
type NodeList struct { type NodeList struct {
@ -31,12 +32,13 @@ func transform(nodes *runtime.Nodes) *NodeList {
for _, nodeOrigin := range nodes.List { for _, nodeOrigin := range nodes.List {
if nodeOrigin != nil { if nodeOrigin != nil {
node := &RawNode{ node := &RawNode{
Firstseen: nodeOrigin.Firstseen, Firstseen: nodeOrigin.Firstseen,
Lastseen: nodeOrigin.Lastseen, Lastseen: nodeOrigin.Lastseen,
Online: nodeOrigin.Online, Online: nodeOrigin.Online,
Statistics: nodeOrigin.Statistics, Statistics: nodeOrigin.Statistics,
Nodeinfo: nodeOrigin.Nodeinfo, Nodeinfo: nodeOrigin.Nodeinfo,
Neighbours: nodeOrigin.Neighbours, Neighbours: nodeOrigin.Neighbours,
CustomFields: nodeOrigin.CustomFields,
} }
nodelist.List = append(nodelist.List, node) nodelist.List = append(nodelist.List, node)
} }