diff options
Diffstat (limited to 'plugins-scripts/t')
-rw-r--r-- | plugins-scripts/t/check_log.t | 82 | ||||
-rw-r--r-- | plugins-scripts/t/check_uptime.t | 22 |
2 files changed, 96 insertions, 8 deletions
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 | |||
7 | use strict; | ||
8 | use Test::More; | ||
9 | use NPTest; | ||
10 | |||
11 | my $tests = 18; | ||
12 | plan tests => $tests; | ||
13 | |||
14 | my $firstTimeOutput ='/^Log check data initialized/'; | ||
15 | my $okOutput = '/^Log check ok - 0 pattern matches found/'; | ||
16 | my $criticalOutput = '/^\(\d+\) < /'; | ||
17 | my $multilineOutput = '/\(3\) <.*\n.*\n.*$/'; | ||
18 | my $unknownOutput = '/^Usage: /'; | ||
19 | my $unknownArgOutput = '/^Unknown argument: /'; | ||
20 | my $bothRegexOutput = '/^Can not use extended and perl regex/'; | ||
21 | |||
22 | my $result; | ||
23 | my $temp_file = "/tmp/check_log.tmp"; | ||
24 | my $oldlog = "/tmp/oldlog.tmp"; | ||
25 | |||
26 | open(FH, '>', $temp_file) or die $!; | ||
27 | close(FH); | ||
28 | |||
29 | $result = NPTest->testCmd("./check_log"); | ||
30 | cmp_ok( $result->return_code, '==', 3, "Missing parameters" ); | ||
31 | like ( $result->output, $unknownOutput, "Output for unknown correct" ); | ||
32 | |||
33 | $result = NPTest->testCmd("./check_log -f"); | ||
34 | cmp_ok( $result->return_code, '==', 3, "Wrong parameters" ); | ||
35 | like ( $result->output, $unknownArgOutput, "Output for unknown correct" ); | ||
36 | |||
37 | $result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'Simple match' -e -p"); | ||
38 | cmp_ok( $result->return_code, '==', 3, "Both regex parameters" ); | ||
39 | like ( $result->output, $bothRegexOutput, "Output for unknown correct" ); | ||
40 | |||
41 | $result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'Simple match'"); | ||
42 | cmp_ok( $result->return_code, '==', 0, "First time executing" ); | ||
43 | like ( $result->output, $firstTimeOutput, "Output for first time executing correct" ); | ||
44 | |||
45 | open(FH, '>>', $temp_file) or die $!; | ||
46 | print FH "This is some text, that should not match\n"; | ||
47 | close(FH); | ||
48 | |||
49 | $result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'No match'"); | ||
50 | cmp_ok( $result->return_code, '==', 0, "No match" ); | ||
51 | like ( $result->output, $okOutput, "Output for no match correct" ); | ||
52 | |||
53 | open(FH, '>>', $temp_file) or die $!; | ||
54 | print FH "This text should match\n"; | ||
55 | close(FH); | ||
56 | |||
57 | $result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'should match'"); | ||
58 | cmp_ok( $result->return_code, '==', 2, "Pattern match" ); | ||
59 | like ( $result->output, $criticalOutput, "Output for match correct" ); | ||
60 | |||
61 | open(FH, '>>', $temp_file) or die $!; | ||
62 | print FH "This text should not match, because it is excluded\n"; | ||
63 | close(FH); | ||
64 | |||
65 | $result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'match' --exclude 'because'"); | ||
66 | cmp_ok( $result->return_code, '==', 0, "Exclude a pattern" ); | ||
67 | like ( $result->output, $okOutput, "Output for no match correct" ); | ||
68 | |||
69 | open(FH, '>>', $temp_file) or die $!; | ||
70 | print FH "Trying\nwith\nmultiline\nignore me\n"; | ||
71 | close(FH); | ||
72 | |||
73 | $result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'Trying\\|with\\|multiline\\|ignore' --exclude 'me' --all"); | ||
74 | cmp_ok( $result->return_code, '==', 2, "Multiline pattern match with --all" ); | ||
75 | like ( $result->output, $multilineOutput, "Output for multiline match correct" ); | ||
76 | |||
77 | $result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'match' -a"); | ||
78 | cmp_ok( $result->return_code, '==', 0, "Non matching --all" ); | ||
79 | like ( $result->output, $okOutput, "Output for no match correct" ); | ||
80 | |||
81 | unlink($oldlog); | ||
82 | unlink($temp_file); | ||
diff --git a/plugins-scripts/t/check_uptime.t b/plugins-scripts/t/check_uptime.t index c395307..6e81db3 100644 --- a/plugins-scripts/t/check_uptime.t +++ b/plugins-scripts/t/check_uptime.t | |||
@@ -5,7 +5,7 @@ | |||
5 | # | 5 | # |
6 | 6 | ||
7 | use strict; | 7 | use strict; |
8 | use Test::More tests => 40; | 8 | use Test::More tests => 42; |
9 | use NPTest; | 9 | use NPTest; |
10 | 10 | ||
11 | my $result; | 11 | my $result; |
@@ -46,29 +46,35 @@ cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" ); | |||
46 | like ( $result->output, '/Running since \d+/', "Output for the s parameter correct" ); | 46 | like ( $result->output, '/Running since \d+/', "Output for the s parameter correct" ); |
47 | 47 | ||
48 | $result = NPTest->testCmd( | 48 | $result = NPTest->testCmd( |
49 | "./check_uptime -d -w 1 -c 2" | ||
50 | ); | ||
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" ); | ||
53 | |||
54 | $result = NPTest->testCmd( | ||
49 | "./check_uptime -w 1 -c 2" | 55 | "./check_uptime -w 1 -c 2" |
50 | ); | 56 | ); |
51 | cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" ); | 57 | cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" ); |
52 | like ( $result->output, '/^CRITICAL: uptime is \d+ seconds/', "Output for uptime higher than 2 seconds correct" ); | 58 | like ( $result->output, '/^CRITICAL: Uptime is \d+ seconds/', "Output for uptime higher than 2 seconds correct" ); |
53 | 59 | ||
54 | $result = NPTest->testCmd( | 60 | $result = NPTest->testCmd( |
55 | "./check_uptime -w 1 -c 9999w" | 61 | "./check_uptime -w 1 -c 9999w" |
56 | ); | 62 | ); |
57 | cmp_ok( $result->return_code, '==', 1, "Uptime lower than 9999 weeks" ); | 63 | cmp_ok( $result->return_code, '==', 1, "Uptime lower than 9999 weeks" ); |
58 | like ( $result->output, '/^WARNING: uptime is \d+ seconds/', "Output for uptime lower than 9999 weeks correct" ); | 64 | like ( $result->output, '/^WARNING: Uptime is \d+ seconds/', "Output for uptime lower than 9999 weeks correct" ); |
59 | 65 | ||
60 | $result = NPTest->testCmd( | 66 | $result = NPTest->testCmd( |
61 | "./check_uptime -w 9998w -c 9999w" | 67 | "./check_uptime -w 9998w -c 9999w" |
62 | ); | 68 | ); |
63 | cmp_ok( $result->return_code, '==', 0, "Uptime lower than 9998 weeks" ); | 69 | cmp_ok( $result->return_code, '==', 0, "Uptime lower than 9998 weeks" ); |
64 | like ( $result->output, '/^OK: uptime is \d+ seconds/', "Output for uptime lower than 9998 weeks correct" ); | 70 | like ( $result->output, '/^OK: Uptime is \d+ seconds/', "Output for uptime lower than 9998 weeks correct" ); |
65 | like ( $result->output, '/\|uptime=[0-9]+s;6046790400;6047395200;/', "Checking for performance output" ); | 71 | like ( $result->output, '/\|uptime=[0-9]+s;6046790400;6047395200;/', "Checking for performance output" ); |
66 | 72 | ||
67 | $result = NPTest->testCmd( | 73 | $result = NPTest->testCmd( |
68 | "./check_uptime -w 111222d -c 222333d" | 74 | "./check_uptime -w 111222d -c 222333d" |
69 | ); | 75 | ); |
70 | cmp_ok( $result->return_code, '==', 0, "Uptime lower than 111222 days" ); | 76 | cmp_ok( $result->return_code, '==', 0, "Uptime lower than 111222 days" ); |
71 | like ( $result->output, '/^OK: uptime is \d+ seconds/', "Output for uptime lower than 111222 days correct" ); | 77 | like ( $result->output, '/^OK: Uptime is \d+ seconds/', "Output for uptime lower than 111222 days correct" ); |
72 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); | 78 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); |
73 | 79 | ||
74 | # Same as before, hopefully uptime is higher than 2 seconds so no warning | 80 | # Same as before, hopefully uptime is higher than 2 seconds so no warning |
@@ -76,7 +82,7 @@ $result = NPTest->testCmd( | |||
76 | "./check_uptime -w 2:111222d -c 1:222333d" | 82 | "./check_uptime -w 2:111222d -c 1:222333d" |
77 | ); | 83 | ); |
78 | cmp_ok( $result->return_code, '==', 0, "Uptime lower than 111222 days, and higher 2 seconds" ); | 84 | cmp_ok( $result->return_code, '==', 0, "Uptime lower than 111222 days, and higher 2 seconds" ); |
79 | like ( $result->output, '/^OK: uptime is \d+ seconds/', "Output for uptime lower than 111222 days, and higher 2 seconds correct" ); | 85 | like ( $result->output, '/^OK: Uptime is \d+ seconds/', "Output for uptime lower than 111222 days, and higher 2 seconds correct" ); |
80 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); | 86 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); |
81 | 87 | ||
82 | # Same as before, now the low warning should trigger | 88 | # Same as before, now the low warning should trigger |
@@ -84,7 +90,7 @@ $result = NPTest->testCmd( | |||
84 | "./check_uptime -w 111221d:111222d -c 1:222333d" | 90 | "./check_uptime -w 111221d:111222d -c 1:222333d" |
85 | ); | 91 | ); |
86 | cmp_ok( $result->return_code, '==', 1, "Uptime lower than 111221 days raises warning" ); | 92 | cmp_ok( $result->return_code, '==', 1, "Uptime lower than 111221 days raises warning" ); |
87 | like ( $result->output, '/^WARNING: uptime is \d+ seconds/', "Output for uptime lower than 111221 days correct" ); | 93 | like ( $result->output, '/^WARNING: Uptime is \d+ seconds/', "Output for uptime lower than 111221 days correct" ); |
88 | like ( $result->output, '/Exceeds lower warn threshold/', "Exceeds text correct" ); | 94 | like ( $result->output, '/Exceeds lower warn threshold/', "Exceeds text correct" ); |
89 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); | 95 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); |
90 | 96 | ||
@@ -93,7 +99,7 @@ $result = NPTest->testCmd( | |||
93 | "./check_uptime -w 111221d:111222d -c 111220d:222333d" | 99 | "./check_uptime -w 111221d:111222d -c 111220d:222333d" |
94 | ); | 100 | ); |
95 | cmp_ok( $result->return_code, '==', 2, "Uptime lower than 111220 days raises critical" ); | 101 | cmp_ok( $result->return_code, '==', 2, "Uptime lower than 111220 days raises critical" ); |
96 | like ( $result->output, '/^CRITICAL: uptime is \d+ seconds/', "Output for uptime lower than 111220 days correct" ); | 102 | like ( $result->output, '/^CRITICAL: Uptime is \d+ seconds/', "Output for uptime lower than 111220 days correct" ); |
97 | like ( $result->output, '/Exceeds lower crit threshold/', "Exceeds text correct" ); | 103 | like ( $result->output, '/Exceeds lower crit threshold/', "Exceeds text correct" ); |
98 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); | 104 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); |
99 | 105 | ||