summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/t/check_uptime.t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-scripts/t/check_uptime.t')
-rw-r--r--plugins-scripts/t/check_uptime.t135
1 files changed, 135 insertions, 0 deletions
diff --git a/plugins-scripts/t/check_uptime.t b/plugins-scripts/t/check_uptime.t
new file mode 100644
index 0000000..6e81db3
--- /dev/null
+++ b/plugins-scripts/t/check_uptime.t
@@ -0,0 +1,135 @@
1#!/usr/bin/perl -w -I ..
2#
3# check_uptime tests
4#
5#
6
7use strict;
8use Test::More tests => 42;
9use NPTest;
10
11my $result;
12
13$result = NPTest->testCmd(
14 "./check_uptime"
15 );
16cmp_ok( $result->return_code, '==', 3, "Missing parameters" );
17like ( $result->output, '/^Usage: check_uptime -w/', "Output for missing parameters correct" );
18
19$result = NPTest->testCmd(
20 "./check_uptime --help"
21 );
22cmp_ok( $result->return_code, '==', 3, "Help output requested" );
23like ( $result->output, '/ABSOLUTELY NO WARRANTY/', "Output for help correct" );
24
25$result = NPTest->testCmd(
26 "./check_uptime -w 5 -c 2"
27 );
28cmp_ok( $result->return_code, '==', 3, "Warning greater than critical" );
29like ( $result->output, '/^Upper Warning .*cannot be greater than Critical/', "Output for warning greater than critical correct" );
30
31$result = NPTest->testCmd(
32 "./check_uptime -c 1000 -W 100 2>&1"
33 );
34like ( $result->output, '/^Unknown option: W/', "Output with wrong parameter is correct" );
35
36$result = NPTest->testCmd(
37 "./check_uptime -f -w 1 -c 2"
38 );
39cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" );
40like ( $result->output, '/Running for \d+/', "Output for the f parameter correct" );
41
42$result = NPTest->testCmd(
43 "./check_uptime -s -w 1 -c 2"
44 );
45cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" );
46like ( $result->output, '/Running since \d+/', "Output for the s parameter correct" );
47
48$result = NPTest->testCmd(
49 "./check_uptime -d -w 1 -c 2"
50 );
51cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" );
52like ( $result->output, '/CRITICAL: Uptime is \d+ days/', "Output for the d parameter correct" );
53
54$result = NPTest->testCmd(
55 "./check_uptime -w 1 -c 2"
56 );
57cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" );
58like ( $result->output, '/^CRITICAL: Uptime is \d+ seconds/', "Output for uptime higher than 2 seconds correct" );
59
60$result = NPTest->testCmd(
61 "./check_uptime -w 1 -c 9999w"
62 );
63cmp_ok( $result->return_code, '==', 1, "Uptime lower than 9999 weeks" );
64like ( $result->output, '/^WARNING: Uptime is \d+ seconds/', "Output for uptime lower than 9999 weeks correct" );
65
66$result = NPTest->testCmd(
67 "./check_uptime -w 9998w -c 9999w"
68 );
69cmp_ok( $result->return_code, '==', 0, "Uptime lower than 9998 weeks" );
70like ( $result->output, '/^OK: Uptime is \d+ seconds/', "Output for uptime lower than 9998 weeks correct" );
71like ( $result->output, '/\|uptime=[0-9]+s;6046790400;6047395200;/', "Checking for performance output" );
72
73$result = NPTest->testCmd(
74 "./check_uptime -w 111222d -c 222333d"
75 );
76cmp_ok( $result->return_code, '==', 0, "Uptime lower than 111222 days" );
77like ( $result->output, '/^OK: Uptime is \d+ seconds/', "Output for uptime lower than 111222 days correct" );
78like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" );
79
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"
83 );
84cmp_ok( $result->return_code, '==', 0, "Uptime lower than 111222 days, and higher 2 seconds" );
85like ( $result->output, '/^OK: Uptime is \d+ seconds/', "Output for uptime lower than 111222 days, and higher 2 seconds correct" );
86like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" );
87
88# Same as before, now the low warning should trigger
89$result = NPTest->testCmd(
90 "./check_uptime -w 111221d:111222d -c 1:222333d"
91 );
92cmp_ok( $result->return_code, '==', 1, "Uptime lower than 111221 days raises warning" );
93like ( $result->output, '/^WARNING: Uptime is \d+ seconds/', "Output for uptime lower than 111221 days correct" );
94like ( $result->output, '/Exceeds lower warn threshold/', "Exceeds text correct" );
95like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" );
96
97# Same as before, now the low critical should trigger
98$result = NPTest->testCmd(
99 "./check_uptime -w 111221d:111222d -c 111220d:222333d"
100 );
101cmp_ok( $result->return_code, '==', 2, "Uptime lower than 111220 days raises critical" );
102like ( $result->output, '/^CRITICAL: Uptime is \d+ seconds/', "Output for uptime lower than 111220 days correct" );
103like ( $result->output, '/Exceeds lower crit threshold/', "Exceeds text correct" );
104like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" );
105
106
107#
108# Range values using ":" without two parts ("a:b") is invalid
109# Strings without two parts are always considered as upper threshold
110#
111
112$result = NPTest->testCmd(
113 "./check_uptime -w 2: -c 1:4"
114 );
115cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" );
116like ( $result->output, '/^Upper warning .* is not numeric/', "Output for wrong parameter format correct" );
117
118$result = NPTest->testCmd(
119 "./check_uptime -w 2:3 -c 1:"
120 );
121cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" );
122like ( $result->output, '/^Upper critical .* is not numeric/', "Output for wrong parameter format correct" );
123
124$result = NPTest->testCmd(
125 "./check_uptime -w :3 -c 1:4"
126 );
127cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" );
128like ( $result->output, '/^Upper warning .* is not numeric/', "Output for wrong parameter format correct" );
129
130$result = NPTest->testCmd(
131 "./check_uptime -w 2:3 -c :4"
132 );
133cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" );
134like ( $result->output, '/^Upper critical .* is not numeric/', "Output for wrong parameter format correct" );
135