summaryrefslogtreecommitdiff
path: root/check.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-04-18 23:00:48 +0300
committerPaul Buetow <paul@buetow.org>2023-04-18 23:00:48 +0300
commit3658638e3bb3edb0f266c65fe0e42a1cd53a5f83 (patch)
tree53735108cc161bec79ebafaecc12803d636e1f3a /check.go
parent7ea496151c0336414c9563613d7c1ce87e28f4ba (diff)
use nagiosCode and other refactorings
Diffstat (limited to 'check.go')
-rw-r--r--check.go23
1 files changed, 12 insertions, 11 deletions
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)
}