From: Stephen L Johnson Date: Wed, 27 Sep 2000 04:04:48 +0000 (+0000) Subject: Add or clean up some debugging in various spots. Fix some typos and X-Git-Tag: spong-2_7_0-beta1~19 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f6b4fa78088e264cdaef14af17fd3fa874353c4;p=spong.git Add or clean up some debugging in various spots. Fix some typos and incorrect comments, and removed some duplicated comments. Only display (count/level) in summary if more than 1 attempt needed. $line returned from check_tcp() should be a string. Close filehandle outside of timeout eval in case alarm goes off; else we'll orphan a FIFO. Allow --refresh or --nosleep to run even if there is a spong-client already running (original behavior). Pass debug value when doing a restart. Allow spaces or comma to separate services in spong.hosts. --- diff --git a/src/spong-network.pl b/src/spong-network.pl index 25f7075..fc1275e 100755 --- a/src/spong-network.pl +++ b/src/spong-network.pl @@ -88,6 +88,7 @@ while( 1 ) { $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); } } @@ -99,6 +100,8 @@ while( 1 ) { @bad_checks = (); foreach $tmp (@tmp_checks) { my ( $host, $check ) = split / /,$tmp; + $0 = "spong-network (rechecking $host/$check)"; + &debug( "checking $host/$check", 9 ); &do_check($host,$check); } @@ -124,7 +127,7 @@ while( 1 ) { $0 = "spong-network (sleeping)"; sleep $sleep; } - $lastcheck = $nexttime; # Save the curent check time as the last time + $lastcheck = $nexttime; # Save the current check time as the last time } } @@ -177,7 +180,8 @@ sub do_check { } else { $HOSTS{$host}->{'service'}->{$service}->{'laststatus'} = 'red'; } - $summary = "($crit_count/$CRIT_WARN_LEVEL) " . $summary; + $summary = "($crit_count/$CRIT_WARN_LEVEL) " . $summary + if $CRIT_WARN_LEVEL > 1; push @bad_checks, "$host $service" if ($crit_count < $CRIT_WARN_LEVEL); } else { $crit_count = 0; @@ -217,7 +221,7 @@ sub check_simple { $attempt++; if( $message =~ /$check/ ) { $color = "green"; last; } - &debug("Attempt $a failed."); + &debug("check_simple: $service - $host - attempt $attempt failed"); } $diff = sprintf("%.2f",$diff); @@ -233,7 +237,7 @@ sub check_simple { # --------------------------------------------------------------------------- -# &check_tcp( HOST, PORT, DATA ) +# &check_tcp( HOST, PORT, DATA, TIMEOUT ) # # This function will make a connection to a port at a given port, and send a # message, it will then return what it gets back to the caller of this @@ -253,11 +257,8 @@ sub check_tcp { $ip = "$a.$b.$c.$d"; } - # Set an alarm so that if we can't connect "immediately" it times out. - # Poor man's exception handling in perl... - $err = 0; - $line = 0; + $line = ""; $iaddr = inet_aton( $ip ) || return -1; $paddr = sockaddr_in( $port, $iaddr ); @@ -275,9 +276,9 @@ sub check_tcp { select((select(SOCK), $| = 1)[0]); print SOCK "$data"; recv( SOCK, $line, 256, 0 ); # just grab a chunk from the service. - close( SOCK ) || die "close: $!"; alarm(0); }; + close( SOCK ) || die "close: $!"; # close even if our alarm went off if ( $@ =~ /^(.*) at/ ) { $err = $1; } if ( $@ =~ /timed out/ ) { $err = "check_tcp timed out"; } @@ -410,7 +411,7 @@ sub handle_signals { } # Check to see if we are already running - &already_running(); + &already_running() unless $nosleep; # Write our pid to the spong tmp directory. @@ -454,7 +455,8 @@ sub exit_handler { sub hup_handler { &debug( "caught HUP signal, restarting..." ); unlink "$SPONGTMP/spong-network.pid" if "$SPONGTMP/spong-network.pid"; - if( $debug ) { exec $me, "--debug"; } else { exec $me; } + alarm(0); + if( $debug ) { exec $me, "--debug", $debug; } else { exec $me; } } sub pipe_handler { @@ -471,7 +473,7 @@ sub munge_services { foreach $host ( @HOSTS_LIST ) { $ping = 1; $services = ""; - foreach $service ( split(/\s+/,$HOSTS{$host}->{'services'}) ) { + foreach $service ( split(/[\s,]+/,$HOSTS{$host}->{'services'}) ) { # noping is a meta-service that say to skip ping test for this host if ( $service eq "noping" ) { $ping = 0; next; } $service = " $service" if ( $services );