[Nagios-users] checking multiple log files

Josh Yost Josh.Yost at epsiia.com
Tue Apr 3 16:16:09 UTC 2007


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'}
}






More information about the Nagios-users mailing list