From: Stephen L Johnson Date: Wed, 10 Jan 2001 16:24:40 +0000 (+0000) Subject: skipped services after a 'stop_after' are reported with a clear status X-Git-Tag: spong-2_7_3~11 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f42f9f2206c610f82439d81f549db5447900674d;p=spong.git skipped services after a 'stop_after' are reported with a clear status --- diff --git a/src/spong-network.pl b/src/spong-network.pl index c1035d3..e5e3229 100755 --- a/src/spong-network.pl +++ b/src/spong-network.pl @@ -17,7 +17,7 @@ # (2) Converted checks to new plugin mechanism (Stephen Johnson May 28, 1999) # Added user-configurable escalation mechanism # -# $Id: spong-network.pl,v 1.28 2000/12/21 22:47:56 sljohnson Exp $ +# $Id: spong-network.pl,v 1.29 2001/01/10 16:24:40 sljohnson Exp $ use Carp; use lib "@@LIBDIR@@"; @@ -92,7 +92,8 @@ while( 1 ) { } my $stopafter = 0; - foreach $_ ( split(/\s+/,$HOSTS{$host}->{'services'}) ) { + my $set_clear = 0; + foreach $_ ( split(/[\s,]+/,$HOSTS{$host}->{'services'}) ) { # ok...if the check has a : on the end, then stop if it # comes back negative if (/^(\w+)(:)$/) { @@ -106,6 +107,13 @@ while( 1 ) { # Reset the critical error count $HOSTS{$host}->{'service'}->{$check}->{'count'} = 0; &debug( "checking $host/$check", 9 ); + +# # If set_clear, set service to clear status and goto next +# if( $set_clear ) { +# set_clear( $host, $check ); +# next; +# } + &do_check($host,$check); # Get the last status of the check @@ -114,7 +122,8 @@ while( 1 ) { if ($stopafter && $laststatus ne 'green') { debug("Check $check failed for host $host," . " skipping remaining tests", 3); - last; + last; +# $set_clear = 1; # Set remaining check to clear status } } } @@ -229,6 +238,65 @@ sub do_check { if ($@) { &error("$@"); } + + # Do set_clear processing if necessary + if( ! $skip_status and $color eq "red" ) { + do_set_clear( $host, $service ); + } +} + +# Do the set_clear process if the service for the host has the 'last' +# flag set in it's 'services'. Flag every service past it as clear. + +sub do_set_clear { + my( $host, $service ) = @_; + + my $set_clear = 0; + my $stop_after = 0; + foreach ( split(/[\s,]+/,$HOSTS{$host}->{'services'}) ) { + + if (/^(\w+)(:)$/) { + $s = $1; + $stop_after = 1; + } else { + $s = $_; + } + + # If our service + if( $s eq $service) { + # Has the stop_after flag, set flag and skip to next service + if( $stop_after ) { $set_clear = 1; next; } + else { last; } + } + + # If set_clear, set service to clear status + if( $set_clear ) { + sleep 1; + set_clear( $host, $s ); + } + } + +} + + +# Set service for a host to 'clear' status for non checking of service +# This used for for skipping remaining test for a host if last flag +# is set for the service + +sub set_clear { + my( $host, $service ) = @_; + + $summary = "Test skipped due. A prev test flagged as stop_after"; + $message = ""; + + eval { + &status( $SPONGSERVER, $host, $service, 'clear', $summary, $message ); + }; + + if ($@) { + &error("set_clear: @"); + } + } # A generic tcp port checking routine. You give this function a hostname, a @@ -242,16 +310,16 @@ sub check_simple { my( $attempt, $start, $message, $diff, $errcd ); for $timeout ( 3, 5, 12 ) { - $start = time(); + $start = $hires ? main::time() : time(); ($errcd,$message) = &check_tcp( $host, $port, $send, $timeout ); - $diff = time() - $start; + $diff = ($hires ? main::time() : time()) - $start; $attempt++; if( $message =~ /$check/ ) { $color = "green"; last; } &debug("check_simple: $service - $host - attempt $attempt failed"); } - $diff = sprintf("%.2f",$diff); + $diff = sprintf("%.3f",$diff); $summary = "$service is down, $errcd" if $color eq "red" and $errcd; $summary = "$service ok - $diff second response time" if $color eq "green";