# (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@@";
}
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+)(:)$/) {
# 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
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
}
}
}
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
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";