summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlorenzg <lorenz.gruenwald@consol.de>2023-01-20 07:52:38 (GMT)
committerSven Nierlein <sven@nierlein.org>2023-01-20 08:11:26 (GMT)
commitc410ad38798fde8cc278a3f1522a9571dbdb7fae (patch)
tree8ec84205e9b2ba494ba61c22831ddb5264ebf0e6
parentb153a8c499802c2fdba199e84f5f7426ff4c0748 (diff)
downloadmonitoring-plugins-c410ad3.tar.gz
add tests for check_log
-rw-r--r--plugins-scripts/t/check_log.t82
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
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);