File: 060templates.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 (219 lines) | stat: -rw-r--r-- 7,611 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/usr/bin/perl -w
#
# ~/check_logfiles/test/060templates.t
#
#  Test logfiles which will be deleted and recreated instead of rotated.
#

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

my $configfile =<<EOCFG;	
	\$protocolsdir = "./var/tmp";
	\$seekfilesdir = "./var/tmp";
	\@searches = (
	    {
	      template => "outlook",
	      logfile => "./var/adm/messages",
	      criticalpatterns => "mailbox corrupt",
	      warningpatterns => "mailbox full",
	      options => 'perfdata,syslogclient=\$CL_TAG\$'
	    },
	    {
	      template => "excel",
	      logfile => "./var/adm/messages",
	      criticalpatterns => "oo file found",
	      options => 'perfdata,syslogclient=\$CL_TAG\$'
	    },
	    {
	      tag => "simple",
	      logfile => "./var/adm/messages",
	      criticalpatterns => "Failed password",
	      warningpatterns => "Unknown user",
	      options => "perfdata"
	    });
EOCFG

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

$configfile =<<EOCFG;	
	\$protocolsdir = "./var/tmp";
	\$seekfilesdir = "./var/tmp";
	\@searches = (
	    {
	      template => "outlook",
	      logfile => "./var/adm/messages",
	      criticalpatterns => "mailbox corrupt",
	      warningpatterns => "mailbox full",
	      options => 'perfdata,syslogclient=\$CL_TAG\$'
	    },
	    {
	      template => "excel",
	      logfile => "./var/adm/messages",
	      criticalpatterns => "oo file found",
	      options => 'perfdata,syslogclient=\$CL_TAG\$'
	    },
	    {
	      tag => "simple",
	      logfile => "./var/adm/messages",
	      criticalpatterns => "Failed password",
	      warningpatterns => "Unknown user",
	      options => "perfdata"
	    });
EOCFG

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

my $cl0815 = Nagios::CheckLogfiles::Test->new({ 
	cfgfile => "./etc/templates.cfg",
    selectedsearches => ['excel', 'outlook'],
    dynamictag => 'pc0815.muc' });
printf STDERR "%s\n", $Nagios::CheckLogfiles::ExitMsg;
#printf STDERR "%s", Data::Dumper::Dumper($cl0815);

my $cl4711 = Nagios::CheckLogfiles::Test->new({ 
	cfgfile => "./etc/templates.cfg",
    selectedsearches => ['excel', 'outlook'],
    dynamictag => 'pc4711.muc' });  
    
my $clall = Nagios::CheckLogfiles::Test->new({ 
	cfgfile => "./etc/templates.cfg",
    dynamictag => 'pc4711.muc' });  
ok(scalar(@{$clall->{searches}}) == 3);
    
my $clsimple = Nagios::CheckLogfiles::Test->new({ 
	cfgfile => "./etc/templates.cfg", });
diag(sprintf "clsimple has %d searches", scalar(@{$clsimple->{searches}}));
ok(scalar(@{$clsimple->{searches}}) == 1);

my $outlook0815 = $cl0815->get_search_by_template("outlook");
my $excel0815 = $cl0815->get_search_by_template("excel");
my $outlook4711 = $cl4711->get_search_by_template("outlook");
my $excel4711 = $cl4711->get_search_by_template("excel");

foreach my $cl ($cl0815, $cl4711, $clall, $clsimple) {
  foreach my $s (@{$cl->{searches}}) {
  	$s->delete_seekfile();
  	$s->delete_logfile();
  }
}

$cl0815->run();
$cl4711->run();
$clall->run();
$clsimple->run();

# check the creation of the right seekfiles
ok(-f "./var/tmp/templates.._var_adm_messages.outlook_pc0815.muc");
ok(-f "./var/tmp/templates.._var_adm_messages.outlook_pc4711.muc");
ok(-f "./var/tmp/templates.._var_adm_messages.excel_pc0815.muc");
ok(-f "./var/tmp/templates.._var_adm_messages.excel_pc4711.muc");
ok(-f "./var/tmp/templates.._var_adm_messages.simple");
foreach my $cl ($cl0815, $cl4711, $clall, $clsimple) {
  foreach my $s (@{$cl->{searches}}) {
  	$s->delete_seekfile();
  }
}

ok(! -f "./var/tmp/templates.._var_adm_messages.outlook_pc0815.muc");
ok(! -f "./var/tmp/templates.._var_adm_messages.outlook_pc4711.muc");
ok(! -f "./var/tmp/templates.._var_adm_messages.excel_pc0815.muc");
ok(! -f "./var/tmp/templates.._var_adm_messages.excel_pc4711.muc");

# reset counters
$cl0815->run();
$cl4711->run();
$clall->run();
$clsimple->run();

$outlook0815->logger(undef, undef, 4, "pc0815.muc: Failed password");
$outlook0815->logger(undef, undef, 2, "pc4711.muc: Failed password");
$outlook0815->logger(undef, undef, 4, "pc0815.muc: mailbox corrupt");
$outlook0815->loggercrap(undef, undef, 20);
$outlook0815->logger(undef, undef, 4, "pc0815.muc: mailbox full");
$outlook0815->loggercrap(undef, undef, 20);
$outlook0815->logger(undef, undef, 4, "pc04711.muc: ramsch");
$outlook0815->loggercrap(undef, undef, 20);
$outlook0815->logger(undef, undef, 14, "pc4711.muc: mailbox full");
$outlook0815->loggercrap(undef, undef, 20);
$outlook0815->logger(undef, undef, 4, "pc4711.muc: excel oo file found");
$outlook0815->loggercrap(undef, undef, 20);
$outlook0815->logger(undef, undef, 4, "pc4711.muc: outlook mailbox full");
$outlook0815->loggercrap(undef, undef, 20);

$cl0815->reset();
$cl0815->run(); 
$cl4711->reset();
$cl4711->run();
$clall->reset();
$clall->run();
$clsimple->reset();
$clsimple->run();
# 4 mailb corr, 4 mailb full
diag($cl0815->has_result());
diag($cl0815->{exitmessage});
ok($cl0815->expect_result(0, 4, 4, 0, 2));
ok($cl0815->{exitmessage} =~ /CRITICAL - \(4 errors, 4 warnings.* - .* mailbox corrupt /);
diag($cl4711->has_result());
diag($cl4711->{exitmessage});
ok($cl4711->expect_result(0, 18, 4, 0, 2));
ok($cl4711->{exitmessage} =~ /CRITICAL - \(4 errors, 18 warnings.* - .* oo file .* /);
diag($clall->has_result());
diag($clall->{exitmessage});

$clall->reset();
$clall->run();
$outlook0815->logger(undef, undef, 4, "pc0815.muc: Failed password");
$outlook0815->logger(undef, undef, 2, "pc4711.muc: Failed password");
$outlook0815->logger(undef, undef, 4, "pc0815.muc: mailbox corrupt");
$outlook0815->loggercrap(undef, undef, 20);
$outlook0815->logger(undef, undef, 4, "pc0815.muc: mailbox full");
$outlook0815->loggercrap(undef, undef, 20);
$outlook0815->logger(undef, undef, 4, "pc4711.muc: ramsch");
$outlook0815->loggercrap(undef, undef, 20);
$outlook0815->logger(undef, undef, 14, "pc4711.muc: mailbox full");
$outlook0815->loggercrap(undef, undef, 20);
$outlook0815->logger(undef, undef, 7, "pc4711.muc: excel oo file found");
$outlook0815->loggercrap(undef, undef, 20);
$outlook0815->logger(undef, undef, 5, "pc4711.muc: outlook mailbox full");
$outlook0815->loggercrap(undef, undef, 20);
$clall->reset();
$clall->run();
diag($clall->has_result());
diag($clall->{exitmessage});
ok($clall->expect_result(0, 19, 13, 0, 2));
ok($clall->{exitmessage} =~ /CRITICAL - \(13 errors, 19 warnings.* - .*4711.muc: Failed .* /);

$clsimple->reset();
$clsimple->run();
$outlook0815->logger(undef, undef, 4, "pc0815.muc: Failed password");
$outlook0815->logger(undef, undef, 2, "pc4711.muc: Failed password");
$outlook0815->logger(undef, undef, 4, "pc0815.muc: mailbox corrupt");
$outlook0815->loggercrap(undef, undef, 20);
$outlook0815->logger(undef, undef, 4, "pc0815.muc: mailbox full");
$outlook0815->loggercrap(undef, undef, 20);
$outlook0815->logger(undef, undef, 4, "pc4711.muc: ramsch");
$outlook0815->loggercrap(undef, undef, 20);
$outlook0815->logger(undef, undef, 14, "pc4711.muc: mailbox full");
$outlook0815->loggercrap(undef, undef, 20);
$outlook0815->logger(undef, undef, 7, "pc4711.muc: excel oo file found");
$outlook0815->loggercrap(undef, undef, 20);
$outlook0815->logger(undef, undef, 5, "pc4711.muc: outlook mailbox full");
$outlook0815->loggercrap(undef, undef, 20);
$clsimple->reset();
$clsimple->run();
diag($clsimple->has_result());
diag($clsimple->{exitmessage});
ok($clsimple->expect_result(0, 0, 6, 0, 2));
ok($clsimple->{exitmessage} =~ /CRITICAL - \(6 errors.* - .*4711.muc: Failed .* /);

#$cl4711->run();
#$clsimple->run()