File: 090matches.t

package info (click to toggle)
monitoring-plugins-check-logfiles 4.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,992 kB
  • sloc: perl: 19,492; sh: 3,422; makefile: 72; awk: 41
file content (63 lines) | stat: -rw-r--r-- 1,728 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl -w
#
# ~/check_logfiles/test/016smartaction.t
#
#  Test that all the Perl modules we require are available.
#

use strict;
use Test::More tests => 2;
use Cwd;
use lib "../plugins-scripts";
use Nagios::CheckLogfiles::Test;
use constant TESTDIR => ".";

my $configfile = <<EOCFG;
\$protocolsdir = "./var/tmp";
\$seekfilesdir = "./var/tmp";
\$options = "smartprescript,smartpostscript";
\@searches = (
    {
      tag => "smart",
      logfile => "./var/adm/messages",
      criticalpatterns => [
          'bla ((pat1) blub (pat2.*)) bla',
      ],
      options => 'smartscript,capturegroups,noprotocol',
      script => "script.sh"
});

EOCFG
open CCC, ">./etc/check_action.cfg";
print CCC $configfile;
close CCC;

my $cl = Nagios::CheckLogfiles::Test->new({ cfgfile => "./etc/check_action.cfg" });
my $action = $cl->get_search_by_tag("smart");
$action->{script} = sub {
    my $num = $ENV{CHECK_LOGFILES_CAPTURE_GROUPS};
    printf "%d:pat1(%s)pat2(%s)pat3(%s)", 
        $ENV{CHECK_LOGFILES_CAPTURE_GROUPS},
        $ENV{CHECK_LOGFILES_CAPTURE_GROUP1},
        $ENV{CHECK_LOGFILES_CAPTURE_GROUP2},
        $ENV{CHECK_LOGFILES_CAPTURE_GROUP3};
    return 2;
};
$action->{options}->{supersmartscript} = 1;
$action->{options}->{smartscript} = 1;
$action->{options}->{script} = 1;
$cl->run(); #init
$cl->reset();
$cl->run();
$action->loggercrap(undef, undef, 100);
$action->logger(undef, undef, 1, "bla pat1 blub pat2kaas bla");
$action->loggercrap(undef, undef, 100);
sleep 1;
$cl->run();
#$action->dump_protocol();
diag($cl->has_result());
diag($cl->{exitmessage});

ok($cl->{exitmessage} eq "CRITICAL - (1 errors) - 3:pat1(pat1 blub pat2kaas)pat2(pat1)pat3(pat2kaas) ");
ok($cl->expect_result(0, 0, 1, 0, 2));