Merge pull request #2032 from RincewindsHat/cleanup/check_apt
[monitoring-plugins.git] / plugins-scripts / t / check_uptime.t
blob6e81db3c1d01c409f4b036326bc461296201288f
1 #!/usr/bin/perl -w -I ..
3 # check_uptime tests
7 use strict;
8 use Test::More tests => 42;
9 use NPTest;
11 my $result;
13 $result = NPTest->testCmd(
14 "./check_uptime"
16 cmp_ok( $result->return_code, '==', 3, "Missing parameters" );
17 like ( $result->output, '/^Usage: check_uptime -w/', "Output for missing parameters correct" );
19 $result = NPTest->testCmd(
20 "./check_uptime --help"
22 cmp_ok( $result->return_code, '==', 3, "Help output requested" );
23 like ( $result->output, '/ABSOLUTELY NO WARRANTY/', "Output for help correct" );
25 $result = NPTest->testCmd(
26 "./check_uptime -w 5 -c 2"
28 cmp_ok( $result->return_code, '==', 3, "Warning greater than critical" );
29 like ( $result->output, '/^Upper Warning .*cannot be greater than Critical/', "Output for warning greater than critical correct" );
31 $result = NPTest->testCmd(
32 "./check_uptime -c 1000 -W 100 2>&1"
34 like ( $result->output, '/^Unknown option: W/', "Output with wrong parameter is correct" );
36 $result = NPTest->testCmd(
37 "./check_uptime -f -w 1 -c 2"
39 cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" );
40 like ( $result->output, '/Running for \d+/', "Output for the f parameter correct" );
42 $result = NPTest->testCmd(
43 "./check_uptime -s -w 1 -c 2"
45 cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" );
46 like ( $result->output, '/Running since \d+/', "Output for the s parameter correct" );
48 $result = NPTest->testCmd(
49 "./check_uptime -d -w 1 -c 2"
51 cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" );
52 like ( $result->output, '/CRITICAL: Uptime is \d+ days/', "Output for the d parameter correct" );
54 $result = NPTest->testCmd(
55 "./check_uptime -w 1 -c 2"
57 cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" );
58 like ( $result->output, '/^CRITICAL: Uptime is \d+ seconds/', "Output for uptime higher than 2 seconds correct" );
60 $result = NPTest->testCmd(
61 "./check_uptime -w 1 -c 9999w"
63 cmp_ok( $result->return_code, '==', 1, "Uptime lower than 9999 weeks" );
64 like ( $result->output, '/^WARNING: Uptime is \d+ seconds/', "Output for uptime lower than 9999 weeks correct" );
66 $result = NPTest->testCmd(
67 "./check_uptime -w 9998w -c 9999w"
69 cmp_ok( $result->return_code, '==', 0, "Uptime lower than 9998 weeks" );
70 like ( $result->output, '/^OK: Uptime is \d+ seconds/', "Output for uptime lower than 9998 weeks correct" );
71 like ( $result->output, '/\|uptime=[0-9]+s;6046790400;6047395200;/', "Checking for performance output" );
73 $result = NPTest->testCmd(
74 "./check_uptime -w 111222d -c 222333d"
76 cmp_ok( $result->return_code, '==', 0, "Uptime lower than 111222 days" );
77 like ( $result->output, '/^OK: Uptime is \d+ seconds/', "Output for uptime lower than 111222 days correct" );
78 like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" );
80 # Same as before, hopefully uptime is higher than 2 seconds so no warning
81 $result = NPTest->testCmd(
82 "./check_uptime -w 2:111222d -c 1:222333d"
84 cmp_ok( $result->return_code, '==', 0, "Uptime lower than 111222 days, and higher 2 seconds" );
85 like ( $result->output, '/^OK: Uptime is \d+ seconds/', "Output for uptime lower than 111222 days, and higher 2 seconds correct" );
86 like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" );
88 # Same as before, now the low warning should trigger
89 $result = NPTest->testCmd(
90 "./check_uptime -w 111221d:111222d -c 1:222333d"
92 cmp_ok( $result->return_code, '==', 1, "Uptime lower than 111221 days raises warning" );
93 like ( $result->output, '/^WARNING: Uptime is \d+ seconds/', "Output for uptime lower than 111221 days correct" );
94 like ( $result->output, '/Exceeds lower warn threshold/', "Exceeds text correct" );
95 like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" );
97 # Same as before, now the low critical should trigger
98 $result = NPTest->testCmd(
99 "./check_uptime -w 111221d:111222d -c 111220d:222333d"
101 cmp_ok( $result->return_code, '==', 2, "Uptime lower than 111220 days raises critical" );
102 like ( $result->output, '/^CRITICAL: Uptime is \d+ seconds/', "Output for uptime lower than 111220 days correct" );
103 like ( $result->output, '/Exceeds lower crit threshold/', "Exceeds text correct" );
104 like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" );
108 # Range values using ":" without two parts ("a:b") is invalid
109 # Strings without two parts are always considered as upper threshold
112 $result = NPTest->testCmd(
113 "./check_uptime -w 2: -c 1:4"
115 cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" );
116 like ( $result->output, '/^Upper warning .* is not numeric/', "Output for wrong parameter format correct" );
118 $result = NPTest->testCmd(
119 "./check_uptime -w 2:3 -c 1:"
121 cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" );
122 like ( $result->output, '/^Upper critical .* is not numeric/', "Output for wrong parameter format correct" );
124 $result = NPTest->testCmd(
125 "./check_uptime -w :3 -c 1:4"
127 cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" );
128 like ( $result->output, '/^Upper warning .* is not numeric/', "Output for wrong parameter format correct" );
130 $result = NPTest->testCmd(
131 "./check_uptime -w 2:3 -c :4"
133 cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" );
134 like ( $result->output, '/^Upper critical .* is not numeric/', "Output for wrong parameter format correct" );