forked from goss-org/goss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nagios.go
37 lines (31 loc) · 846 Bytes
/
nagios.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
package outputs
import (
"fmt"
"time"
"github.com/aelsabbahy/goss/resource"
)
type Nagios struct{}
func (r Nagios) Output(results <-chan []resource.TestResult, startTime time.Time) (exitCode int) {
var testCount, failed, skipped int
for resultGroup := range results {
for _, testResult := range resultGroup {
switch testResult.Result {
case resource.FAIL:
failed++
case resource.SKIP:
skipped++
}
testCount++
}
}
duration := time.Since(startTime)
if failed > 0 {
fmt.Printf("GOSS CRITICAL - Count: %d, Failed: %d, Skipped: %d, Duration: %.3fs\n", testCount, failed, skipped, duration.Seconds())
return 2
}
fmt.Printf("GOSS OK - Count: %d, Failed: %d, Skipped: %d, Duration: %.3fs\n", testCount, failed, skipped, duration.Seconds())
return 0
}
func init() {
RegisterOutputer("nagios", &Nagios{})
}