From: Stephen L Johnson Date: Tue, 19 Dec 2000 20:01:57 +0000 (+0000) Subject: fixed timer() problem in tcp_check() and code to skip remaining tests for host if... X-Git-Tag: spong-2_7_2~33 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d5ba256080fe8e0b09c3c6cb8631b389c60a4b54;p=spong.git fixed timer() problem in tcp_check() and code to skip remaining tests for host if flagged test fails. --- diff --git a/src/spong-network.pl b/src/spong-network.pl index f9e9e58..fe44411 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.26 2000/12/19 05:27:35 sljohnson Exp $ +# $Id: spong-network.pl,v 1.27 2000/12/19 20:01:57 sljohnson Exp $ use Carp; use lib "@@LIBDIR@@"; @@ -86,12 +86,31 @@ while( 1 ) { foreach $host ( @HOSTS_LIST ) { &debug( "checking network services on $host" ); - foreach my $check ( split(/\s+/,$HOSTS{$host}->{'services'}) ) { - $0 = "spong-network (checking $host/$check)"; - # Reset the critical error count - $HOSTS{$host}->{'service'}->{$check}->{'count'} = 0; - &debug( "checking $host/$check", 9 ); - &do_check($host,$check); + my $stopafter = 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+)(:)$/) { + $check = $1; + $stopafter = 1; + } else { + $check = $_; + } + + $0 = "spong-network (checking $host/$check)"; + # Reset the critical error count + $HOSTS{$host}->{'service'}->{$check}->{'count'} = 0; + &debug( "checking $host/$check", 9 ); + &do_check($host,$check); + + # Get the last status of the check + my $laststatus = $HOSTS{$host}{'service'}{$check}{'laststatus'} + || 'green'; + if ($stopafter && $laststatus ne 'green') { + debug("Check $check failed for host $host," . + " skipping remaining tests", 3); + last; + } } } @@ -179,6 +198,7 @@ sub do_check { if ($crit_count < $CRIT_WARN_LEVEL) { $color = 'yellow' if $laststatus eq 'green'; $skip_status = 1; + $HOSTS{$host}->{'service'}->{$service}->{'laststatus'} = 'yellow'; } else { $HOSTS{$host}->{'service'}->{$service}->{'laststatus'} = 'red'; } @@ -280,8 +300,8 @@ sub check_tcp { select((select(SOCK), $| = 1)[0]); print SOCK "$data"; recv( SOCK, $line, 256, 0 ); # just grab a chunk from the service. - alarm(0); }; + alarm(0); close( SOCK ) || die "close: $!"; # close even if our alarm went off if ( $@ =~ /^(.*) at/ ) { $err = $1; } @@ -484,7 +504,7 @@ sub munge_services { $services .= $service; } - $services = "ping $services" if ( $ping ); + $services = "ping $services" if ( $ping && $services !~ /ping/ ); $HOSTS{$host}->{'services'} = $services; } } @@ -499,6 +519,8 @@ sub config_funcs { my (%checks,$check); foreach $host ( @HOSTS_LIST ) { foreach $check (split(/\s+/,$HOSTS{$host}->{'services'})) { + # Strip any ':' from service names + $check =~ s/://g; $checks{$check} = 1; } }