From 3658638e3bb3edb0f266c65fe0e42a1cd53a5f83 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 18 Apr 2023 23:00:48 +0300 Subject: use nagiosCode and other refactorings --- check.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'check.go') diff --git a/check.go b/check.go index b0db691..492bd98 100644 --- a/check.go +++ b/check.go @@ -12,10 +12,15 @@ type check struct { Args []string } +type namedCheck struct { + check + name string +} + type checkResult struct { name string output string - status int + status nagiosCode } func (c check) execute(ctx context.Context, name string) checkResult { @@ -27,11 +32,7 @@ func (c check) execute(ctx context.Context, name string) checkResult { if err := cmd.Run(); err != nil { if ctx.Err() == context.DeadlineExceeded { - return checkResult{ - name: name, - output: "Check command timed out", - status: critical, - } + return checkResult{name, "Check command timed out", critical} } } @@ -39,9 +40,9 @@ func (c check) execute(ctx context.Context, name string) checkResult { parts := strings.Split(bytes.String(), "|") output := strings.TrimSpace(parts[0]) - return checkResult{ - name: name, - output: output, - status: cmd.ProcessState.ExitCode(), - } + return checkResult{name, output, nagiosCode(cmd.ProcessState.ExitCode())} +} + +func (c namedCheck) execute(ctx context.Context) checkResult { + return c.check.execute(ctx, c.name) } -- cgit v1.2.3