checking multiple log files
Kyle O'Donnell
kyle.odonnell at gmail.com
Tue Apr 3 18:31:04 CEST 2007
Hi Josh,
Thanks very much, but I went the lazy route.
I modified the following in check_logfiles:
from:
# maybe a rotation situation, a typo in the configfile,...
trace("could not find logfile %s", $loginfo->{logfile});
$lastmsg{UNKNOWN} = sprintf "could not find logfile %s",
$loginfo->{logfile};
push(@{$matchlines->{UNKNOWN}}, $lastmsg{UNKNOWN);
to:
# maybe a rotation situation, a typo in the configfile,...
trace("could not find logfile %s", $loginfo->{logfile});
$lastmsg{OK} = sprintf "could not find logfile %s",
$loginfo->{logfile};
push(@{$matchlines->{OK}}, $lastmsg{OK});
I was mistaken about the output. It does print the last offending
line, but it's found in the 'performance data' output instead.
Running it from the cmd line its printed after the '|', checked
perfdata, and voila.. right there :)
Thanks again,
Kyle
On 4/3/07, Josh Yost <Josh.Yost at epsiia.com> wrote:
>
> Kyle O'Donnell wrote:
> > Hi,
> >
> > I need to check for a string in multiple log files. The names of the
> > log files will contain a constant string, and be located in constant
> > directory.
> >
> > Currently I am using the check_logfiles plugin with the following
> configuration:
> >
> >
> > @logs = (
> > {
> > tag => 'mqrefused',
> > logfile => '/var/mqm/exits/logs/.*.log',
> > rotation => 'solaris',
> > warningpatterns => 'refused',
> > }
> >
> > );
> >
> > @logs = (
> > {
> > tag => 'mqfdcprobe',
> > logfile => '/var/mqm/errors/.*.FDC',
> > rotation => 'solaris',
> > warningpatterns => 'Probe Id',
> > }
> >
> > );
> >
> >
> > The only problems are that, the output does not contain the offending
> > string/line, and the status is set to UNKNOWN when a string isn't
> > matched.
> >
>
> Hi,
> I would suggest writing your own plugin if it's this specific & you
> know what you're looking for. What you're wanting to do would be pretty
> easy in perl (but I'm not sure what output you're looking for exactly).
>
> here's my really quick, ugly, untested implementation =):
>
> use lib '/usr/nagios/libexec';
> use utils qw ( %ERRORS );
>
> my @files;
> push @files, (glob ('/var/mqm/exits/logs/*.log'),
> glob ('/var/mqm/errors/*.FDC'));
>
> my %errors;
> for my $f (@files){
> unless (open FILE, $f){
> print "can't open file $f!\n"; exit $ERRORS{'UNKNOWN'}
> }
> my $counter = 0;
> while (<FILE>){
> $counter++;
> if (($f =~ /log$/ && /refused/) || ($f =~ /FDC$/ && /Probe ID/)){
> push @{$errors{$f}},$counter
> }
> }
> close FILE;
> }
>
> if (!%errors){
> print "OK!\n"; exit $ERRORS{'OK'}
> }
> else{
> for my $key (sort keys %errors){
> print "$key: errors at lines ", join ',',@{$errors{$key}}, " ";
> }
> print "\n";
> exit $ERRORS{'CRITICAL'}
> }
>
>
>
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue.
::: Messages without supporting info will risk being sent to /dev/null
More information about the Users
mailing list