File: 025commandline.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 (112 lines) | stat: -rw-r--r-- 3,744 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
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
107
108
109
110
111
112
#!/usr/bin/perl -w
#
# ~/check_logfiles/test/025commandline.t
#
#  Test the capability of finding rotated logfiles with the commandline.
#

#
# problem: the test script is ran under cygwin, but the check_logfiles is
# a native active state perl script.
# once /tmp, then TEMP is used as seekfilesdir, so the seekfiles are 
# not deleted properly
#
use strict;
use Test::More tests => 5;
use Cwd;
use lib "../plugins-scripts";
use Nagios::CheckLogfiles::Test;
use constant TESTDIR => ".";

my $cl = Nagios::CheckLogfiles::Test->new({
        protocolsdir => ($^O =~/MSWin/) ? 'C:\TEMP' : '/tmp',
        seekfilesdir => ($^O =~/MSWin/) ? 'C:\TEMP' : '/tmp',
        searches => [
            {
              tag => "ssh",
              logfile => TESTDIR."/var/adm/messages",
              criticalpatterns => "Failed password",
              warningpatterns => "Unknown user",
              rotation => "SOLARIS",
            }
        ]    });
my $ssh = $cl->get_search_by_tag("ssh");
$ssh->trace("starting.............%s", $cl->{seekfilesdir});
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';
 }
  $ssh->{logfile} =~ s/\//\\/g;
}
my $command = sprintf $perlpath.' ../plugins-scripts/check_logfiles --tag=%s --criticalpattern="%s" --warningpattern="%s" --rotation=%s --logfile=%s --seekfilesdir %s',
    $ssh->{tag}, $ssh->{patterns}->{CRITICAL}->[0], 
    $ssh->{patterns}->{WARNING}->[0],
    $ssh->{rotation}, $ssh->{logfile}, $cl->{seekfilesdir};
diag($command);
$ssh->trace("executing %s", $command);
$ssh->trace("deleting logfile and seekfile");
$ssh->delete_logfile();
$ssh->delete_seekfile();
$ssh->trace("deleted logfile and seekfile");
 
# logfile will be created. there is no seekfile. position at the end of file
# and remember this as starting point for the next run.
$ssh->trace("==== 1 ====");
$ssh->logger(undef, undef, 2, "Failed password for invalid user1");
my $output = `$command`;
diag($output);
ok(($output =~ /OK - no errors or warnings/) && (($? >> 8) == 0));

# now find the two criticals
$ssh->trace("==== 2 ====");
$cl->reset();
sleep 1; # if not, cygwin says "Log file has the same modified time"
#$ssh->loggercrap(undef, undef, 100);
$ssh->logger(undef, undef, 2, "Failed password for invalid user2");
#$ssh->loggercrap(undef, undef, 100);
system("ls -l var/adm/messages");
system("cat var/adm/messages");
$output = `$command`;
diag($output);
ok(($output =~ /CRITICAL - \(2 errors in/) && (($? >> 8) == 2));

# now find the two criticals without a protocol
$ssh->trace("==== 3 ====");
$cl->reset();
sleep 1;
$ssh->loggercrap(undef, undef, 100);
$ssh->logger(undef, undef, 2, "Failed password for invalid user3");
$ssh->loggercrap(undef, undef, 100);
sleep 1;
$output = `$command --noprotocol`;
diag($output);
ok(($output =~ /CRITICAL - \(2 errors\)/) && (($? >> 8) == 2));

 
# now rotate and find the two new criticals
$ssh->trace("==== 4 ====");
$ssh->rotate();
$cl->reset();
$ssh->loggercrap(undef, undef, 100);
$ssh->logger(undef, undef, 2, "Failed password for invalid user4");
$ssh->loggercrap(undef, undef, 100);
$output = `$command`;
diag($output);
ok(($output =~ /CRITICAL - \(2 errors in/) && (($? >> 8) == 2));

# now rotate and find the two new criticals but without perfdata
$ssh->trace("==== 5 ====");
$ssh->rotate();
$cl->reset();
$ssh->loggercrap(undef, undef, 100);
$ssh->logger(undef, undef, 2, "Failed password for invalid user5");
$ssh->loggercrap(undef, undef, 100);
$output = `$command --noperfdata`;
diag($output);
ok(($output =~ /CRITICAL - \(2 errors in.*\.\.\./) && (($? >> 8) == 2));
$ssh->delete_logfile();
$ssh->delete_seekfile();