From: Stephen L Johnson Date: Wed, 26 Apr 2000 05:56:47 +0000 (+0000) Subject: fixed compile problem with Time::HiRes no being installed in server. X-Git-Tag: spong-2_7-alpha5~6 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7df96b4aafb0f5c9d62e31bd8eb554b20213b043;p=spong.git fixed compile problem with Time::HiRes no being installed in server. sleep time can be individually set for each program via $SPONGSLEEP{} hash. changed escalation code to be a subloop that rechecks all services reported as down after main check loop --- diff --git a/src/spong-network.pl b/src/spong-network.pl index 819e98c..295a2f5 100755 --- a/src/spong-network.pl +++ b/src/spong-network.pl @@ -1,4 +1,4 @@ -#!@@PERL@@ +#!/usr/bin/perl # # Spong network monitoring script. This runs various tests against IP based # network services (like nntp, smtp, http, pop, etc...) If it can not @@ -33,7 +33,7 @@ use Spong::Status qw(status); use Spong::Log; # Check to see if the Time::HiRes module is available -eval "use Time::HiRes qw( time );"; +eval { require Time::HiRes; import Time::HiRes qw(time); }; if (! $@ ) { $hires = 1; } else { $hires = 0; }; srand( time() ^ ($$ + ($$ << 15 )) ); @@ -71,32 +71,60 @@ $SPONGSLEEP = $SPONGSLEEP{'spong-network'} || $SPONGSLEEP{'DEFAULT'} || %PLUGINS = {}; &config_funcs(); +my @bad_checks; + # Do the various network tests for each host. +my $lastcheck = time(); + while( 1 ) { + @bad_checks = (); # Clear out the bad check list + + # Main checking loop, check everything. foreach $host ( @HOSTS_LIST ) { &debug( "checking network services on $host" ); - my $check; - foreach $check ( split(/\s+/,$HOSTS{$host}->{'services'}) ) { + foreach my $check ( split(/\s+/,$HOSTS{$host}->{'services'}) ) { $0 = "spong-network (checking $host/$check)"; &do_check($host,$check); } - } + } + - # If we are suppose to stay alive, then sleep about $SPONGSLEEP seconds, we - # add a little randomness so that things don't get in sync and pound the - # spong-server. Otherwise, just exit. + # Now recheck the services that were down, but need to be rechecked + while ( @bad_checks ) { + my @tmp_checks = @bad_checks; + @bad_checks = (); + foreach $tmp (@tmp_checks) { + my ( $host, $check ) = split / /,$tmp; + &do_check($host,$check); + } + + sleep $RECHECKSLEEP; + } + + # If we are suppose to stay alive, then calculate the time for the next + # main time loop which is $lastcheck + $SPONGSLEEP, add a little randomness + # so that things don't get in sync and pound the spong-server. If we need + # to sleep off the difference. Otherwise, just exit. if( $nosleep ) { last; } else { - my $sleep = int($SPONGSLEEP - (.05 * $SPONGSLEEP) + - rand(.1 * $SPONGSLEEP)); - &debug( "sleeping for $sleep seconds" ); - $0 = "spong-network (sleeping)"; - sleep $sleep; + + # Calculate the time for the next loop + my $nexttime = $lastcheck + int($SPONGSLEEP - (.05 * $SPONGSLEEP) + + rand(.1 * $SPONGSLEEP)); + + if ( $nexttime > time() ) { + my $sleep = $nexttime - time(); + &debug( "sleeping for $sleep seconds" ); + $0 = "spong-network (sleeping)"; + sleep $sleep; + } + $lastcheck = $nexttime; # Save the curent check time as the last time } + } unlink( "$SPONGTMP/spong-network.pid" ) unless $nosleep; @@ -136,7 +164,8 @@ sub do_check { if ($status eq 'red') { $crit_count += 1; $color = ($crit_count < $CRIT_WARN_LEVEL) ? 'yellow' : 'red'; - $summary = "($crit_count/$CRIT_WARN_LEVEL) " . $summary + $summary = "($crit_count/$CRIT_WARN_LEVEL) " . $summary; + push @bad_checks, "$host $service" if ($crit_count < $CRIT_WARN_LEVEL); } else { $crit_count = 0; $color = $status; @@ -145,11 +174,7 @@ sub do_check { &debug("$status - $crit_count - $CRIT_WARN_LEVEL - $color - $summary"); # Save the critical counter in the host for the service - if ($color ne "green") { - $HOSTS{$host}->{'service'}->{$service}->{'count'} = $crit_count; - } else { - undef $HOSTS{$host}->{'service'}->{$service}->{'count'}; - } + $HOSTS{$host}->{'service'}->{$service}->{'count'} = $crit_count; eval { &status( $SPONGSERVER, $host, $service, $color, $summary, $message ); @@ -170,9 +195,9 @@ sub check_simple { my( $attempt, $start, $message, $diff, $errcd ); for $timeout ( 3, 5, 12 ) { - $start = main::time(); + $start = time(); ($errcd,$message) = &check_tcp( $host, $port, $send, $timeout ); - $diff = main::time() - $start; + $diff = time() - $start; $attempt++; if( $message =~ /$check/ ) { $color = "green"; last; }