From d1a807840c517473b38f8657bbc748d303cfceb7 Mon Sep 17 00:00:00 2001 From: Stefan Lengauer Date: Wed, 4 Mar 2020 14:49:59 +0100 Subject: [PATCH] Fix cs collector crashing when running on a domain joined machine The wmi lib does some type checking for nil values. Use a pointer as a workaround for that. --- collector/cs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/collector/cs.go b/collector/cs.go index 352ac3653..f545b7012 100644 --- a/collector/cs.go +++ b/collector/cs.go @@ -67,7 +67,7 @@ type Win32_ComputerSystem struct { TotalPhysicalMemory uint64 DNSHostname string Domain string - Workgroup string + Workgroup *string } func (c *CSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { @@ -93,7 +93,7 @@ func (c *CSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, er ) var fqdn string - if dst[0].Domain != dst[0].Workgroup { + if dst[0].Workgroup == nil || dst[0].Domain != *dst[0].Workgroup { fqdn = dst[0].DNSHostname + "." + dst[0].Domain } else { fqdn = dst[0].DNSHostname