diff --git a/plugins/processors/snmp_lookup/lookup.go b/plugins/processors/snmp_lookup/lookup.go index ed852ca22..486457974 100644 --- a/plugins/processors/snmp_lookup/lookup.go +++ b/plugins/processors/snmp_lookup/lookup.go @@ -126,25 +126,25 @@ func (l *Lookup) Add(m telegraf.Metric, acc telegraf.Accumulator) error { // Default update function func (l *Lookup) updateAgent(agent string) *tagMap { + tm := &tagMap{created: time.Now()} + // Initialize connection to agent conn, err := l.getConnectionFunc(agent) if err != nil { l.Log.Errorf("Getting connection for %q failed: %v", agent, err) - return nil + return tm } // Query table including translation table, err := l.table.Build(conn, true) if err != nil { l.Log.Errorf("Building table for %q failed: %v", agent, err) - return nil + return tm } // Copy tags for all rows - tm := &tagMap{ - created: table.Time, - rows: make(tagMapRows, len(table.Rows)), - } + tm.created = table.Time + tm.rows = make(tagMapRows, len(table.Rows)) for _, row := range table.Rows { index := row.Tags["index"] delete(row.Tags, "index") diff --git a/plugins/processors/snmp_lookup/lookup_test.go b/plugins/processors/snmp_lookup/lookup_test.go index c8cb4ae50..b4ab67e33 100644 --- a/plugins/processors/snmp_lookup/lookup_test.go +++ b/plugins/processors/snmp_lookup/lookup_test.go @@ -231,7 +231,12 @@ func TestUpdateAgent(t *testing.T) { t.Run("table build fail", func(t *testing.T) { tsc = &testSNMPConnection{} - require.Nil(t, p.updateAgent("127.0.0.1")) + start := time.Now() + tm := p.updateAgent("127.0.0.1") + end := time.Now() + + require.Nil(t, tm.rows) + require.WithinRange(t, tm.created, start, end) require.EqualValues(t, 1, tsc.calls.Load()) }) @@ -240,7 +245,12 @@ func TestUpdateAgent(t *testing.T) { return nil, errors.New("Random connection error") } - require.Nil(t, p.updateAgent("127.0.0.1")) + start := time.Now() + tm := p.updateAgent("127.0.0.1") + end := time.Now() + + require.Nil(t, tm.rows) + require.WithinRange(t, tm.created, start, end) }) }