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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
#!/usr/bin/perl -w
#
# ~/check_logfiles/test/001simple.t
#
# Test that all the Perl modules we require are available.
#
use strict;
use Test::More tests => 4;
use Cwd;
use lib "../plugins-scripts";
use Nagios::CheckLogfiles::Test;
use constant TESTDIR => ".";
my $configfile = <<EOCFG;
\$protocolsdir = "./var/tmp";
\$seekfilesdir = "./var/tmp";
\@searches = ({
tag => "html",
logfile => "./var/adm/messages",
criticalpatterns => ["head.*body"],
});
EOCFG
open CCC, ">./etc/check_html.cfg";
print CCC $configfile;
close CCC;
my $cl = Nagios::CheckLogfiles::Test->new({
protocolsdir => "./var/tmp",
seekfilesdir => "./var/tmp",
searches => [
{
tag => "html",
logfile => "./var/adm/messages",
criticalpatterns => ["head.*body"],
}
] });
my $html = $cl->get_search_by_tag("html");
my $perlpath = `which perl`;
chomp $perlpath;
if ($^O =~ /MSWin/) {
if (-f 'C:\strawberry\perl\bin\perl.exe') {
$perlpath = 'C:\strawberry\perl\bin\perl';
} else {
$perlpath = 'C:\Perl\bin\perl';
}
$html->{logfile} =~ s/\//\\/g;
}
$cl->delete_file("./var/adm/messages");
$cl->delete_file("./var/tmp/check_html.._var_adm_messages.html");
$html->trace("deleted logfile and seekfile");
$html->logger(undef, undef, 1, "<head title=\"bled\">A&B</head><body title='bb'>");
my $command = sprintf $perlpath.' ../plugins-scripts/check_logfiles --config=etc/check_html.cfg ';
my $output = `$command`;
diag($output);
ok(($output =~ /OK - no errors or warnings/) && (($? >> 8) == 0));
# 1 critical
$html->trace(sprintf "+----------------------- test %d ------------------", 2);
$html->logger(undef, undef, 1, "<head title=\"bled\">A&B</head><body title='bb'>");
sleep 1;
$output = `$command`;
diag($output);
ok(($output =~ /<head title="bled">A&B<\/head><body title='bb'>/) && (($? >> 8) == 2));
sleep 1;
printf STDERR "now i add --htmlencode\n";
diag($command." --htmlencode");
$html->trace(sprintf "+----------------------- test %d ------------------", 2);
$html->logger(undef, undef, 1, "<head title=\"bled\">A&B</head><body title='bb'>");
sleep 1;
### zuletzt und command neu aufbauen ohne cfgfile nur options
$output = `$command --htmlencode`;
diag($output);
ok(($output =~ /<head title="bled">A&B<\/head><body title='bb'>/) && (($? >> 8) == 2));
printf STDERR "now i add options/htmlencode\n";
$configfile = <<EOCFG;
\$protocolsdir = "./var/tmp";
\$seekfilesdir = "./var/tmp";
\@searches = ({
tag => "html",
logfile => "./var/adm/messages",
criticalpatterns => ["head.*body"],
});
\$options = "htmlencode";
EOCFG
open CCC, ">./etc/check_html.cfg";
print CCC $configfile;
close CCC;
# 1 critical
$html->trace(sprintf "+----------------------- test %d ------------------", 2);
$html->logger(undef, undef, 1, "<head title=\"bled\">A&B</head><body title='bb'>");
sleep 1;
diag($command);
$output = `$command`;
diag($output);
ok(($output =~ /<head title="bled">A&B<\/head><body title='bb'>/) && (($? >> 8) == 2));
|