Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated T128_peer_path Tags #64

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 54 additions & 9 deletions plugins/inputs/t128_peer_path/t128_peer_path.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package t128_peer_path

import (
"fmt"
"time"

"github.com/influxdata/telegraf"
Expand All @@ -10,6 +11,15 @@ import (
)

const (
peerRouterKey = "peerRouter"
adjacentAddressKey = "adjacentAddress"
adjacentHostnameKey = "adjacentHostname"
nodeKey = "node"
deviceInterfaceKey = "deviceInterface"
vlanKey = "vlan"
peerPathKey = "peer-path"
routerNameKey = "routerName"

//DefaultRequestTimeout is the request timeout if none is configured
DefaultRequestTimeout = 5 * time.Second

Expand Down Expand Up @@ -153,17 +163,52 @@ func (plugin *T128PeerPath) Gather(acc telegraf.Accumulator) error {
acc.AddError(err)
}
}

for _, processedResponse := range processedResponses {
for k, v := range processedResponse.Tags {
if k == "adjacentAddress" && v == "127.117.97.105" {
delete(processedResponse.Tags, "adjacentAddress")
continue
}
if k == "adjacentHostname" && v == "" {
delete(processedResponse.Tags, "adjacentHostname")
continue
}

routerValue, exists := processedResponse.Tags[routerNameKey]
if exists {
processedResponse.Tags[peerRouterKey] = routerValue
delete(processedResponse.Tags, routerNameKey)
}

adjacentAddressValue, adjacentAddressExists := processedResponse.Tags[adjacentAddressKey]
adjacentHostnameValue, adjacentHostnameExists := processedResponse.Tags[adjacentHostnameKey]
if adjacentAddressExists && adjacentAddressValue == "127.117.97.105" {
delete(processedResponse.Tags, adjacentAddressKey)
processedResponse.Tags[peerPathKey] = fmt.Sprintf(
"%s/%s/%s/%s/%s",
processedResponse.Tags[peerRouterKey],
processedResponse.Tags[adjacentHostnameKey],
processedResponse.Tags[nodeKey],
processedResponse.Tags[deviceInterfaceKey],
processedResponse.Tags[vlanKey],
)
} else if adjacentHostnameExists && adjacentHostnameValue != "" {
processedResponse.Tags[peerPathKey] = fmt.Sprintf(
"%s/%s/%s/%s/%s/%s",
processedResponse.Tags[peerRouterKey],
processedResponse.Tags[adjacentAddressKey],
processedResponse.Tags[adjacentHostnameKey],
processedResponse.Tags[nodeKey],
processedResponse.Tags[deviceInterfaceKey],
processedResponse.Tags[vlanKey],
)
} else {
processedResponse.Tags[peerPathKey] = fmt.Sprintf(
"%s/%s/%s/%s/%s",
processedResponse.Tags[peerRouterKey],
processedResponse.Tags[adjacentAddressKey],
processedResponse.Tags[nodeKey],
processedResponse.Tags[deviceInterfaceKey],
processedResponse.Tags[vlanKey],
)
}
_, nodeExists := processedResponse.Tags[nodeKey]
if nodeExists {
delete(processedResponse.Tags, nodeKey)
}

acc.AddFields(
plugin.CollectorName,
processedResponse.Fields,
Expand Down
20 changes: 10 additions & 10 deletions plugins/inputs/t128_peer_path/t128_peer_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ var CollectorTestCases = []struct {
"adjacentAddress": "10.10.10.10",
"deviceInterface": "wan5",
"networkInterface": "wan5",
"node": "node1",
"vlan": "0",
"routerName": "NorthEast",
"peerRouter": "NorthEast",
"peer-path": "NorthEast/10.10.10.10/node1/wan5/0",
},
Fields: map[string]interface{}{
"status": "UP",
Expand Down Expand Up @@ -113,9 +113,9 @@ var CollectorTestCases = []struct {
"adjacentAddress": "10.10.10.10",
"deviceInterface": "wan5",
"networkInterface": "wan5",
"node": "node1",
"vlan": "0",
"routerName": "NorthEast",
"peerRouter": "NorthEast",
"peer-path": "NorthEast/10.10.10.10/node1/wan5/0",
},
Fields: map[string]interface{}{
"status": "UP",
Expand Down Expand Up @@ -160,9 +160,9 @@ var CollectorTestCases = []struct {
"adjacentHostname": "fake-peer",
"deviceInterface": "wan5",
"networkInterface": "wan5",
"node": "node1",
"vlan": "0",
"routerName": "NorthEast",
"peerRouter": "NorthEast",
"peer-path": "NorthEast/10.10.10.10/fake-peer/node1/wan5/0",
},
Fields: map[string]interface{}{
"status": "UP",
Expand Down Expand Up @@ -216,9 +216,9 @@ var CollectorTestCases = []struct {
"adjacentAddress": "172.16.3.2",
"deviceInterface": "wan5",
"networkInterface": "wan5",
"node": "node1",
"vlan": "0",
"routerName": "NorthEast",
"peerRouter": "NorthEast",
"peer-path": "NorthEast/172.16.3.2/node1/wan5/0",
},
Fields: map[string]interface{}{
"status": "UP",
Expand All @@ -231,9 +231,9 @@ var CollectorTestCases = []struct {
"adjacentHostname": "fake-peer",
"deviceInterface": "wan5",
"networkInterface": "wan5",
"node": "node1",
"vlan": "0",
"routerName": "NorthEast",
"peerRouter": "NorthEast",
"peer-path": "NorthEast/fake-peer/node1/wan5/0",
},
Fields: map[string]interface{}{
"status": "DOWN",
Expand Down