File: 081rununique.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 (67 lines) | stat: -rw-r--r-- 1,629 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
#!/usr/bin/perl -w
#
# ~/check_logfiles/test/050perms.t
#
#  Test that all the Perl modules we require are available.
#

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

my $configfile = <<EOCFG;
\$options = "rununique";
\$protocolsdir = "./var/tmp";
\$seekfilesdir = "./var/tmp";
\@searches = (
    {
      tag => "unique",
      logfile => "./var/adm/messages",
      criticalpatterns => [
          'blabla',
      ],
});

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

my $cl = Nagios::CheckLogfiles::Test->new({ cfgfile => "./etc/check_action.cfg" });
my $pidfile = $cl->construct_pidfile();
diag($pidfile);

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';
 }
}
my $command = $perlpath.' ../plugins-scripts/check_logfiles --config ./etc/check_action.cfg --rununique';
if ($^O =~ /MSWin/) {
 $command =~ s/\//\\/g;
}
my $output = `$command`;
diag($command);
diag($output);
ok(($output =~ /OK - no errors or warnings/) && (($? >> 8) == 0));

open PID, ">$pidfile";
close PID;
ok(-e $pidfile, "pidfile exists");
$output = `$command`;
diag($output);
ok(($output =~ /Exiting because another check is already running/), "aborts correctly");
ok(($output =~ /Exiting because another check is already running/) && (($? >> 8) == 3));

unlink $pidfile;
$output = `$command`;
diag($output);
ok(($output =~ /OK - no errors or warnings/) && (($? >> 8) == 0));