Skip to content

Commit

Permalink
add device_scan_max_oids_per_run
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreYang committed Nov 23, 2023
1 parent 7f19817 commit 8e336c8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
16 changes: 15 additions & 1 deletion pkg/collector/corechecks/snmp/internal/checkconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const defaultDiscoveryWorkers = 5
const defaultDiscoveryAllowedFailures = 3
const defaultDiscoveryInterval = 3600
const defaultDetectMetricsRefreshInterval = 3600
const defaultDeviceScanMaxOidsPerRun = 1000

// subnetTagKey is the prefix used for subnet tag
const subnetTagKey = "autodiscovery_subnet"
Expand Down Expand Up @@ -79,6 +80,7 @@ type InitConfig struct {
DetectMetricsEnabled Boolean `yaml:"experimental_detect_metrics_enabled"`
DetectMetricsRefreshInterval int `yaml:"experimental_detect_metrics_refresh_interval"`
DeviceScanEnabled Boolean `yaml:"device_scan_enabled"`
DeviceScanMaxOidsPerRun int `yaml:"device_scan_max_oids_per_run"`
}

// InstanceConfig is used to deserialize integration instance config
Expand Down Expand Up @@ -138,7 +140,8 @@ type InstanceConfig struct {
DetectMetricsEnabled *Boolean `yaml:"experimental_detect_metrics_enabled"`
DetectMetricsRefreshInterval int `yaml:"experimental_detect_metrics_refresh_interval"`

DeviceScanEnabled *Boolean `yaml:"device_scan_enabled"`
DeviceScanEnabled *Boolean `yaml:"device_scan_enabled"`
DeviceScanMaxOidsPerRun int `yaml:"device_scan_max_oids_per_run"`

// `interface_configs` option is not supported by SNMP corecheck autodiscovery (`network_address`)
// it's only supported for single device instance (`ip_address`)
Expand Down Expand Up @@ -192,6 +195,7 @@ type CheckConfig struct {
DetectMetricsRefreshInterval int

DeviceScanEnabled bool
DeviceScanMaxOidsPerRun int
DeviceScanLastOid string
DeviceScanCurScanStart time.Time
DeviceScanCurScanOidsCount int
Expand Down Expand Up @@ -391,6 +395,15 @@ func NewCheckConfig(rawInstance integration.Data, rawInitConfig integration.Data
c.DeviceScanEnabled = bool(initConfig.DeviceScanEnabled)
}

// TODO: TEST ME
if instance.DeviceScanMaxOidsPerRun != 0 {
c.DeviceScanMaxOidsPerRun = int(instance.DeviceScanMaxOidsPerRun)
} else if initConfig.DeviceScanMaxOidsPerRun != 0 {
c.DeviceScanMaxOidsPerRun = int(initConfig.DeviceScanMaxOidsPerRun)
} else {
c.DeviceScanMaxOidsPerRun = defaultDeviceScanMaxOidsPerRun
}

if instance.DetectMetricsRefreshInterval != 0 {
c.DetectMetricsRefreshInterval = int(instance.DetectMetricsRefreshInterval)
} else if initConfig.DetectMetricsRefreshInterval != 0 {
Expand Down Expand Up @@ -660,6 +673,7 @@ func (c *CheckConfig) Copy() *CheckConfig {
newConfig.DetectMetricsEnabled = c.DetectMetricsEnabled
newConfig.DetectMetricsRefreshInterval = c.DetectMetricsRefreshInterval
newConfig.DeviceScanEnabled = c.DeviceScanEnabled
newConfig.DeviceScanMaxOidsPerRun = c.DeviceScanMaxOidsPerRun
newConfig.MinCollectionInterval = c.MinCollectionInterval
newConfig.InterfaceConfigs = c.InterfaceConfigs

Expand Down
5 changes: 2 additions & 3 deletions pkg/collector/corechecks/snmp/internal/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ func getDeviceScanValues(sess session.Session, config *checkconfig.CheckConfig)
config.DeviceScanCurScanOidsCount = 0
}

maxOidsToFetch := 100 // TODO: Update to 1000 (?)
fetchStart := time.Now()
fetchedResults, lastOid, err := session.FetchAllOIDsUsingGetNext(sess, rootOid, maxOidsToFetch)
fetchedResults, lastOid, err := session.FetchAllOIDsUsingGetNext(sess, rootOid, config.DeviceScanMaxOidsPerRun)
if err != nil {
log.Warnf("[FetchAllOIDsUsingGetNext] error: %s", err)
return nil
Expand All @@ -95,7 +94,7 @@ func getDeviceScanValues(sess session.Session, config *checkconfig.CheckConfig)
config.DeviceScanCurScanOidsCount += len(fetchedResults)

// TODO: ADD TELEMETRY for each check run
if len(fetchedResults) == maxOidsToFetch {
if len(fetchedResults) == config.DeviceScanMaxOidsPerRun {
log.Warnf("[FetchAllOIDsUsingGetNext] Partial Device Scan (Total Count: %d, Fetch Duration Ms: %d)",
config.DeviceScanCurScanOidsCount,
fetchDuration.Milliseconds(),
Expand Down

0 comments on commit 8e336c8

Please sign in to comment.