summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/t/check_log.t
blob: b66e0fd887a12330f6c9a4579bd1966481214785 (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
#!/usr/bin/perl -w -I ..
#
# check_log tests
#
#

use strict;
use Test::More;
use NPTest;

my $tests = 18;
plan tests => $tests;

my $firstTimeOutput ='/^Log check data initialized/';
my $okOutput = '/^Log check ok - 0 pattern matches found/';
my $criticalOutput = '/^\(\d+\) < /';
my $multilineOutput = '/\(3\) <.*\n.*\n.*$/';
my $unknownOutput = '/^Usage: /';
my $unknownArgOutput = '/^Unknown argument: /';
my $bothRegexOutput = '/^Can not use extended and perl regex/';

my $result;
my $temp_file = "/tmp/check_log.tmp";
my $oldlog = "/tmp/oldlog.tmp";

open(FH, '>', $temp_file) or die $!;
close(FH);

$result = NPTest->testCmd("./check_log");
cmp_ok( $result->return_code, '==', 3, "Missing parameters" );
like  ( $result->output, $unknownOutput, "Output for unknown correct" );

$result = NPTest->testCmd("./check_log -f");
cmp_ok( $result->return_code, '==', 3, "Wrong parameters" );
like  ( $result->output, $unknownArgOutput, "Output for unknown correct" );

$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'Simple match' -e -p");
cmp_ok( $result->return_code, '==', 3, "Both regex parameters" );
like  ( $result->output, $bothRegexOutput, "Output for unknown correct" );

$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'Simple match'");
cmp_ok( $result->return_code, '==', 0, "First time executing" );
like  ( $result->output, $firstTimeOutput, "Output for first time executing correct" );

open(FH, '>>', $temp_file) or die $!;
print FH "This is some text, that should not match\n";
close(FH);

$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'No match'");
cmp_ok( $result->return_code, '==', 0, "No match" );
like  ( $result->output, $okOutput, "Output for no match correct" );

open(FH, '>>', $temp_file) or die $!;
print FH "This text should match\n";
close(FH);

$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'should match'");
cmp_ok( $result->return_code, '==', 2, "Pattern match" );
like  ( $result->output, $criticalOutput, "Output for match correct" );

open(FH, '>>', $temp_file) or die $!;
print FH "This text should not match, because it is excluded\n";
close(FH);

$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'match' --exclude 'because'");
cmp_ok( $result->return_code, '==', 0, "Exclude a pattern" );
like  ( $result->output, $okOutput, "Output for no match correct" );

open(FH, '>>', $temp_file) or die $!;
print FH "Trying\nwith\nmultiline\nignore me\n";
close(FH);

$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'Trying\\|with\\|multiline\\|ignore' --exclude 'me' --all");
cmp_ok( $result->return_code, '==', 2, "Multiline pattern match with --all" );
like  ( $result->output, $multilineOutput, "Output for multiline match correct" );

$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'match' -a");
cmp_ok( $result->return_code, '==', 0, "Non matching --all" );
like  ( $result->output, $okOutput, "Output for no match correct" );

unlink($oldlog);
unlink($temp_file);