Skip to content

Commit 037b5de

Browse files
committed
check_process: make process filter is case insensitive
1 parent 7d645a4 commit 037b5de

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ next:
66
- change like operator to be case insensitive
77
- add new slike operator which is case sensitive
88
- add support for str() operator
9+
- check_process: make process filter is case insensitive
910

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

docs/checks/commands/check_process.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ Naemon Config
7272

7373
## Check Specific Arguments
7474

75-
| Argument | Description |
76-
| -------- | ---------------------------------------------------------- |
77-
| process | The process to check, set to \* to check all. Default: \* |
78-
| timezone | Sets the timezone for time metrics (default is local time) |
75+
| Argument | Description |
76+
| -------- | ---------------------------------------------------------------------------- |
77+
| process | The process to check, set to \* to check all. (Case insensitive) Default: \* |
78+
| timezone | Sets the timezone for time metrics (default is local time) |
7979

8080
## Attributes
8181

pkg/snclient/check_process.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"runtime"
7+
"strings"
78

89
"github.com/consol-monitoring/snclient/pkg/convert"
910
)
@@ -33,7 +34,7 @@ func (l *CheckProcess) Build() *CheckData {
3334
State: CheckExitOK,
3435
},
3536
args: map[string]CheckArgument{
36-
"process": {value: &l.processes, description: "The process to check, set to * to check all. Default: *", isFilter: true},
37+
"process": {value: &l.processes, description: "The process to check, set to * to check all. (Case insensitive) Default: *", isFilter: true},
3738
"timezone": {value: &l.timeZoneStr, description: "Sets the timezone for time metrics (default is local time)"},
3839
},
3940
conditionAlias: l.buildConditionAlias(),
@@ -116,6 +117,11 @@ func (l *CheckProcess) buildConditionAlias() map[string]map[string]string {
116117
func (l *CheckProcess) Check(ctx context.Context, _ *Agent, check *CheckData, _ []Argument) (*CheckResult, error) {
117118
check.ExpandThresholdUnit([]string{"k", "m", "g", "p", "e", "ki", "mi", "gi", "pi", "ei"}, "B", []string{"rss", "virtual", "pagefile"})
118119

120+
// make process arg lowercase
121+
for i := range l.processes {
122+
l.processes[i] = strings.ToLower(l.processes[i])
123+
}
124+
119125
err := l.fetchProcs(ctx, check)
120126
if err != nil {
121127
return nil, err

pkg/snclient/check_process_other.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (l *CheckProcess) fetchProcs(ctx context.Context, check *CheckData) error {
5555
}
5656
}
5757

58-
if len(l.processes) > 0 && !slices.Contains(l.processes, exe) && !slices.Contains(l.processes, "*") {
58+
if len(l.processes) > 0 && !slices.Contains(l.processes, strings.ToLower(exe)) && !slices.Contains(l.processes, "*") {
5959
continue
6060
}
6161

pkg/snclient/check_process_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package snclient
55
import (
66
"os"
77
"path/filepath"
8+
"strings"
89
"testing"
910

1011
"github.com/consol-monitoring/snclient/pkg/convert"
@@ -52,5 +53,11 @@ func TestCheckProcess(t *testing.T) {
5253
assert.Regexpf(t, `OK - all \d+ processes are ok.`, string(res.BuildPluginOutput()), "output ok")
5354
assert.Regexpf(t, `rss'=\d{1,15}B;;;0`, string(res.BuildPluginOutput()), "rss ok")
5455

56+
// should work case insensitive
57+
res = snc.RunCheck("check_process", []string{"process=" + strings.ToUpper(filepath.Base(myExe))})
58+
assert.Equalf(t, CheckExitOK, res.State, "state ok")
59+
assert.Regexpf(t, `OK - all \d+ processes are ok.`, string(res.BuildPluginOutput()), "output ok")
60+
assert.Regexpf(t, `rss'=\d{1,15}B;;;0`, string(res.BuildPluginOutput()), "rss ok")
61+
5562
StopTestAgent(t, snc)
5663
}

pkg/snclient/check_process_windows.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"slices"
7+
"strings"
78
"time"
89

910
"github.com/consol-monitoring/snclient/pkg/wmi"
@@ -63,7 +64,7 @@ func (l *CheckProcess) fetchProcs(_ context.Context, check *CheckData) error {
6364
for i := range processData {
6465
proc := processData[i]
6566

66-
if len(l.processes) > 0 && !slices.Contains(l.processes, proc.Name) && !slices.Contains(l.processes, "*") {
67+
if len(l.processes) > 0 && !slices.Contains(l.processes, strings.ToLower(proc.Name)) && !slices.Contains(l.processes, "*") {
6768
continue
6869
}
6970

0 commit comments

Comments
 (0)