Skip to content
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.

Commit

Permalink
- Using new exit code for healthchecker for failed checks (2).
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristoffer Ahl committed Oct 5, 2018
1 parent 92b472f commit 8b87448
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions healthchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"strings"
"time"

"github.com/apex/log"
Expand Down Expand Up @@ -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,
Expand All @@ -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
}

Expand All @@ -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
Expand Down

0 comments on commit 8b87448

Please sign in to comment.