$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);
}
}
@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);
}
$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
}
}
} 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;
$attempt++;
if( $message =~ /$check/ ) { $color = "green"; last; }
- &debug("Attempt $a failed.");
+ &debug("check_simple: $service - $host - attempt $attempt failed");
}
$diff = sprintf("%.2f",$diff);
# ---------------------------------------------------------------------------
-# &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
$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 );
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"; }
}
# Check to see if we are already running
- &already_running();
+ &already_running() unless $nosleep;
# Write our pid to the spong tmp directory.
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 {
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 );