Skip to content

Commit

Permalink
[NDM] Fix for ignored_ip_addresses in autodiscovery (#30180)
Browse files Browse the repository at this point in the history
Co-authored-by: Lénaïc Huard <[email protected]>
  • Loading branch information
a-rhodes and L3n41c authored Oct 23, 2024
1 parent 0b8caf8 commit 6c03220
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
7 changes: 4 additions & 3 deletions pkg/config/autodiscovery/autodiscovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ func DiscoverComponentsFromConfig() ([]pkgconfigsetup.ConfigurationProviders, []
}

// Auto-activate autodiscovery without listeners: - snmp
configs := []snmplistener.Config{}
err := pkgconfigsetup.Datadog().UnmarshalKey("network_devices.autodiscovery.configs", &configs)
snmpConfig, err := snmplistener.NewListenerConfig()

if err == nil && len(configs) > 0 {
if err != nil {
log.Errorf("Error unmarshalling snmp listener config. Error: %v", err)
} else if len(snmpConfig.Configs) > 0 {
detectedListeners = append(detectedListeners, pkgconfigsetup.Listeners{Name: "snmp"})
log.Info("Configs for autodiscovery detected: Adding the snmp listener")
}
Expand Down
19 changes: 17 additions & 2 deletions pkg/config/autodiscovery/autodiscovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup"
)
Expand All @@ -25,7 +26,7 @@ network_devices:
`))
assert.NoError(t, err)
_, configListeners := DiscoverComponentsFromConfig()
assert.Len(t, configListeners, 1)
require.Len(t, configListeners, 1)
assert.Equal(t, "snmp", configListeners[0].Name)

err = pkgconfigsetup.Datadog().ReadConfig(strings.NewReader(`
Expand All @@ -44,5 +45,19 @@ snmp_listener:
`))
assert.NoError(t, err)
_, configListeners = DiscoverComponentsFromConfig()
assert.Empty(t, len(configListeners))
require.Len(t, configListeners, 1)
assert.Equal(t, "snmp", configListeners[0].Name)

err = pkgconfigsetup.Datadog().ReadConfig(strings.NewReader(`
network_devices:
autodiscovery:
configs:
- network_address: 127.0.0.1/30
ignored_ip_addresses:
- 127.0.0.3
`))
assert.NoError(t, err)
_, configListeners = DiscoverComponentsFromConfig()
require.Len(t, configListeners, 1)
assert.Equal(t, "snmp", configListeners[0].Name)
}
11 changes: 11 additions & 0 deletions releasenotes/notes/fix-config-autodiscovery-49d61b77e8f76f58.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Each section from every release note are combined when the
# CHANGELOG.rst is rendered. So the text needs to be worded so that
# it does not depend on any information only available in another
# section. This may mean repeating some details, but each section
# must be readable independently of the other.
#
# Each section note must be formatted as reStructuredText.
---
fixes:
- |
Fix a bug in the config parser that broke ignored_ip_addresses from working in NDM Autodiscovery.

0 comments on commit 6c03220

Please sign in to comment.