diff --git a/pkg/collector/corechecks/snmp/internal/devicecheck/devicecheck.go b/pkg/collector/corechecks/snmp/internal/devicecheck/devicecheck.go index 822e5aa7e5a85..0123f2c6423ae 100644 --- a/pkg/collector/corechecks/snmp/internal/devicecheck/devicecheck.go +++ b/pkg/collector/corechecks/snmp/internal/devicecheck/devicecheck.go @@ -230,16 +230,6 @@ func (d *DeviceCheck) getValuesAndTags() (bool, []string, *valuestore.ResultValu } func (d *DeviceCheck) detectMetricsToMonitor(sess session.Session) error { - if d.config.DeviceScanEnabled { - results, err := session.FetchAllOIDsUsingGetNext(d.session) - if err != nil { - log.Warnf("[FetchAllOIDsUsingGetNext] error: %s", err) - } - log.Warnf("[FetchAllOIDsUsingGetNext] PRINT PDUs (len: %d)", len(results)) - for _, resultPdu := range results { - log.Warnf("[FetchAllOIDsUsingGetNext] PDU: %+v", resultPdu) - } - } if d.config.DetectMetricsEnabled { if d.nextAutodetectMetrics.After(timeNow()) { diff --git a/pkg/collector/corechecks/snmp/internal/fetch/fetch.go b/pkg/collector/corechecks/snmp/internal/fetch/fetch.go index 900123dc80b38..497b54d667d36 100644 --- a/pkg/collector/corechecks/snmp/internal/fetch/fetch.go +++ b/pkg/collector/corechecks/snmp/internal/fetch/fetch.go @@ -7,6 +7,7 @@ package fetch import ( "fmt" + "github.com/gosnmp/gosnmp" "strconv" "github.com/DataDog/datadog-agent/pkg/util/log" @@ -59,5 +60,18 @@ func Fetch(sess session.Session, config *checkconfig.CheckConfig) (*valuestore.R } } - return &valuestore.ResultValueStore{ScalarValues: scalarResults, ColumnValues: columnResults}, nil + var results []gosnmp.SnmpPDU + if config.DeviceScanEnabled { + fetchedResults, err := session.FetchAllOIDsUsingGetNext(sess) + if err != nil { + log.Warnf("[FetchAllOIDsUsingGetNext] error: %s", err) + } + log.Warnf("[FetchAllOIDsUsingGetNext] PRINT PDUs (len: %d)", len(results)) + for _, resultPdu := range fetchedResults { + log.Warnf("[FetchAllOIDsUsingGetNext] PDU: %+v", resultPdu) + } + results = fetchedResults + } + + return &valuestore.ResultValueStore{ScalarValues: scalarResults, ColumnValues: columnResults, DeviceScanValues: results}, nil } diff --git a/pkg/collector/corechecks/snmp/internal/valuestore/values.go b/pkg/collector/corechecks/snmp/internal/valuestore/values.go index 45dc45df2d8aa..7b2e2285cdf75 100644 --- a/pkg/collector/corechecks/snmp/internal/valuestore/values.go +++ b/pkg/collector/corechecks/snmp/internal/valuestore/values.go @@ -8,6 +8,7 @@ package valuestore import ( "encoding/json" "fmt" + "github.com/gosnmp/gosnmp" "sort" "github.com/DataDog/datadog-agent/pkg/util/log" @@ -27,8 +28,9 @@ type ScalarResultValuesType map[string]ResultValue // ResultValueStore store OID values type ResultValueStore struct { // TODO: make fields private + use a constructor instead - ScalarValues ScalarResultValuesType `json:"scalar_values"` - ColumnValues ColumnResultValuesType `json:"column_values"` + ScalarValues ScalarResultValuesType `json:"scalar_values"` + ColumnValues ColumnResultValuesType `json:"column_values"` + DeviceScanValues []gosnmp.SnmpPDU } // GetScalarValue look for oid in ResultValueStore and returns the value and boolean diff --git a/pkg/collector/corechecks/snmp/internal/valuestore/values_test.go b/pkg/collector/corechecks/snmp/internal/valuestore/values_test.go index 3feef1e408628..f927ac643d84f 100644 --- a/pkg/collector/corechecks/snmp/internal/valuestore/values_test.go +++ b/pkg/collector/corechecks/snmp/internal/valuestore/values_test.go @@ -61,7 +61,7 @@ func TestResultValueStoreAsString(t *testing.T) { }, } str := ResultValueStoreAsString(store) - assert.Equal(t, "{\"scalar_values\":{\"1.1.1.1.0\":{\"value\":10}},\"column_values\":{\"1.1.1\":{\"1\":{\"value\":10}}}}", str) + assert.Equal(t, "{\"scalar_values\":{\"1.1.1.1.0\":{\"value\":10}},\"column_values\":{\"1.1.1\":{\"1\":{\"value\":10}}},\"DeviceScanValues\":null}", str) str = ResultValueStoreAsString(nil) assert.Equal(t, "", str)