summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/t/check_uptime.t
blob: b31d0c6c28efa588578083919170ae71207b9aba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/perl -w -I ..
#
# check_uptime tests
#
#

use strict;
use Test::More tests => 42;
use NPTest;

my $result;

$result = NPTest->testCmd(
	"./check_uptime"
	);
cmp_ok( $result->return_code, '==', 3, "Missing parameters" );
like  ( $result->output, '/^Usage: check_uptime -w/', "Output for missing parameters correct" );

$result = NPTest->testCmd(
	"./check_uptime --help"
	);
cmp_ok( $result->return_code, '==', 3, "Help output requested" );
like  ( $result->output, '/ABSOLUTELY NO WARRANTY/', "Output for help correct" );

$result = NPTest->testCmd(
	"./check_uptime -w 5 -c 2"
	);
cmp_ok( $result->return_code, '==', 3, "Warning greater than critical" );
like  ( $result->output, '/^Upper Warning .*cannot be greater than Critical/', "Output for warning greater than critical correct" );

$result = NPTest->testCmd(
	"./check_uptime -c 1000 -W 100 2>&1"
	);
like  ( $result->output, '/^Unknown option: W/', "Output with wrong parameter is correct" );

$result = NPTest->testCmd(
	"./check_uptime -f -w 1 -c 2"
	);
cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" );
like  ( $result->output, '/Running for \d+/', "Output for the f parameter correct" );

$result = NPTest->testCmd(
	"./check_uptime -s -w 1 -c 2"
	);
cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" );
like  ( $result->output, '/Running since \d+/', "Output for the s parameter correct" );

$result = NPTest->testCmd(
	"./check_uptime -d -w 1 -c 2"
	);
cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" );
like  ( $result->output, '/CRITICAL: uptime is \d+ days/', "Output for the d parameter correct" );

$result = NPTest->testCmd(
	"./check_uptime -w 1 -c 2"
	);
cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" );
like  ( $result->output, '/^CRITICAL: uptime is \d+ seconds/', "Output for uptime higher than 2 seconds correct" );

$result = NPTest->testCmd(
	"./check_uptime -w 1 -c 9999w"
	);
cmp_ok( $result->return_code, '==', 1, "Uptime lower than 9999 weeks" );
like  ( $result->output, '/^WARNING: uptime is \d+ seconds/', "Output for uptime lower than 9999 weeks correct" );

$result = NPTest->testCmd(
	"./check_uptime -w 9998w -c 9999w"
	);
cmp_ok( $result->return_code, '==', 0, "Uptime lower than 9998 weeks" );
like  ( $result->output, '/^OK: uptime is \d+ seconds/', "Output for uptime lower than 9998 weeks correct" );
like  ( $result->output, '/\|uptime=[0-9]+s;6046790400;6047395200;/', "Checking for performance output" );

$result = NPTest->testCmd(
	"./check_uptime -w 111222d -c 222333d"
	);
cmp_ok( $result->return_code, '==', 0, "Uptime lower than 111222 days" );
like  ( $result->output, '/^OK: uptime is \d+ seconds/', "Output for uptime lower than 111222 days correct" );
like  ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" );

# Same as before, hopefully uptime is higher than 2 seconds so no warning
$result = NPTest->testCmd(
	"./check_uptime -w 2:111222d -c 1:222333d"
	);
cmp_ok( $result->return_code, '==', 0, "Uptime lower than 111222 days, and higher 2 seconds" );
like  ( $result->output, '/^OK: uptime is \d+ seconds/', "Output for uptime lower than 111222 days, and higher 2 seconds correct" );
like  ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" );

# Same as before, now the low warning should trigger
$result = NPTest->testCmd(
	"./check_uptime -w 111221d:111222d -c 1:222333d"
	);
cmp_ok( $result->return_code, '==', 1, "Uptime lower than 111221 days raises warning" );
like  ( $result->output, '/^WARNING: uptime is \d+ seconds/', "Output for uptime lower than 111221 days correct" );
like  ( $result->output, '/Exceeds lower warn threshold/', "Exceeds text correct" );
like  ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" );

# Same as before, now the low critical should trigger
$result = NPTest->testCmd(
	"./check_uptime -w 111221d:111222d -c 111220d:222333d"
	);
cmp_ok( $result->return_code, '==', 2, "Uptime lower than 111220 days raises critical" );
like  ( $result->output, '/^CRITICAL: uptime is \d+ seconds/', "Output for uptime lower than 111220 days correct" );
like  ( $result->output, '/Exceeds lower crit threshold/', "Exceeds text correct" );
like  ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" );


#
# Range values using ":" without two parts ("a:b") is invalid
# Strings without two parts are always considered as upper threshold
#

$result = NPTest->testCmd(
	"./check_uptime -w 2: -c 1:4"
	);
cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" );
like  ( $result->output, '/^Upper warning .* is not numeric/', "Output for wrong parameter format correct" );

$result = NPTest->testCmd(
	"./check_uptime -w 2:3 -c 1:"
	);
cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" );
like  ( $result->output, '/^Upper critical .* is not numeric/', "Output for wrong parameter format correct" );

$result = NPTest->testCmd(
	"./check_uptime -w :3 -c 1:4"
	);
cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" );
like  ( $result->output, '/^Upper warning .* is not numeric/', "Output for wrong parameter format correct" );

$result = NPTest->testCmd(
	"./check_uptime -w 2:3 -c :4"
	);
cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" );
like  ( $result->output, '/^Upper critical .* is not numeric/', "Output for wrong parameter format correct" );