Skip to content

Commit

Permalink
fix(inputs.cisco_telemetry_mdt): Handle NXOS DME subtree telemetry fo…
Browse files Browse the repository at this point in the history
…rmat (#15923)
  • Loading branch information
yusufshalaby authored Oct 2, 2024
1 parent f42104f commit 2268175
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 2 deletions.
10 changes: 8 additions & 2 deletions plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,13 +624,19 @@ func (c *CiscoTelemetryMDT) parseClassAttributeField(grouper *metric.SeriesGroup
}
nxAttributes = field.Fields[0].Fields[0].Fields[0].Fields[0]

// Find dn tag among list of attributes
for _, subfield := range nxAttributes.Fields {
if subfield.Name == "dn" {
tags["dn"] = decodeTag(subfield)
} else {
c.parseContentField(grouper, subfield, "", encodingPath, tags, timestamp)
break
}
}
// Add attributes to grouper with consistent dn tag
for _, subfield := range nxAttributes.Fields {
c.parseContentField(grouper, subfield, "", encodingPath, tags, timestamp)
}
// Delete dn tag to prevent it from being added to the next node's attributes
delete(tags, "dn")
}

func (c *CiscoTelemetryMDT) getMeasurementName(encodingPath string) string {
Expand Down
140 changes: 140 additions & 0 deletions plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,146 @@ func TestHandleNXDME(t *testing.T) {
fields1 := map[string]interface{}{"value": "foo"}
acc.AssertContainsTaggedFields(t, "dme", fields1, tags1)
}
func TestHandleNXDMESubtree(t *testing.T) {
c := &CiscoTelemetryMDT{
Transport: "dummy",
Aliases: map[string]string{"dme": "sys/dme"},
}
acc := &testutil.Accumulator{}
err := c.Start(acc)
// error is expected since we are passing in dummy transport
require.Error(t, err)

telemetry := &telemetryBis.Telemetry{
MsgTimestamp: 1543236572000,
EncodingPath: "sys/dme",
NodeId: &telemetryBis.Telemetry_NodeIdStr{NodeIdStr: "hostname"},
Subscription: &telemetryBis.Telemetry_SubscriptionIdStr{SubscriptionIdStr: "subscription"},
DataGpbkv: []*telemetryBis.TelemetryField{
{
Fields: []*telemetryBis.TelemetryField{
{
Name: "keys",
Fields: []*telemetryBis.TelemetryField{
{
Name: "sys/dme",
ValueByType: &telemetryBis.TelemetryField_StringValue{StringValue: "sys/dme"},
},
},
},
{
Name: "content",
Fields: []*telemetryBis.TelemetryField{
{
Fields: []*telemetryBis.TelemetryField{
{
Name: "children",
Fields: []*telemetryBis.TelemetryField{
{
Fields: []*telemetryBis.TelemetryField{
{
Name: "fooEntity",
Fields: []*telemetryBis.TelemetryField{
{
Fields: []*telemetryBis.TelemetryField{
{
Name: "attributes",
Fields: []*telemetryBis.TelemetryField{
{
Fields: []*telemetryBis.TelemetryField{
{
Name: "foo",
ValueByType: &telemetryBis.TelemetryField_StringValue{
StringValue: "bar1",
},
},
{
Name: "dn",
ValueByType: &telemetryBis.TelemetryField_StringValue{
StringValue: "eth1/1",
},
},
},
},
},
},
},
},
},
},
},
},
{
Fields: []*telemetryBis.TelemetryField{
{
Name: "fooEntity",
Fields: []*telemetryBis.TelemetryField{
{
Fields: []*telemetryBis.TelemetryField{
{
Name: "attributes",
Fields: []*telemetryBis.TelemetryField{
{
Fields: []*telemetryBis.TelemetryField{
{
Name: "foo",
ValueByType: &telemetryBis.TelemetryField_StringValue{
StringValue: "bar2",
},
},
{
Name: "dn",
ValueByType: &telemetryBis.TelemetryField_StringValue{
StringValue: "eth1/2",
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
}}
data, err := proto.Marshal(telemetry)
require.NoError(t, err)

c.handleTelemetry(data)
require.Empty(t, acc.Errors)

require.Len(t, acc.Metrics, 2)

tags1 := map[string]string{
"dn": "eth1/1",
"path": "sys/dme",
"source": "hostname",
"subscription": "subscription",
"sys/dme": "sys/dme",
}
fields1 := map[string]interface{}{"foo": "bar1", "dn": "eth1/1"}
acc.AssertContainsTaggedFields(t, "dme", fields1, tags1)

tags2 := map[string]string{
"dn": "eth1/2",
"path": "sys/dme",
"source": "hostname",
"subscription": "subscription",
"sys/dme": "sys/dme",
}
fields2 := map[string]interface{}{"foo": "bar2", "dn": "eth1/2"}
acc.AssertContainsTaggedFields(t, "dme", fields2, tags2)
}

func TestTCPDialoutOverflow(t *testing.T) {
c := &CiscoTelemetryMDT{
Expand Down

0 comments on commit 2268175

Please sign in to comment.