summaryrefslogtreecommitdiffstats
path: root/plugins/tests/check_procs.t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/tests/check_procs.t')
-rwxr-xr-x[-rw-r--r--]plugins/tests/check_procs.t85
1 files changed, 49 insertions, 36 deletions
diff --git a/plugins/tests/check_procs.t b/plugins/tests/check_procs.t
index d71c83a..54d43d9 100644..100755
--- a/plugins/tests/check_procs.t
+++ b/plugins/tests/check_procs.t
@@ -18,59 +18,68 @@ my $command = "./check_procs --input-file=tests/var/ps-axwo.darwin";
18 18
19$result = NPTest->testCmd( "$command" ); 19$result = NPTest->testCmd( "$command" );
20is( $result->return_code, 0, "Run with no options" ); 20is( $result->return_code, 0, "Run with no options" );
21like( $result->output, '/^PROCS OK: 95 processes$/', "Output correct" ); 21is( $result->output, "PROCS OK: 95 processes | procs=95;;;0;", "Output correct" );
22 22
23$result = NPTest->testCmd( "$command -w 5" ); 23$result = NPTest->testCmd( "$command -w 5" );
24is( $result->return_code, 1, "Checking > 5 processes" ); 24is( $result->return_code, 1, "Checking > 5 processes" );
25like( $result->output, '/^PROCS WARNING: 95 processes$/', "Output correct" ); 25is( $result->output, "PROCS WARNING: 95 processes | procs=95;5;;0;", "Output correct" );
26 26
27$result = NPTest->testCmd( "$command -w 4 -c 44" ); 27$result = NPTest->testCmd( "$command -w 4 -c 44" );
28is( $result->return_code, 2, "Checking critical" ); 28is( $result->return_code, 2, "Checking critical" );
29like( $result->output, '/^PROCS CRITICAL: 95 processes$/', "Output correct" ); 29is( $result->output, "PROCS CRITICAL: 95 processes | procs=95;4;44;0;", "Output correct" );
30 30
31$result = NPTest->testCmd( "$command -w 100 -c 200" ); 31$result = NPTest->testCmd( "$command -w 100 -c 200" );
32is( $result->return_code, 0, "Checking no threshold breeched" ); 32is( $result->return_code, 0, "Checking no threshold breeched" );
33like( $result->output, '/^PROCS OK: 95 processes$/', "Output correct" ); 33is( $result->output, "PROCS OK: 95 processes | procs=95;100;200;0;", "Output correct" );
34 34
35$result = NPTest->testCmd( "$command -C launchd -c 5" ); 35$result = NPTest->testCmd( "$command -C launchd -c 5" );
36is( $result->return_code, 2, "Checking processes filtered by command name" ); 36is( $result->return_code, 2, "Checking processes filtered by command name" );
37like( $result->output, '/^PROCS CRITICAL: 6 processes with command name \'launchd\'$/', "Output correct" ); 37is( $result->output, "PROCS CRITICAL: 6 processes with command name 'launchd' | procs=6;;5;0;", "Output correct" );
38 38
39$result = NPTest->testCmd( "$command -u 501 -w 39 -c 41" ); 39SKIP: {
40is( $result->return_code, 1, "Checking processes filtered by userid" ); 40 skip 'user with uid 501 required', 4 unless getpwuid(501);
41like( $result->output, '/^PROCS WARNING: 40 processes with UID = 501 (.*)$/', "Output correct" );
42 41
43$result = NPTest->testCmd( "$command -C launchd -u 501" ); 42 $result = NPTest->testCmd( "$command -u 501 -w 39 -c 41" );
44is( $result->return_code, 0, "Checking processes filtered by command name and userid" ); 43 is( $result->return_code, 1, "Checking processes filtered by userid" );
45like( $result->output, '/^PROCS OK: 1 process with command name \'launchd\', UID = 501 (.*)$/', "Output correct" ); 44 like( $result->output, '/^PROCS WARNING: 40 processes with UID = 501 (.*)$/', "Output correct" );
46 45
47$result = NPTest->testCmd( "$command -u -2 -w 2:2" ); 46 $result = NPTest->testCmd( "$command -C launchd -u 501" );
48is( $result->return_code, 1, "Checking processes with userid=-2" ); 47 is( $result->return_code, 0, "Checking processes filtered by command name and userid" );
49like( $result->output, '/^PROCS WARNING: 3 processes with UID = -2 \(nobody\)$/', "Output correct" ); 48 like( $result->output, '/^PROCS OK: 1 process with command name \'launchd\', UID = 501 (.*)$/', "Output correct" );
49}
50
51SKIP: {
52 skip 'user with uid -2 required', 8 unless getpwuid(-2);
53 skip 'uid -2 must have name "nobody"', 8 unless getpwuid(-2) eq 'nobody';
50 54
51$result = NPTest->testCmd( "$command -u -2 -w 3:3" ); 55 $result = NPTest->testCmd( "$command -u -2 -w 2:2" );
52is( $result->return_code, 0, "Checking processes with userid=-2 past threshold" ); 56 is( $result->return_code, 1, "Checking processes with userid=-2" );
53like( $result->output, '/^PROCS OK: 3 processes with UID = -2 \(nobody\)$/', "Output correct" ); 57 like( $result->output, '/^PROCS WARNING: 3 processes with UID = -2 \(nobody\)$/', "Output correct" );
54 58
55$result = NPTest->testCmd( "$command -u -2 -a usb" ); 59 $result = NPTest->testCmd( "$command -u -2 -w 3:3" );
56is( $result->return_code, 0, "Checking processes with userid=-2 and usb in arguments" ); 60 is( $result->return_code, 0, "Checking processes with userid=-2 past threshold" );
57like( $result->output, '/^PROCS OK: 1 process with UID = -2 \(nobody\), args \'usb\'/', "Output correct" ); 61 like( $result->output, '/^PROCS OK: 3 processes with UID = -2 \(nobody\)$/', "Output correct" );
58 62
59$result = NPTest->testCmd( "$command -u -2 -a UsB" ); 63 $result = NPTest->testCmd( "$command -u -2 -a usb" );
60is( $result->return_code, 0, "Checking case sensitivity of args" ); 64 is( $result->return_code, 0, "Checking processes with userid=-2 and usb in arguments" );
61like( $result->output, '/^PROCS OK: 0 processes with UID = -2 \(nobody\), args \'UsB\'/', "Output correct" ); 65 like( $result->output, '/^PROCS OK: 1 process with UID = -2 \(nobody\), args \'usb\'/', "Output correct" );
66
67 $result = NPTest->testCmd( "$command -u -2 -a UsB" );
68 is( $result->return_code, 0, "Checking case sensitivity of args" );
69 like( $result->output, '/^PROCS OK: 0 processes with UID = -2 \(nobody\), args \'UsB\'/', "Output correct" );
70};
62 71
63$result = NPTest->testCmd( "$command --ereg-argument-array='mdworker.*501'" ); 72$result = NPTest->testCmd( "$command --ereg-argument-array='mdworker.*501'" );
64is( $result->return_code, 0, "Checking regexp search of arguments" ); 73is( $result->return_code, 0, "Checking regexp search of arguments" );
65is( $result->output, "PROCS OK: 1 process with regex args 'mdworker.*501'", "Output correct" ); 74is( $result->output, "PROCS OK: 1 process with regex args 'mdworker.*501' | procs=1;;;0;", "Output correct" );
66 75
67$result = NPTest->testCmd( "$command --vsz 1000000" ); 76$result = NPTest->testCmd( "$command --vsz 1000000" );
68is( $result->return_code, 0, "Checking filter by VSZ" ); 77is( $result->return_code, 0, "Checking filter by VSZ" );
69like( $result->output, '/^PROCS OK: 24 processes with VSZ >= 1000000$/', "Output correct" ); 78is( $result->output, 'PROCS OK: 24 processes with VSZ >= 1000000 | procs=24;;;0;', "Output correct" );
70 79
71$result = NPTest->testCmd( "$command --rss 100000" ); 80$result = NPTest->testCmd( "$command --rss 100000" );
72is( $result->return_code, 0, "Checking filter by RSS" ); 81is( $result->return_code, 0, "Checking filter by RSS" );
73like( $result->output, '/^PROCS OK: 3 processes with RSS >= 100000$/', "Output correct" ); 82is( $result->output, 'PROCS OK: 3 processes with RSS >= 100000 | procs=3;;;0;', "Output correct" );
74 83
75$result = NPTest->testCmd( "$command -s S" ); 84$result = NPTest->testCmd( "$command -s S" );
76is( $result->return_code, 0, "Checking filter for sleeping processes" ); 85is( $result->return_code, 0, "Checking filter for sleeping processes" );
@@ -86,34 +95,38 @@ like( $result->output, '/^PROCS CRITICAL: 39 processes with PPID = 1/', "Output
86 95
87$result = NPTest->testCmd( "$command -P 0.71" ); 96$result = NPTest->testCmd( "$command -P 0.71" );
88is( $result->return_code, 0, "Checking filter for percentage cpu > 0.71" ); 97is( $result->return_code, 0, "Checking filter for percentage cpu > 0.71" );
89is( $result->output, 'PROCS OK: 7 processes with PCPU >= 0.71', "Output correct" ); 98is( $result->output, 'PROCS OK: 7 processes with PCPU >= 0.71 | procs=7;;;0;', "Output correct" );
90 99
91$result = NPTest->testCmd( "$command -P 0.70" ); 100$result = NPTest->testCmd( "$command -P 0.70" );
92is( $result->return_code, 0, "Checking filter for percentage cpu > 0.70" ); 101is( $result->return_code, 0, "Checking filter for percentage cpu > 0.70" );
93is( $result->output, 'PROCS OK: 8 processes with PCPU >= 0.70', "Output correct" ); 102is( $result->output, 'PROCS OK: 8 processes with PCPU >= 0.70 | procs=8;;;0;', "Output correct" );
94 103
95$result = NPTest->testCmd( "$command --metric=CPU -w 8" ); 104$result = NPTest->testCmd( "$command --metric=CPU -w 8" );
96is( $result->return_code, 1, "Checking against metric of CPU > 8" ); 105is( $result->return_code, 1, "Checking against metric of CPU > 8" );
97is( $result->output, 'CPU WARNING: 1 warn out of 95 processes', "Output correct" ); 106is( $result->output, 'CPU WARNING: 1 warn out of 95 processes | procs=95;;;0; procs_warn=1;;;0; procs_crit=0;;;0;', "Output correct" );
98 107
99# TODO: Because of a conversion to int, if CPU is 1.45%, will not alert, but 2.01% will. 108# 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" ); 109SKIP: {
101is( $result->return_code, 1, "Checking against metric of CPU > 1 with uid=501 - TODO" ); 110 skip 'user with uid 501 required', 2 unless getpwuid(501);
102is( $result->output, 'CPU WARNING: 2 warn out of 40 processes with UID = 501 (tonvoon) [Skype, PubSubAgent]', "Output correct" ); 111
112 $result = NPTest->testCmd( "$command --metric=CPU -w 1 -u 501 -v" );
113 is( $result->return_code, 1, "Checking against metric of CPU > 1 with uid=501 - TODO" );
114 is( $result->output, 'CPU WARNING: 2 warn out of 40 processes with UID = 501 (tonvoon) [Skype, PubSubAgent]', "Output correct" );
115};
103 116
104$result = NPTest->testCmd( "$command --metric=VSZ -w 1200000 -v" ); 117$result = NPTest->testCmd( "$command --metric=VSZ -w 1200000 -v" );
105is( $result->return_code, 1, "Checking against VSZ > 1.2GB" ); 118is( $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" ); 119is( $result->output, 'VSZ WARNING: 4 warn out of 95 processes [WindowServer, Safari, Mail, Skype] | procs=95;;;0; procs_warn=4;;;0; procs_crit=0;;;0;', "Output correct" );
107 120
108$result = NPTest->testCmd( "$command --metric=VSZ -w 1200000 -v" ); 121$result = NPTest->testCmd( "$command --metric=VSZ -w 1200000 -v" );
109is( $result->return_code, 1, "Checking against VSZ > 1.2GB" ); 122is( $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" ); 123is( $result->output, 'VSZ WARNING: 4 warn out of 95 processes [WindowServer, Safari, Mail, Skype] | procs=95;;;0; procs_warn=4;;;0; procs_crit=0;;;0;', "Output correct" );
111 124
112$result = NPTest->testCmd( "$command --metric=RSS -c 70000 -v" ); 125$result = NPTest->testCmd( "$command --metric=RSS -c 70000 -v" );
113is( $result->return_code, 2, "Checking against RSS > 70MB" ); 126is( $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" ); 127is( $result->output, 'RSS CRITICAL: 5 crit, 0 warn out of 95 processes [WindowServer, SystemUIServer, Safari, Mail, Safari] | procs=95;;;0; procs_warn=0;;;0; procs_crit=5;;;0;', "Output correct" );
115 128
116$result = NPTest->testCmd( "$command --ereg-argument-array='(nosuchname|nosuch2name)'" ); 129$result = NPTest->testCmd( "$command --ereg-argument-array='(nosuchname|nosuch2name)'" );
117is( $result->return_code, 0, "Checking no pipe symbol in output" ); 130is( $result->return_code, 0, "Checking no pipe symbol in output" );
118is( $result->output, "PROCS OK: 0 processes with regex args '(nosuchname,nosuch2name)'", "Output correct" ); 131is( $result->output, "PROCS OK: 0 processes with regex args '(nosuchname,nosuch2name)' | procs=0;;;0;", "Output correct" );
119 132