forked from goss-org/goss
/
nagios_verbose.go
47 lines (39 loc) · 1.12 KB
/
nagios_verbose.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package outputs
import (
"fmt"
"io"
"strconv"
"time"
"github.com/aelsabbahy/goss/resource"
)
type NagiosVerbose struct{}
func (r NagiosVerbose) Output(w io.Writer, results <-chan []resource.TestResult, startTime time.Time) (exitCode int) {
var testCount, failed, skipped int
var summary map[int]string
summary = make(map[int]string)
for resultGroup := range results {
for _, testResult := range resultGroup {
switch testResult.Result {
case resource.FAIL:
summary[failed] = "Fail " + strconv.Itoa(failed+1) + " - " + humanizeResult2(testResult) + "\n"
failed++
case resource.SKIP:
skipped++
}
testCount++
}
}
duration := time.Since(startTime)
if failed > 0 {
fmt.Fprintf(w, "GOSS CRITICAL - Count: %d, Failed: %d, Skipped: %d, Duration: %.3fs\n", testCount, failed, skipped, duration.Seconds())
for i := 0; i < failed; i++ {
fmt.Fprintf(w, "%s", summary[i])
}
return 2
}
fmt.Fprintf(w, "GOSS OK - Count: %d, Failed: %d, Skipped: %d, Duration: %.3fs\n", testCount, failed, skipped, duration.Seconds())
return 0
}
func init() {
RegisterOutputer("nagios_verbose", &NagiosVerbose{})
}