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

[BUG] NDM Autodisovery in datadog.yaml breaks when using ignored_ip_addresses #30181

Open
a-rhodes opened this issue Oct 16, 2024 · 0 comments
Open
Assignees

Comments

@a-rhodes
Copy link
Contributor

Agent Environment
Tested Versions: 7.57.2 & 7.57.0

Bug was introduced in 7.54.0 when network_devices.autodiscovery was added to datadog.yaml

Describe what happened:
When using the ignored_ip_addresses feature of network_devices.autodiscovery.configs, the SNMP Listener will fail to start and no network devices will be monitored.

Describe what you expected:
Expect ignored_ip_addresses to work as documented.

Steps to reproduce the issue:
Add a network_devices config to datadog.yaml:

network_devices:
  autodiscovery:
    loader: core
    configs:
      - network_address: 192.168.0.1/30
        snmp_version: 2
        port: 161
        community_string: public
        ignored_ip_addresses:
          - 192.168.0.2

No log for Configs for autodiscovery detected: Adding the snmp listener or snmp listener successfully started in agent.log

Additional environment details (Operating System, Cloud provider, etc):
Here is a PR with a unit test showing the failure: #30177
Here is a PR with a fix and a new unit test: #30180

The issue comes down to the YAML Unmarshal. It is documented that the config item ignored_ip_addresses should be a list of IPs as strings, but the struct for the config expects a map[string]bool. In the primary autodiscovery code, it calls snmp.NewListenerConfig()
https://github.com/DataDog/datadog-agent/blob/main/comp/core/autodiscovery/listeners/snmp.go#L71
Which has a special hook for converting lists to maps:
https://github.com/DataDog/datadog-agent/blob/main/pkg/snmp/snmp.go#L101-L117

But, when the agent starts and tries to add the listener, it attempts to load the config without this hook, and as such the configuration fails to load and the listener is not added. The error is also not logged, so the user has no idea why it's failing:

// Auto-activate autodiscovery without listeners: - snmp
configs := []snmplistener.Config{}
err := pkgconfigsetup.Datadog().UnmarshalKey("network_devices.autodiscovery.configs", &configs)
if err == nil && len(configs) > 0 {
detectedListeners = append(detectedListeners, pkgconfigsetup.Listeners{Name: "snmp"})
log.Info("Configs for autodiscovery detected: Adding the snmp listener")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants