From 5b04503cf9a4a7eb1f4cf0c58698845ad8cbc561 Mon Sep 17 00:00:00 2001 From: Daniel Schauenberg Date: Wed, 9 Nov 2022 11:43:16 +0100 Subject: [PATCH] move collector initialization up in Run method all logging methods rely on the collector being initialized. When this isn't the case logging anything causes the whole app to crash with a nil pointer dereference. Specifically the datadog plugin causes unpoller to crash when it's disabled because it write a debug log on an uninitialized collector. --- integrations/datadogunifi/datadog.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/datadogunifi/datadog.go b/integrations/datadogunifi/datadog.go index e5e4e3c7..d074b0e1 100644 --- a/integrations/datadogunifi/datadog.go +++ b/integrations/datadogunifi/datadog.go @@ -190,6 +190,7 @@ func (u *DatadogUnifi) setConfigDefaults() { // Run runs a ticker to poll the unifi server and update Datadog. func (u *DatadogUnifi) Run(c poller.Collect) error { + u.Collector = c if u.Disable { u.LogDebugf("Datadog config is disabled, output is disabled.") return nil @@ -198,7 +199,6 @@ func (u *DatadogUnifi) Run(c poller.Collect) error { u.LogErrorf("DataDog config is missing and is not disabled: Datadog output is disabled!") return nil } - u.Collector = c u.Logf("Datadog is configured.") u.setConfigDefaults()