Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NDM] Fix for ignored_ip_addresses in autodiscovery #30180

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)
}
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.
Loading