summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-scripts/t')
-rw-r--r--plugins-scripts/t/check_file_age.t75
-rw-r--r--plugins-scripts/t/check_log.t82
-rw-r--r--plugins-scripts/t/check_uptime.t135
-rw-r--r--plugins-scripts/t/utils.t1
4 files changed, 261 insertions, 32 deletions
diff --git a/plugins-scripts/t/check_file_age.t b/plugins-scripts/t/check_file_age.t
index 50a2e69..8b87670 100644
--- a/plugins-scripts/t/check_file_age.t
+++ b/plugins-scripts/t/check_file_age.t
@@ -5,14 +5,14 @@
5# 5#
6 6
7use strict; 7use strict;
8use Test::More tests => 17; 8use Test::More tests => 27;
9use NPTest; 9use NPTest;
10 10
11my $successOutput = '/^FILE_AGE OK: /'; 11my $successOutput = '/^FILE_AGE OK: /';
12my $warningOutput = '/^FILE_AGE WARNING: /'; 12my $warningOutput = '/^FILE_AGE WARNING: /';
13my $criticalOutput = '/^FILE_AGE CRITICAL: /'; 13my $criticalOutput = '/^FILE_AGE CRITICAL: /';
14my $unknownOutput = '/^FILE_AGE UNKNOWN: /'; 14my $unknownOutput = '/^FILE_AGE UNKNOWN: /';
15my $performanceOutput = '/ \| age=[0-9]+s;[0-9]+;[0-9]+ size=[0-9]+B;[0-9]+;[0-9]+;0$/'; 15my $performanceOutput = '/ \| age=[0-9]+s;[0-9:]+;[0-9:]+ size=[0-9]+B;[0-9:]+;[0-9:]+;0$/';
16 16
17my $result; 17my $result;
18my $temp_file = "/tmp/check_file_age.tmp"; 18my $temp_file = "/tmp/check_file_age.tmp";
@@ -20,64 +20,75 @@ my $temp_link = "/tmp/check_file_age.link.tmp";
20 20
21unlink $temp_file, $temp_link; 21unlink $temp_file, $temp_link;
22 22
23$result = NPTest->testCmd( 23$result = NPTest->testCmd("./check_file_age");
24 "./check_file_age"
25 );
26cmp_ok( $result->return_code, '==', 3, "Missing parameters" ); 24cmp_ok( $result->return_code, '==', 3, "Missing parameters" );
27like ( $result->output, $unknownOutput, "Output for unknown correct" ); 25like ( $result->output, $unknownOutput, "Output for unknown correct" );
28 26
29$result = NPTest->testCmd( 27$result = NPTest->testCmd("./check_file_age -f $temp_file");
30 "./check_file_age -f $temp_file"
31 );
32cmp_ok( $result->return_code, '==', 2, "File not exists" ); 28cmp_ok( $result->return_code, '==', 2, "File not exists" );
33like ( $result->output, $criticalOutput, "Output for file missing correct" ); 29like ( $result->output, $criticalOutput, "Output for file missing correct" );
34 30
35write_chars(100); 31write_chars(100);
36$result = NPTest->testCmd( 32$result = NPTest->testCmd("./check_file_age -f $temp_file");
37 "./check_file_age -f $temp_file"
38 );
39cmp_ok( $result->return_code, '==', 0, "File is new enough" ); 33cmp_ok( $result->return_code, '==', 0, "File is new enough" );
40like ( $result->output, $successOutput, "Output for success correct" ); 34like ( $result->output, $successOutput, "Output for success correct" );
41 35
42sleep 2; 36sleep 2;
43 37
44$result = NPTest->testCmd( 38$result = NPTest->testCmd("./check_file_age -f $temp_file -w 1");
45 "./check_file_age -f $temp_file -w 1"
46 );
47cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old" ); 39cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old" );
48like ( $result->output, $warningOutput, "Output for warning correct" ); 40like ( $result->output, $warningOutput, "Output for warning correct" );
49 41
50$result = NPTest->testCmd( 42$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1");
51 "./check_file_age -f $temp_file -c 1"
52 );
53cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old" ); 43cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old" );
54like ( $result->output, $criticalOutput, "Output for critical correct" ); 44like ( $result->output, $criticalOutput, "Output for critical correct" );
55 45
56$result = NPTest->testCmd( 46$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 100");
57 "./check_file_age -f $temp_file -c 1000 -W 100"
58 );
59cmp_ok( $result->return_code, '==', 0, "Checking file size" ); 47cmp_ok( $result->return_code, '==', 0, "Checking file size" );
60 48
61$result = NPTest->testCmd( 49$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 100");
62 "./check_file_age -f $temp_file -c 1000 -W 100"
63 );
64like( $result->output, $performanceOutput, "Checking for performance Output" ); 50like( $result->output, $performanceOutput, "Checking for performance Output" );
65 51
66$result = NPTest->testCmd( 52$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 100");
67 "./check_file_age -f /non/existent --ignore-missing" 53like( $result->output, $performanceOutput, "Checking for performance Output from range" );
68 ); 54
55$result = NPTest->testCmd("./check_file_age -f /non/existent --ignore-missing");
69cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" ); 56cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" );
70 57
71$result = NPTest->testCmd( 58$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 101");
72 "./check_file_age -f $temp_file -c 1000 -W 101"
73 );
74cmp_ok( $result->return_code, '==', 1, "One byte too short" ); 59cmp_ok( $result->return_code, '==', 1, "One byte too short" );
75 60
76$result = NPTest->testCmd( 61$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -C 101");
77 "./check_file_age -f $temp_file -c 1000 -C 101"
78 );
79cmp_ok( $result->return_code, '==', 2, "One byte too short - critical" ); 62cmp_ok( $result->return_code, '==', 2, "One byte too short - critical" );
80 63
64SKIP: {
65 eval 'use Monitoring::Plugin::Range';
66 skip "Monitoring::Plugin::Range module require", 9 if $@;
67
68 $result = NPTest->testCmd("./check_file_age -f $temp_file -w 0:1");
69 cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old by range" );
70 like ( $result->output, $warningOutput, "Output for warning by range correct" );
71
72 $result = NPTest->testCmd("./check_file_age -f $temp_file -c 0:1");
73 cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old by range" );
74 like ( $result->output, $criticalOutput, "Output for critical by range correct" );
75
76 $result = NPTest->testCmd("./check_file_age -f $temp_file -c 0:1000 -W 0:100");
77 cmp_ok( $result->return_code, '==', 0, "Checking file size by range" );
78
79 $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 101:");
80 cmp_ok( $result->return_code, '==', 1, "One byte too short by range" );
81
82 $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 0:99");
83 cmp_ok( $result->return_code, '==', 1, "One byte too long by range" );
84
85 $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -C 101:");
86 cmp_ok( $result->return_code, '==', 2, "One byte too short by range - critical" );
87
88 $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -C 0:99");
89 cmp_ok( $result->return_code, '==', 2, "One byte too long by range - critical" );
90};
91
81symlink $temp_file, $temp_link or die "Cannot create symlink"; 92symlink $temp_file, $temp_link or die "Cannot create symlink";
82$result = NPTest->testCmd("./check_file_age -f $temp_link -c 10"); 93$result = NPTest->testCmd("./check_file_age -f $temp_link -c 10");
83cmp_ok( $result->return_code, '==', 0, "Works for symlinks" ); 94cmp_ok( $result->return_code, '==', 0, "Works for symlinks" );
diff --git a/plugins-scripts/t/check_log.t b/plugins-scripts/t/check_log.t
new file mode 100644
index 0000000..b66e0fd
--- /dev/null
+++ b/plugins-scripts/t/check_log.t
@@ -0,0 +1,82 @@
1#!/usr/bin/perl -w -I ..
2#
3# check_log tests
4#
5#
6
7use strict;
8use Test::More;
9use NPTest;
10
11my $tests = 18;
12plan tests => $tests;
13
14my $firstTimeOutput ='/^Log check data initialized/';
15my $okOutput = '/^Log check ok - 0 pattern matches found/';
16my $criticalOutput = '/^\(\d+\) < /';
17my $multilineOutput = '/\(3\) <.*\n.*\n.*$/';
18my $unknownOutput = '/^Usage: /';
19my $unknownArgOutput = '/^Unknown argument: /';
20my $bothRegexOutput = '/^Can not use extended and perl regex/';
21
22my $result;
23my $temp_file = "/tmp/check_log.tmp";
24my $oldlog = "/tmp/oldlog.tmp";
25
26open(FH, '>', $temp_file) or die $!;
27close(FH);
28
29$result = NPTest->testCmd("./check_log");
30cmp_ok( $result->return_code, '==', 3, "Missing parameters" );
31like ( $result->output, $unknownOutput, "Output for unknown correct" );
32
33$result = NPTest->testCmd("./check_log -f");
34cmp_ok( $result->return_code, '==', 3, "Wrong parameters" );
35like ( $result->output, $unknownArgOutput, "Output for unknown correct" );
36
37$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'Simple match' -e -p");
38cmp_ok( $result->return_code, '==', 3, "Both regex parameters" );
39like ( $result->output, $bothRegexOutput, "Output for unknown correct" );
40
41$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'Simple match'");
42cmp_ok( $result->return_code, '==', 0, "First time executing" );
43like ( $result->output, $firstTimeOutput, "Output for first time executing correct" );
44
45open(FH, '>>', $temp_file) or die $!;
46print FH "This is some text, that should not match\n";
47close(FH);
48
49$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'No match'");
50cmp_ok( $result->return_code, '==', 0, "No match" );
51like ( $result->output, $okOutput, "Output for no match correct" );
52
53open(FH, '>>', $temp_file) or die $!;
54print FH "This text should match\n";
55close(FH);
56
57$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'should match'");
58cmp_ok( $result->return_code, '==', 2, "Pattern match" );
59like ( $result->output, $criticalOutput, "Output for match correct" );
60
61open(FH, '>>', $temp_file) or die $!;
62print FH "This text should not match, because it is excluded\n";
63close(FH);
64
65$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'match' --exclude 'because'");
66cmp_ok( $result->return_code, '==', 0, "Exclude a pattern" );
67like ( $result->output, $okOutput, "Output for no match correct" );
68
69open(FH, '>>', $temp_file) or die $!;
70print FH "Trying\nwith\nmultiline\nignore me\n";
71close(FH);
72
73$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'Trying\\|with\\|multiline\\|ignore' --exclude 'me' --all");
74cmp_ok( $result->return_code, '==', 2, "Multiline pattern match with --all" );
75like ( $result->output, $multilineOutput, "Output for multiline match correct" );
76
77$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'match' -a");
78cmp_ok( $result->return_code, '==', 0, "Non matching --all" );
79like ( $result->output, $okOutput, "Output for no match correct" );
80
81unlink($oldlog);
82unlink($temp_file);
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
diff --git a/plugins-scripts/t/utils.t b/plugins-scripts/t/utils.t
index 9c2c569..5c23179 100644
--- a/plugins-scripts/t/utils.t
+++ b/plugins-scripts/t/utils.t
@@ -10,6 +10,7 @@ use strict;
10use Test::More; 10use Test::More;
11use NPTest; 11use NPTest;
12 12
13use lib ".";
13use lib ".."; 14use lib "..";
14use utils; 15use utils;
15 16