Skip to content

Commit

Permalink
move
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreYang committed Nov 22, 2023
1 parent d6e22c2 commit c4b94b5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
10 changes: 0 additions & 10 deletions pkg/collector/corechecks/snmp/internal/devicecheck/devicecheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
16 changes: 15 additions & 1 deletion pkg/collector/corechecks/snmp/internal/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package fetch

import (
"fmt"
"github.com/gosnmp/gosnmp"
"strconv"

"github.com/DataDog/datadog-agent/pkg/util/log"
Expand Down Expand Up @@ -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
}
6 changes: 4 additions & 2 deletions pkg/collector/corechecks/snmp/internal/valuestore/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package valuestore
import (
"encoding/json"
"fmt"
"github.com/gosnmp/gosnmp"
"sort"

"github.com/DataDog/datadog-agent/pkg/util/log"
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c4b94b5

Please sign in to comment.