From 43093196ba1f4c5f06154be0e43e3530132ff1f4 Mon Sep 17 00:00:00 2001 From: Tesifonte Belda Date: Wed, 21 Jun 2023 11:32:18 +0200 Subject: [PATCH] [bugfix] better handling no client and no responding when creating esxcli metrics --- internal/vccollector/host.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/vccollector/host.go b/internal/vccollector/host.go index 6a958ce..07a9ace 100644 --- a/internal/vccollector/host.go +++ b/internal/vccollector/host.go @@ -459,9 +459,14 @@ func (c *VcCollector) ReportHostEsxcliResponse( hsfields = make(map[string]interface{}) hostSt *hostState t time.Time + z time.Duration respondingCode int ) + if c.client == nil { + return fmt.Errorf("could not get host esxcli response: %w", govplus.ErrorNoClient) + } + t = time.Now() for i, dc := range c.dcs { for j, host := range c.hosts[i] { @@ -482,7 +487,7 @@ func (c *VcCollector) ReportHostEsxcliResponse( respondingCode = 0 if !hostSt.isHostConnected() { respondingCode = 1 - } else if !hostSt.isHostConnectedAndResponding(c.skipNotRespondigFor) { + } else if !hostSt.isHostConnectedAndResponding(z) { respondingCode = 2 } hsfields["respondingCode"] = respondingCode