checking multiple log files

Josh Yost Josh.Yost at epsiia.com
Tue Apr 3 18:16:09 CEST 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'}
}



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