File: 071biggzrotation.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 (129 lines) | stat: -rw-r--r-- 3,726 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/perl -w
#
# ~/check_logfiles/test/071biggzrotation.t
#
#  Test the capability of finding rotated logfiles.
#

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

if ($^O =~ /MSWin/) {
  # in a desperate attempt...
  $ENV{PATH} = $ENV{PATH}.';C:\Programme\cygwin\bin;C:\cygwin\bin';
}

my $cl = Nagios::CheckLogfiles::Test->new({
        protocolsdir => TESTDIR."/var/tmp",
        seekfilesdir => TESTDIR."/var/tmp",
        searches => [
            {
              tag => "bigssh",
              logfile => TESTDIR."/var/adm/messages",
              criticalpatterns => "Failed password",
              warningpatterns => "Unknown user",
              rotation => "SOLARIS",
            }
        ]    });
my $bigssh = $cl->get_search_by_tag("bigssh");
$bigssh->delete_logfile();
$bigssh->delete_seekfile();
$bigssh->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.
$bigssh->logger(undef, undef, 2, "Failed password for invalid user1");
sleep 1;
$bigssh->trace("initial run");
$cl->run();
diag($cl->has_result());
diag($cl->{exitmessage});
ok($cl->expect_result(0, 0, 0, 0, 0));

# now find the two criticals
$bigssh->trace("==== 2 ====");
$cl->reset();
rename "./var/adm/messages", "./var/adm/messages2";
#system("mv ./var/adm/messages ./var/adm/messages2");
$bigssh->loggercrap(undef, undef, 100);
$bigssh->logger(undef, undef, 2, "Failed password for invalid user2");
$bigssh->loggercrap(undef, undef, 100);
diag("logging big amounts of data");
$bigssh->loggercrap(undef, undef, 100000);
open CACA, ">>xyxy";
open MSG, "./var/adm/messages";
while (<MSG>) {
  print CACA $_;
}
close CACA;
close MSG;
#system("cat ./var/adm/messages >> xyxy");
my $size = (stat("./var/adm/messages"))[7];
my $errcnt = 1;
$bigssh->{max_readsize} = 1024 * 1024 ;
while ($size < $bigssh->{max_readsize}) {
  open CACA, ">>xyxy";
  open MSG, "./var/adm/messages";
  while (<MSG>) {
    print CACA $_;
  }
  close CACA;
  close MSG;
  #system("cat ./var/adm/messages >> xyxy");
  $size = (stat("xyxy"))[7];
  $errcnt++;
}
open CACA, ">>xyxy";
open MSG, "./var/adm/messages";
while (<MSG>) {
  print CACA $_;
}
close CACA;
close MSG;
#system("cat ./var/adm/messages >> xyxy");
$errcnt++;
$size = (stat("xyxy"))[7];
open CACA, "xyxy";
open MSG, ">>./var/adm/messages2";
while (<CACA>) {
  print MSG $_;
}
close CACA;
close MSG;
#system("cat xyxy >> ./var/adm/messages2");
rename "./var/adm/messages2", "./var/adm/messages";
#system("mv ./var/adm/messages2 ./var/adm/messages");
unlink("xyxy");
diag(sprintf "i wrote the messages %d times", $errcnt);
diag(sprintf "size is %u\n", $size);
diag(sprintf "maxs is %u\n", $bigssh->{max_readsize});
sleep 1;
diag("now position at a low offset and scan through a big file");
$cl->run();
diag("now a big offset was saved");
diag($cl->has_result());
diag($cl->{exitmessage});
diag(sprintf "i expect %d errors", 2 * $errcnt);
ok($cl->expect_result(0, 0, 2 * $errcnt, 0, 2));
system("cat ./var/tmp/check_logfiles.._var_adm_messages.bigssh");

# now flood the log, rotate and find the two new criticals
$bigssh->trace("==== 3 ====");
$bigssh->loggercrap(undef, undef, 100);
$bigssh->rotate_compress(); # mess -> mess.0
$bigssh->loggercrap(undef, undef, 100);
$bigssh->rotate_compress(); # mess.0 -> mess.1.gz
$cl->reset();
$bigssh->loggercrap(undef, undef, 100);
$bigssh->logger(undef, undef, 2, "Failed password for invalid user3");
$bigssh->loggercrap(undef, undef, 100);
sleep 1;
$cl->run();
diag($cl->has_result());
diag($cl->{exitmessage});
ok($cl->expect_result(0, 0, 2, 0, 2));