From 4b6b2e5120cac9cd21ca545efb072a5fa8c0092f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Mathieu?= Date: Fri, 29 Nov 2019 14:56:24 +0100 Subject: [PATCH] inventories: expvar could not be published if the feature is disabled (#4529) The expvar is also not published immediately at startup, it was also a bug if the status was called early in the Agent startup. --- pkg/status/status.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/status/status.go b/pkg/status/status.go index 42a0bbc61e15c5..70de77ec7f94dc 100644 --- a/pkg/status/status.go +++ b/pkg/status/status.go @@ -319,9 +319,12 @@ func expvarStats(stats map[string]interface{}) (map[string]interface{}, error) { stats["ntpOffset"], err = strconv.ParseFloat(expvar.Get("ntpOffset").String(), 64) } - inventoriesStatsJSON := []byte(expvar.Get("inventories").String()) - inventoriesStats := make(map[string]interface{}) - json.Unmarshal(inventoriesStatsJSON, &inventoriesStats) + inventories := expvar.Get("inventories") + var inventoriesStats map[string]interface{} + if inventories != nil { + inventoriesStatsJSON := []byte(inventories.String()) + json.Unmarshal(inventoriesStatsJSON, &inventoriesStats) + } checkMetadata := map[string]map[string]string{} if data, ok := inventoriesStats["check_metadata"]; ok {