Skip to content

Commit

Permalink
Merge pull request #886 from ripienaar/backport_nagios_prom_status
Browse files Browse the repository at this point in the history
Backports a fix for prometheus exit codes on 0.0.35 cli release
  • Loading branch information
ripienaar authored Sep 28, 2023
2 parents 08972cd + 703e899 commit 48df2a0
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cli/server_check_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,7 @@ func (r *result) criticalIfErr(err error, format string, a ...any) bool {
return true
}

func (r *result) exitCode() int {
if checkRenderFormat == "prometheus" {
return 0
}

func (r *result) nagiosCode() int {
switch r.Status {
case okCheckStatus:
return 0
Expand All @@ -224,6 +220,14 @@ func (r *result) exitCode() int {
}
}

func (r *result) exitCode() int {
if checkRenderFormat == "prometheus" {
return 0
}

return r.nagiosCode()
}

func (r *result) Exit() {
os.Exit(r.exitCode())
}
Expand Down Expand Up @@ -307,7 +311,7 @@ func (r *result) renderPrometheus() string {
}, []string{"item", "status"})
prometheus.MustRegister(status)

status.WithLabelValues(sname, string(r.Status)).Set(float64(r.exitCode()))
status.WithLabelValues(sname, string(r.Status)).Set(float64(r.nagiosCode()))

var buf bytes.Buffer

Expand Down

0 comments on commit 48df2a0

Please sign in to comment.