From 493246e64c750828941c8c8e0bf381c9a5ae50fa Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 27 Jul 2004 17:04:28 +0000 Subject: [PATCH] Allow a 'host' entry in a check_logs configuration section. This allows you to report problems as a different host. Useful when you are monitoring SNMP traps, consolidating syslogs, etc. --- src/lib/Spong/Client/logmon.pm | 1 + src/lib/Spong/Client/plugins/check_logs | 55 ++++++++++++++++++------- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/lib/Spong/Client/logmon.pm b/src/lib/Spong/Client/logmon.pm index 6f8db46..083cfcc 100755 --- a/src/lib/Spong/Client/logmon.pm +++ b/src/lib/Spong/Client/logmon.pm @@ -141,6 +141,7 @@ sub check { $self->{'stati'}->{$id} = { item=>'logs', status=>$rep->{'status'}, endtime=>time+($rep->{'duration'}*60), + host=>($rep->{'host'} or $HOST), text=>"$text" }; } } diff --git a/src/lib/Spong/Client/plugins/check_logs b/src/lib/Spong/Client/plugins/check_logs index 8ffec6c..82297cf 100755 --- a/src/lib/Spong/Client/plugins/check_logs +++ b/src/lib/Spong/Client/plugins/check_logs @@ -9,7 +9,9 @@ use Spong::Client::logmon; 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) { @@ -19,37 +21,62 @@ sub check_logs { 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. -- 2.30.2