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
|
#!/usr/bin/perl -w
#
# ~/check_logfiles/test/033wagnermacros.t
#
# Test that all the Perl modules we require are available.
#
use strict;
use Test::More tests => 3;
use Cwd;
use lib "../plugins-scripts";
use Nagios::CheckLogfiles::Test;
use Net::Domain qw(hostname hostdomain hostfqdn);
use Socket;
use constant TESTDIR => ".";
#
# some macros in patterns
# some search specific macros
# a dynamically named logfile
# test also an external config file
#
#
my $cl = Nagios::CheckLogfiles::Test->new({
protocolsdir => TESTDIR."/var/tmp",
seekfilesdir => TESTDIR."/var/tmp",
macros => { CL_VG00 => '/dev/vg00', CL_VG => '/dev/vg' },
searches => [
{
tag => 'Maestro',
logfile => '/tmp/mytest/out.log',
criticalpatterns => ['exception'],
options => 'script,nocase',
script => 'nagmsg',
scriptparams => '-n chaos -m $CL_TAG$ -s warning -t "$CL_SERVICEOUTPUT$"',
},
{
tag => 'BACKUP',
logfile => '/tmp/mytest/ou',
rotation => '.*out\d.log',
type => 'rotating::uniform',
criticalpatterns => ['gaga','markus'],
options => 'script,nocase',
script => 'nagmsg',
scriptparams => '-n chaos -m $CL_TAG$ -s critical -t "$CL_SERVICEOUTPUT$"',
},
]
});
my $maestro = $cl->get_search_by_tag("Maestro");
my $backup = $cl->get_search_by_tag("BACKUP");
$maestro->delete_logfile();
$maestro->delete_seekfile();
$backup->delete_logfile();
$backup->delete_seekfile();
ok($maestro->{tag} eq $maestro->{macros}->{CL_TAG});
ok($backup->{tag} eq $backup->{macros}->{CL_TAG});
my $scriptparams = $backup->{scriptparams};
$backup->resolve_macros(\$scriptparams);
diag($scriptparams);
ok($scriptparams eq '-n chaos -m BACKUP -s critical -t "$CL_SERVICEOUTPUT$"');
|