sub check_logs {
my $color = "green";
my( $message, $summary, $word, $ret, $hit, @hit, $time, $critical );
- my( $lm, @logs, $stat, $key, $numprob, $status, $text, $file, $chk, $lc);
+ my( $lm, %logs, $stat, $key, $numprob, $status, $text, $file, $chk, $lc);
+ my( $hits, $hostname );
+ my %byhost = ();
# If @LOGMON is not defined, load the log monitoring checks
if (! defined @LOGMON) {
foreach $chk ( @{$lc->{'checks'}} ) {
$lm->add_check($chk);
}
- push @LOGMON, $lm
+ push @LOGMON, $lm;
+ }
+ }
+
+ foreach $lc (@$LOGCHECKS) {
+ foreach $chk ( @{$lc->{'checks'}} ) {
+ $byhost{$chk->{'host'} or $HOST} = ();
}
}
# Run the checks for all of the log files
foreach $lm (@LOGMON) { $lm->check(); }
- # Scan each log monitor stati, build the message and calculate summary
$message = "";
foreach $lm (@LOGMON) {
$message .= $lm->logfile() . "\n";
- $stat = $lm->stati(); $numprob = 0;
- foreach $key (%$stat) {
+ $hits = $lm->stati(); $numprob = 0;
+ foreach $key (keys %$hits) {
+ # Grab the status and text fields to make things easier
+ $status = $hits->{$key}->{'status'};
+ $text = $hits->{$key}->{'text'};
+ $host = ($hits->{$key}->{'host'} or $HOST);
+ push @{$byhost{$host}},{ 'status' => $status,
+ 'text' => $text,
+ 'logfile' => $lm->logfile() };
+ }
+ }
+
+ foreach $hostname (sort keys %byhost) {
+ %logs = ();
+ $numprob = 0;
+ $message = "";
+ $color = "green";
+ # Loop over each element in the array
+ foreach $elem ( @{$byhost{$hostname}} ) {
+ $status = $elem->{'status'};
+ $text = $elem->{'text'};
$numprob++;
- $status = $stat->{$key}->{'status'};
- $text = $stat->{$key}->{'text'};
+
+ # Scan each log monitor stati, build the message and calculate summary
if ( $text or $status ) {
$message .= "$status : $text\n";
}
$color = "yellow" if $status eq "yellow" and $color eq "green";
$color = "red" if $status eq "red";
+ $logs{$elem->{'logfile'}} = 1;
}
- if ($numprob == 0) {$message .= "No bad messages\n"; }
- else { push @logs,$lm->logfile(); }
- }
- $summary = "All logs ok." if $color eq "green";
- $summary = "log problems: @logs" if $color ne "green";
+ if ($numprob == 0) { $message .= "No bad messages\n"; }
- &debug( "logs - $color, $summary" );
- &status( $SPONGSERVER, $HOST, "logs", $color, $summary, $message );
+ $summary = "All logs ok." if $color eq "green";
+ $summary = "log problems: ".join("\n",keys %logs) if $color ne "green";
+
+ &debug( "logs - $color, $summary" );
+ &status( $SPONGSERVER, $hostname, "logs", $color, $summary, $message );
+ }
}
# I'm included perl code, I need this line.