diff --git a/pkg/config/autodiscovery/autodiscovery.go b/pkg/config/autodiscovery/autodiscovery.go index c1fab80232a55..e0feabf9968ff 100644 --- a/pkg/config/autodiscovery/autodiscovery.go +++ b/pkg/config/autodiscovery/autodiscovery.go @@ -9,6 +9,8 @@ package autodiscovery import ( + "errors" + "github.com/DataDog/datadog-agent/comp/core/autodiscovery/providers" "github.com/DataDog/datadog-agent/comp/core/autodiscovery/providers/names" "github.com/DataDog/datadog-agent/pkg/config/env" @@ -77,7 +79,7 @@ func DiscoverComponentsFromConfig() ([]pkgconfigsetup.ConfigurationProviders, [] // Auto-activate autodiscovery without listeners: - snmp snmpConfig, err := snmplistener.NewListenerConfig() - if err != nil { + if err != nil && !errors.Is(err, snmplistener.ErrNoConfigGiven) { log.Errorf("Error unmarshalling snmp listener config. Error: %v", err) } else if len(snmpConfig.Configs) > 0 { detectedListeners = append(detectedListeners, pkgconfigsetup.Listeners{Name: "snmp"}) diff --git a/pkg/snmp/snmp.go b/pkg/snmp/snmp.go index 8e63ad76a6d3e..db35905dbabf5 100644 --- a/pkg/snmp/snmp.go +++ b/pkg/snmp/snmp.go @@ -95,6 +95,9 @@ type intOrBoolPtr interface { *int | *bool } +// ErrNoConfigGiven is returned when the SNMP listener config was not found +var ErrNoConfigGiven = errors.New("no config given for snmp_listener") + // NewListenerConfig parses configuration and returns a built ListenerConfig func NewListenerConfig() (ListenerConfig, error) { var snmpConfig ListenerConfig @@ -114,7 +117,7 @@ func NewListenerConfig() (ListenerConfig, error) { return snmpConfig, err } } else { - return snmpConfig, errors.New("no config given for snmp_listener") + return snmpConfig, ErrNoConfigGiven } if snmpConfig.AllowedFailures == 0 && snmpConfig.AllowedFailuresLegacy != 0 {