Skip to content

Commit 0766379

Browse files
authored
Correction of return code
Previous version fails to exit with the correct return code (1 for WARNING, 2 for CRITICAL ...). The new version fixes that point. Note that i've proposed a patch to the author of NSClient++ which also corrects the problem. (see : mickem/nscp#560 ). If the patch to NSClient++ is accepted, we should roll back to previous version.
1 parent 8e6b622 commit 0766379

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

check_nsc_web.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type ResultLine struct {
7474
type QueryV1 struct {
7575
Command string `json:"command"`
7676
Lines []ResultLine `json:"lines"`
77-
Result string `json:"result"`
77+
Result int `json:"result"`
7878
}
7979

8080
type QueryLeg struct {
@@ -95,12 +95,20 @@ type QueryLeg struct {
9595
} `json:"payload"`
9696
}
9797

98+
var ReturncodeMap = map[string]int{
99+
"OK": 0,
100+
"WARNING": 1,
101+
"CRITICAL": 2,
102+
"UNKNOWN": 3,
103+
}
104+
98105
func (q QueryLeg) toV1() *QueryV1 {
99106
qV1 := new(QueryV1)
100107
if len(q.Payload) == 0 {
101108
return qV1
102109
}
103110
qV1.Command = q.Payload[0].Command
111+
qV1.Result = ReturncodeMap[q.Payload[0].Result]
104112
qV1.Lines = make([]ResultLine, len(q.Payload[0].Lines))
105113
for i, v := range(q.Payload[0].Lines) {
106114
qV1.Lines[i].Perf = make(map[string]PerfLine)
@@ -148,12 +156,6 @@ func main() {
148156
flag.IntVar(&flagFloatround, "f", -1, "Round performance data float values to this number of digits.")
149157
flag.StringVar(&flagExtratext, "x", "", "Extra text to appear in output.")
150158

151-
ReturncodeMap := map[string]int{
152-
"OK": 0,
153-
"WARNING": 1,
154-
"CRITICAL": 2,
155-
"UNKNOWN": 3,
156-
}
157159

158160
flag.Parse()
159161
if flagVersion {
@@ -336,7 +338,7 @@ func main() {
336338
} else {
337339
fmt.Println(nagiosMessage + "|" + strings.TrimSpace(nagiosPerfdata.String()))
338340
}
339-
os.Exit(ReturncodeMap[queryResult.Result])
341+
os.Exit(queryResult.Result)
340342
}
341343

342344
}

0 commit comments

Comments
 (0)