From 86e6347b06a457b30e54ac202815bfef199b7add Mon Sep 17 00:00:00 2001 From: Julian Labus Date: Sat, 11 Nov 2017 22:21:53 +0100 Subject: [PATCH] influxdb: add site_code tag to node --- database/influxdb/node.go | 3 +++ database/influxdb/node_test.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/database/influxdb/node.go b/database/influxdb/node.go index d00f558..882abcc 100644 --- a/database/influxdb/node.go +++ b/database/influxdb/node.go @@ -49,6 +49,9 @@ func (conn *Connection) InsertNode(node *runtime.Node) { if nodeinfo := node.Nodeinfo; nodeinfo != nil { tags.SetString("hostname", nodeinfo.Hostname) + if len(nodeinfo.System.SiteCode) > 0 { + tags.SetString("site_code", nodeinfo.System.SiteCode) + } if owner := nodeinfo.Owner; owner != nil { tags.SetString("owner", owner.Contact) } diff --git a/database/influxdb/node_test.go b/database/influxdb/node_test.go index 6bda061..6d6b3bc 100644 --- a/database/influxdb/node_test.go +++ b/database/influxdb/node_test.go @@ -51,6 +51,9 @@ func TestToInflux(t *testing.T) { Owner: &data.Owner{ Contact: "nobody", }, + System: &data.System{ + SiteCode: "ffhb", + }, Wireless: &data.Wireless{ TxPower24: 3, Channel24: 4, @@ -97,6 +100,7 @@ func TestToInflux(t *testing.T) { assert.EqualValues("deadbeef", tags["nodeid"]) assert.EqualValues("nobody", tags["owner"]) + assert.EqualValues("ffhb", tags["site_code"]) assert.EqualValues(0.5, fields["load"]) assert.EqualValues(0, fields["neighbours.lldp"]) assert.EqualValues(1, fields["neighbours.batadv"])