File: 015timeout.t

package info (click to toggle)
monitoring-plugins-check-logfiles 4.1.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,024 kB
  • sloc: perl: 19,496; sh: 3,422; makefile: 72; awk: 41
file content (73 lines) | stat: -rw-r--r-- 1,721 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
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/perl -w
#
# ~/check_logfiles/test/005negative.t
#
#  Test that all the Perl modules we require are available.
#

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

my $configfile = <<EOCFG;
\$protocolsdir = "./var/tmp";
\$seekfilesdir = "./var/tmp";
\$scriptpath = "./bin";
\@searches = (
    {
      tag => "action",
      protocolsdir => "./var/tmp",
      logfile => "./var/adm/messages",
      criticalpatterns => [ 
             '.*ERROR.*',
         ], 
         options => 'script',
         script => "send_snmptrap"
    },
    {
      tag => "action2",
      protocolsdir => "./var/tmp",
      logfile => "./var/adm/messages",
      criticalpatterns => [ 
             '.*ERROR.*',
         ], 
         options => 'script',
         script => "send_snmptrap"
    },
);
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("action");
my $action2 = $cl->get_search_by_tag("action2");
$action->delete_seekfile();
$action2->delete_seekfile();
$action->loggercrap(undef, undef, 100);
$action2->loggercrap(undef, undef, 100);
$cl->run(); #init
sleep 1;
$cl->reset();
$action->{script} = sub {
  sleep 5;
  return 3;
};
$action2->{script} = sub {
  sleep 1;
  return 3;
};
$action->loggercrap(undef, undef, 100);
$action->logger(undef, undef, 10, " ERROR ");
$action->loggercrap(undef, undef, 100);
sleep 1;
$cl->{timeout} = 10;
my $now = time;
$cl->run();
my $elapsed = time - $now;
diag(sprintf "aborted after %d seconds", $elapsed);
ok($elapsed > 16 && $elapsed < 20);