[influxdb] site_code tag to node

This commit is contained in:
Martin Geno 2017-02-18 23:51:24 +01:00
parent f135249795
commit 5d6f046e39
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
2 changed files with 7 additions and 0 deletions

View File

@ -31,6 +31,9 @@ func nodeToInflux(node *runtime.Node) (tags models.Tags, fields models.Fields) {
if nodeinfo := node.Nodeinfo; nodeinfo != nil { if nodeinfo := node.Nodeinfo; nodeinfo != nil {
tags.SetString("hostname", nodeinfo.Hostname) tags.SetString("hostname", nodeinfo.Hostname)
if len(nodeinfo.System.SiteCode) > 0 {
tags.SetString("site_code", nodeinfo.System.SiteCode)
}
if owner := nodeinfo.Owner; owner != nil { if owner := nodeinfo.Owner; owner != nil {
tags.SetString("owner", owner.Contact) tags.SetString("owner", owner.Contact)
} }

View File

@ -49,6 +49,9 @@ func TestToInflux(t *testing.T) {
Owner: &data.Owner{ Owner: &data.Owner{
Contact: "nobody", Contact: "nobody",
}, },
System: data.System{
SiteCode: "ffhb",
},
Wireless: &data.Wireless{ Wireless: &data.Wireless{
TxPower24: 3, TxPower24: 3,
Channel24: 4, Channel24: 4,
@ -70,6 +73,7 @@ func TestToInflux(t *testing.T) {
assert.Equal("foobar", tags.GetString("nodeid")) assert.Equal("foobar", tags.GetString("nodeid"))
assert.Equal("nobody", tags.GetString("owner")) assert.Equal("nobody", tags.GetString("owner"))
assert.Equal("ffhb", tags.GetString("site_code"))
assert.Equal(0.5, fields["load"]) assert.Equal(0.5, fields["load"])
assert.Equal(0, fields["neighbours.lldp"]) assert.Equal(0, fields["neighbours.lldp"])
assert.Equal(1, fields["neighbours.batadv"]) assert.Equal(1, fields["neighbours.batadv"])