diff --git a/plugins/inputs/nsdp/nsdp.go b/plugins/inputs/nsdp/nsdp.go index 393e1563b..3433658cb 100644 --- a/plugins/inputs/nsdp/nsdp.go +++ b/plugins/inputs/nsdp/nsdp.go @@ -45,7 +45,7 @@ func (n *NSDP) Init() error { func (n *NSDP) Start(telegraf.Accumulator) error { conn, err := nsdp.NewConn(n.Address, n.Log.Level().Includes(telegraf.Trace)) if err != nil { - return fmt.Errorf("failed to create connection to address %s: %s", n.Address, err) + return fmt.Errorf("failed to create connection to address %s: %w", n.Address, err) } conn.ReceiveDeviceLimit = n.DeviceLimit conn.ReceiveTimeout = time.Duration(n.Timeout) @@ -84,12 +84,12 @@ func (n *NSDP) Gather(acc telegraf.Accumulator) error { // Create metrics for each responding device for device, response := range responses { n.Log.Tracef("Processing device: %s", device) - n.gatherDevice(acc, device, response) + gatherDevice(acc, device, response) } return nil } -func (n *NSDP) gatherDevice(acc telegraf.Accumulator, device string, response *nsdp.Message) { +func gatherDevice(acc telegraf.Accumulator, device string, response *nsdp.Message) { var deviceModel string var deviceName string var deviceIP net.IP diff --git a/plugins/inputs/nsdp/nsdp_test.go b/plugins/inputs/nsdp/nsdp_test.go index c027f798b..572015283 100644 --- a/plugins/inputs/nsdp/nsdp_test.go +++ b/plugins/inputs/nsdp/nsdp_test.go @@ -4,13 +4,13 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" "github.com/tdrn-org/go-nsdp" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/plugins/parsers/influx" "github.com/influxdata/telegraf/testutil" - "github.com/stretchr/testify/require" ) func TestLoadConfig(t *testing.T) { @@ -36,17 +36,48 @@ func TestInvalidTimeoutConfig(t *testing.T) { } // Verify failing Init - require.EqualError(t, plugin.Init(), "invalid Timeout value 0, must be greater 0") + require.EqualError(t, plugin.Init(), "timeout must be greater than zero") } func TestGather(t *testing.T) { // Setup and start test responder responder, err := nsdp.NewTestResponder("localhost:0") require.NoError(t, err) - defer responder.Stop() + defer responder.Stop() //nolint:errcheck // ignore error responder.AddResponses( - "0102000000000000bcd07432b8dc123456789abc000037b94e534450000000000001000847533130384576330003000773776974636832000600040a010004100000310100000000e73b5f1a000000001e31523c0000000000000000000000000000000000000000000000000000000000000000100000310200000000152d5eae0000000052ea11ea0000000000000000000000000000000000000000000000000000000000000000100000310300000000068561aa00000000bcc8cb35000000000000000000000000000000000000000000000000000000000000000010000031040000000002d5fe00000000002b37dad900000000000000000000000000000000000000000000000000000000000000001000003105000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000310600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000031070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000003108000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffff0000", - "0102000000000000bcd07432b8dccba987654321000037b94e534450000000000001000847533130384576330003000773776974636831000600040a0100031000003101000000059a9d833200000000303e8eb5000000000000000000000000000000000000000000000000000000000000000010000031020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000003103000000000d9a35e4000000026523c66600000000000000000000000000000000000000000000000000000000000000001000003104000000000041c7530000000002cd94ba000000000000000000000000000000000000000000000000000000000000000010000031050000000021b9ca41000000031a9bff610000000000000000000000000000000000000000000000000000000000000000100000310600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000031070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000003108000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffff0000") + "0102000000000000bcd07432b8dc123456789abc000037b94e53445000000000"+ + "0001000847533130384576330003000773776974636832000600040a01000410"+ + "0000310100000000e73b5f1a000000001e31523c000000000000000000000000"+ + "0000000000000000000000000000000000000000100000310200000000152d5e"+ + "ae0000000052ea11ea0000000000000000000000000000000000000000000000"+ + "000000000000000000100000310300000000068561aa00000000bcc8cb350000"+ + "0000000000000000000000000000000000000000000000000000000000001000"+ + "0031040000000002d5fe00000000002b37dad900000000000000000000000000"+ + "0000000000000000000000000000000000000010000031050000000000000000"+ + "0000000000000000000000000000000000000000000000000000000000000000"+ + "0000000000000000100000310600000000000000000000000000000000000000"+ + "0000000000000000000000000000000000000000000000000000000000100000"+ + "3107000000000000000000000000000000000000000000000000000000000000"+ + "0000000000000000000000000000000000001000003108000000000000000000"+ + "0000000000000000000000000000000000000000000000000000000000000000"+ + "00000000000000ffff0000", + "0102000000000000bcd07432b8dccba987654321000037b94e53445000000000"+ + "0001000847533130384576330003000773776974636831000600040a01000310"+ + "00003101000000059a9d833200000000303e8eb5000000000000000000000000"+ + "0000000000000000000000000000000000000000100000310200000000000000"+ + "0000000000000000000000000000000000000000000000000000000000000000"+ + "0000000000000000001000003103000000000d9a35e4000000026523c6660000"+ + "0000000000000000000000000000000000000000000000000000000000001000"+ + "003104000000000041c7530000000002cd94ba00000000000000000000000000"+ + "0000000000000000000000000000000000000010000031050000000021b9ca41"+ + "000000031a9bff61000000000000000000000000000000000000000000000000"+ + "0000000000000000100000310600000000000000000000000000000000000000"+ + "0000000000000000000000000000000000000000000000000000000000100000"+ + "3107000000000000000000000000000000000000000000000000000000000000"+ + "0000000000000000000000000000000000001000003108000000000000000000"+ + "0000000000000000000000000000000000000000000000000000000000000000"+ + "00000000000000ffff0000", + ) require.NoError(t, responder.Start()) // Setup the plugin to target the test responder