Skip to content

Commit a2749fc

Browse files
committed
fix check_process when empty-state is set to OK
1 parent b3f02d5 commit a2749fc

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ issues:
126126
- "cyclomatic complexity .* of func .*.matchSingle"
127127
- "Function 'ParseINI' has too many statements"
128128
- "Function 'buildListMacros' has too many statements"
129+
- "Function 'finalizeOutput' has too many statements"
129130
- "cognitive complexity .* of func .*ParseINI`"
130131
- "cognitive complexity .* of func .*ThresholdString"
131132
- "appendAssign: append result not assigned to the same slice"

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ This file documents the revision history for the SNClient+ agent.
22

33
next:
44
- add alpine support
5+
- fix check_process when empty-state is set to OK
56

67
0.31 Wed Feb 12 18:14:54 CET 2025
78
- fix check_files thresholds on total_size

pkg/snclient/check_process_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ func TestCheckProcess(t *testing.T) {
3131
assert.Equalf(t, "OK - no processes found with this filter. |'count'=0;0;0;0 'rss'=0B;;;0 'virtual'=0B;;;0 'cpu'=0%;;;0",
3232
string(res.BuildPluginOutput()), "output matches")
3333

34+
res = snc.RunCheck("check_process", []string{"process=noneexisting.exe", "empty-state=0"})
35+
assert.Equalf(t, CheckExitOK, res.State, "state ok")
36+
assert.Equalf(t, "OK - no processes found with this filter. |'count'=0;0;0;0 'rss'=0B;;;0 'virtual'=0B;;;0 'cpu'=0%;;;0",
37+
string(res.BuildPluginOutput()), "output matches")
38+
3439
res = snc.RunCheck("check_process", []string{"process=noneexisting.exe", "crit=count>0", "warn=none"})
3540
assert.Equalf(t, CheckExitOK, res.State, "state ok")
3641
assert.Regexpf(t, `OK - no processes found with this filter.`, string(res.BuildPluginOutput()), "output ok")

pkg/snclient/checkdata.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ type CheckData struct {
9696
hasArgsFilter bool // will be true if any arg supplied which has isFilter set
9797
emptySyntax string
9898
emptyState int64
99+
emptyStateSet bool
99100
details map[string]string
100101
listData []map[string]string
101102
listCombine string // join string for detail list
@@ -201,7 +202,8 @@ func (cd *CheckData) finalizeOutput() (*CheckResult, error) {
201202
if cd.emptySyntax != "" {
202203
cd.result.Output = cd.emptySyntax
203204
}
204-
if !cd.HasThreshold("count") {
205+
if cd.emptyStateSet || !cd.HasThreshold("count") {
206+
log.Debugf("exit code set by empty state: %d", cd.emptyState)
205207
cd.result.State = cd.emptyState
206208
}
207209
case cd.showAll:
@@ -609,6 +611,7 @@ func (cd *CheckData) ParseArgs(args []string) (argList []Argument, err error) {
609611
cd.emptySyntax = argValue
610612
case "empty-state":
611613
cd.emptyState = cd.parseStateString(argValue)
614+
cd.emptyStateSet = true
612615
case "show-all":
613616
if argValue == "" {
614617
cd.showAll = true

0 commit comments

Comments
 (0)