From 8b87448c7d41d17b205ef09a9a5ea86cb01afb7f Mon Sep 17 00:00:00 2001 From: Kristoffer Ahl Date: Fri, 5 Oct 2018 15:12:36 +0200 Subject: [PATCH] - Using new exit code for healthchecker for failed checks (2). --- healthchecker.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/healthchecker.go b/healthchecker.go index bb60041..3c1811b 100644 --- a/healthchecker.go +++ b/healthchecker.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "strings" "time" "github.com/apex/log" @@ -44,13 +43,13 @@ func runHealthchecks() ([]*checkSet, int) { checkSets = append(checkSets, monitor.getCheckSet()) // Output checks - success := true + exitCode := 0 for _, cs := range checkSets { for _, c := range cs.checks { topic := "gossip" lm := log.WithFields(log.Fields{ - "check": strings.Replace(c.Name, "gossip:", "", -1), + "check": c.Name, "status": c.Status, "data": c.Data, "output": c.Output, @@ -59,23 +58,21 @@ func runHealthchecks() ([]*checkSet, int) { switch c.Status { case statusSuccess: lm.Info(topic) + break case statusWarning: lm.Warn(topic) + if exitCode == 0 { + exitCode = 1 + } + break case statusFailed: lm.Error(topic) - } - - if c.Status != statusSuccess { - success = false + exitCode = 2 + break } } } - exitCode := 0 - if !success { - exitCode = 1 - } - return checkSets, exitCode } @@ -102,7 +99,7 @@ func (pm *perfMon) getCheckSet() *checkSet { check.Data = slow if len(slow) > 0 { - check.warn(fmt.Sprintf("One or more checks are performing badly (over %v).", config.EmonSlowCheckThreshold)) + check.warn(fmt.Sprintf("One or more checks are performing badly (over %v) %v.", config.EmonSlowCheckThreshold, slow)) } return cs