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
|
package Nagios::CheckLogfiles::Search::Executable;
use strict;
use Exporter;
use File::Basename;
use vars qw(@ISA);
use constant OK => 0;
use constant WARNING => 1;
use constant CRITICAL => 2;
use constant UNKNOWN => 3;
@ISA = qw(Nagios::CheckLogfiles::Search);
sub new {
my $self = bless {}, shift;
return $self->init(shift);
}
sub init {
my $self = shift;
my $params = shift;
$self->default_options({ exeargs => "", });
$self->SUPER::init($params);
}
sub analyze_situation {
my $self = shift;
$self->{logmodified} = 1;
}
sub collectfiles {
my $self = shift;
my @rotatedfiles = ();
my $fh = new IO::File;
#if ($self->getfileisreadable($self->{logfile})) {
if ($self->getfileisexecutable($self->{logfile})) {
my $cmdline = $self->{logfile}.
($self->get_option('exeargs') ? " ".$self->get_option('exeargs') : "").
" 2>&1|";
$fh->open($cmdline);
$self->trace("opened command %s", $cmdline);
push(@{$self->{relevantfiles}},
{ filename => $self->{logfile},
fh => $fh, seekable => 0, statable => 1,
modtime => time,
fingerprint => "0:0" });
} else {
if (-e $self->{logfile}) {
# permission problem
$self->trace("could not open logfile %s", $self->{logfile});
$self->addmatch('CRITICAL', sprintf "could not open logfile %s",
$self->{logfile});
} else {
if ($self->get_option('logfilenocry')) {
$self->trace("could not find scriptfile %s", $self->{logfile});
$self->addmatch($self->get_option('logfilemissing'),
sprintf "could not find scriptfile %s",
$self->{logfile});
} else {
# dont care.
$self->trace("could not find scriptfile %s, but that's ok",
$self->{logfile});
}
}
}
}
sub loadstate {
my $self = shift;
$self->SUPER::loadstate();
$self->{laststate}->{logoffset} = 0;
}
sub savestate {
my $self = shift;
foreach (keys %{$self->{laststate}}) {
$self->{newstate}->{$_} = $self->{laststate}->{$_};
}
$self->SUPER::savestate();
}
|