summaryrefslogtreecommitdiffstats
path: root/plugins/tests
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/tests')
-rw-r--r--plugins/tests/check_procs.t115
1 files changed, 115 insertions, 0 deletions
diff --git a/plugins/tests/check_procs.t b/plugins/tests/check_procs.t
new file mode 100644
index 0000000..1d0c034
--- /dev/null
+++ b/plugins/tests/check_procs.t
@@ -0,0 +1,115 @@
1#! /usr/bin/perl -w -I ..
2#
3# Test check_procs using input files
4#
5
6use strict;
7use Test::More;
8use NPTest;
9
10if (-x "./check_procs") {
11 plan tests => 48;
12} else {
13 plan skip_all => "No check_procs compiled";
14}
15
16my $result;
17my $command = "./check_procs --input-file=tests/var/ps-axwo.darwin";
18
19$result = NPTest->testCmd( "$command" );
20is( $result->return_code, 0, "Run with no options" );
21like( $result->output, '/^PROCS OK: 95 processes$/', "Output correct" );
22
23$result = NPTest->testCmd( "$command -w 5" );
24is( $result->return_code, 1, "Checking > 5 processes" );
25like( $result->output, '/^PROCS WARNING: 95 processes$/', "Output correct" );
26
27$result = NPTest->testCmd( "$command -w 4 -c 44" );
28is( $result->return_code, 2, "Checking critical" );
29like( $result->output, '/^PROCS CRITICAL: 95 processes$/', "Output correct" );
30
31$result = NPTest->testCmd( "$command -w 100 -c 200" );
32is( $result->return_code, 0, "Checking no threshold breeched" );
33like( $result->output, '/^PROCS OK: 95 processes$/', "Output correct" );
34
35$result = NPTest->testCmd( "$command -C launchd -c 5" );
36is( $result->return_code, 2, "Checking processes filtered by command name" );
37like( $result->output, '/^PROCS CRITICAL: 6 processes with command name \'launchd\'$/', "Output correct" );
38
39$result = NPTest->testCmd( "$command -u 501 -w 39 -c 41" );
40is( $result->return_code, 1, "Checking processes filtered by userid" );
41like( $result->output, '/^PROCS WARNING: 40 processes with UID = 501 (.*)$/', "Output correct" );
42
43$result = NPTest->testCmd( "$command -C launchd -u 501" );
44is( $result->return_code, 0, "Checking processes filtered by command name and userid" );
45like( $result->output, '/^PROCS OK: 1 process with command name \'launchd\', UID = 501 (.*)$/', "Output correct" );
46
47$result = NPTest->testCmd( "$command -u -2 -w 2:2" );
48is( $result->return_code, 1, "Checking processes with userid=-2" );
49like( $result->output, '/^PROCS WARNING: 3 processes with UID = -2 \(nobody\)$/', "Output correct" );
50
51$result = NPTest->testCmd( "$command -u -2 -w 3:3" );
52is( $result->return_code, 0, "Checking processes with userid=-2 past threshold" );
53like( $result->output, '/^PROCS OK: 3 processes with UID = -2 \(nobody\)$/', "Output correct" );
54
55$result = NPTest->testCmd( "$command -u -2 -a usb" );
56is( $result->return_code, 0, "Checking processes with userid=-2 and usb in arguments" );
57like( $result->output, '/^PROCS OK: 1 process with UID = -2 \(nobody\), args \'usb\'/', "Output correct" );
58
59$result = NPTest->testCmd( "$command -u -2 -a UsB" );
60is( $result->return_code, 0, "Checking case sensitivity of args" );
61like( $result->output, '/^PROCS OK: 0 processes with UID = -2 \(nobody\), args \'UsB\'/', "Output correct" );
62
63$result = NPTest->testCmd( "$command --ereg-argument-array='mdworker.*501'" );
64is( $result->return_code, 0, "Checking regexp search of arguments" );
65is( $result->output, "PROCS OK: 1 process with regex args 'mdworker.*501'", "Output correct" );
66
67$result = NPTest->testCmd( "$command --vsz 1000000" );
68is( $result->return_code, 0, "Checking filter by VSZ" );
69like( $result->output, '/^PROCS OK: 24 processes with VSZ >= 1000000$/', "Output correct" );
70
71$result = NPTest->testCmd( "$command --rss 100000" );
72is( $result->return_code, 0, "Checking filter by RSS" );
73like( $result->output, '/^PROCS OK: 3 processes with RSS >= 100000$/', "Output correct" );
74
75$result = NPTest->testCmd( "$command -s S" );
76is( $result->return_code, 0, "Checking filter for sleeping processes" );
77like( $result->output, '/^PROCS OK: 44 processes with STATE = S/', "Output correct" );
78
79$result = NPTest->testCmd( "$command -s Z" );
80is( $result->return_code, 0, "Checking filter for zombies" );
81like( $result->output, '/^PROCS OK: 1 process with STATE = Z/', "Output correct" );
82
83$result = NPTest->testCmd( "$command -p 1 -c 30" );
84is( $result->return_code, 2, "Checking filter for parent id = 1" );
85like( $result->output, '/^PROCS CRITICAL: 39 processes with PPID = 1/', "Output correct" );
86
87$result = NPTest->testCmd( "$command -P 0.71" );
88is( $result->return_code, 0, "Checking filter for percentage cpu > 0.71" );
89is( $result->output, 'PROCS OK: 7 processes with PCPU >= 0.71', "Output correct" );
90
91$result = NPTest->testCmd( "$command -P 0.70" );
92is( $result->return_code, 0, "Checking filter for percentage cpu > 0.70" );
93is( $result->output, 'PROCS OK: 8 processes with PCPU >= 0.70', "Output correct" );
94
95$result = NPTest->testCmd( "$command --metric=CPU -w 8" );
96is( $result->return_code, 1, "Checking against metric of CPU > 8" );
97is( $result->output, 'CPU WARNING: 1 warn out of 95 processes', "Output correct" );
98
99# TODO: Because of a conversion to int, if CPU is 1.45%, will not alert, but 2.01% will.
100$result = NPTest->testCmd( "$command --metric=CPU -w 1 -u 501 -v" );
101is( $result->return_code, 1, "Checking against metric of CPU > 1 with uid=501 - TODO" );
102is( $result->output, 'CPU WARNING: 2 warn out of 40 processes with UID = 501 (tonvoon) [Skype, PubSubAgent]', "Output correct" );
103
104$result = NPTest->testCmd( "$command --metric=VSZ -w 1200000 -v" );
105is( $result->return_code, 1, "Checking against VSZ > 1.2GB" );
106is( $result->output, 'VSZ WARNING: 4 warn out of 95 processes [WindowServer, Safari, Mail, Skype]', "Output correct" );
107
108$result = NPTest->testCmd( "$command --metric=VSZ -w 1200000 -v" );
109is( $result->return_code, 1, "Checking against VSZ > 1.2GB" );
110is( $result->output, 'VSZ WARNING: 4 warn out of 95 processes [WindowServer, Safari, Mail, Skype]', "Output correct" );
111
112$result = NPTest->testCmd( "$command --metric=RSS -c 70000 -v" );
113is( $result->return_code, 2, "Checking against RSS > 70MB" );
114is( $result->output, 'RSS CRITICAL: 5 crit, 0 warn out of 95 processes [WindowServer, SystemUIServer, Safari, Mail, Safari]', "Output correct" );
115