diff options
author | Kristian Schuster <116557017+KriSchu@users.noreply.github.com> | 2023-02-19 22:49:18 (GMT) |
---|---|---|
committer | Kristian Schuster <116557017+KriSchu@users.noreply.github.com> | 2023-02-19 22:49:18 (GMT) |
commit | a0d42777217296c0a7bdb1e1be8d8f6de1b24dd7 (patch) | |
tree | 8effe94c57b2f9796ba36090b07551baa8f1e1cb /plugins-scripts/t | |
parent | ca3d59cd6918c9e2739e783b721d4c1122640fd3 (diff) | |
parent | c07206f2ccc2356aa74bc6813a94c2190017d44e (diff) | |
download | monitoring-plugins-a0d42777217296c0a7bdb1e1be8d8f6de1b24dd7.tar.gz |
Merge remote-tracking branch 'origin/master' into feature_check_disk_add_ignore_missing_option
Diffstat (limited to 'plugins-scripts/t')
-rw-r--r-- | plugins-scripts/t/check_log.t | 82 |
1 files changed, 82 insertions, 0 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); | ||