From d7439f0528b7a0252ea11715ddb493a12d61558c Mon Sep 17 00:00:00 2001 From: andersh Date: Mon, 11 Nov 2024 11:39:12 +0100 Subject: [PATCH] fix: issue #72, now return aci_up == 0 if no metrics is returned from the call assuming apic or node is down. --- aci-api.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/aci-api.go b/aci-api.go index 5fff373..49cdb9e 100644 --- a/aci-api.go +++ b/aci-api.go @@ -141,8 +141,15 @@ func (p aciAPI) CollectMetrics() (string, []MetricDefinition, error) { } end := time.Since(start) + + if metrics == nil { + // if no metrics are returned the apic or node may be down + metrics = append(metrics, *p.up(0.0)) + } else { + metrics = append(metrics, *p.up(1.0)) + } + metrics = append(metrics, *p.scrape(end.Seconds())) - metrics = append(metrics, *p.up(1.0)) log.WithFields(log.Fields{ LogFieldRequestID: p.ctx.Value(LogFieldRequestID), LogFieldExecTime: end.Microseconds(),