# If counter < $CRIT_WARN_LEVEL, reduce status to yellow
# else pass a critical as a critical
# If current status is not red, reset the critical level counter.
+ $skip_status = 0;
if ($status eq 'red') {
$crit_count += 1;
$color = 'red';
if ($crit_count < $CRIT_WARN_LEVEL) {
$color = 'yellow' if $laststatus eq 'green';
+ $skip_status = 1;
} else {
$HOSTS{$host}->{'service'}->{$service}->{'laststatus'} = 'red';
}
eval {
&status( $SPONGSERVER, $host, $service, $color, $summary, $message );
- };
+ } if ! $skip_status;
+ &debug("Status change to down, deferring report until after rechecks",5)
+ if $skip_status;
if ($@) {
&error("$@");
}
$diff = sprintf("%.2f",$diff);
- $summary = "$service is down, timed out" if $color eq "red" and $errcd == 3;
- $summary = "$service is down, connection refused" if $color eq "red" and $errcd == 2;
+ $summary = "$service is down, $errcd" if $color eq "red" and $errcd;
$summary = "$service ok - $diff second response time" if $color eq "green";
$summary .= ", attempt $attempt" if ($attempt != 1 && $color eq "green");
$err = 0;
$line = 0;
- {
+
+ $iaddr = inet_aton( $ip ) || return -1;
+ $paddr = sockaddr_in( $port, $iaddr );
+ $proto = getprotobyname( 'tcp' );
+
+ # Set an alarm so that if we can't connect "immediately" it times out.
+ # Poor man's exception handling in perl...
+
+ eval {
local $SIG{'ALRM'} = sub { die "Socket timed out"; };
alarm($timeout);
- eval {
- $sock = IO::Socket::INET->new( PeerAddr => $ip,
- PeerPort => $port,
- Proto => 'tcp',
- Reuse => 1,
- );
- if ( defined $sock ) {
- print $sock "$data";
- $sock->recv( $line, 256, 0 ); # just grab a chunk from the service.
- } else {
- $err = 2; # Could not connect to service port
- }
-
- alarm(0);
- };
+ socket( SOCK, PF_INET, SOCK_STREAM, $proto ) || die "socket: $!";
+ connect( SOCK, $paddr ) || die "connect: $!";
+ 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);
};
- if ( $@ =~ /timed out/ ) { $err = 3; }
+ if ( $@ =~ /^(.*) at/ ) { $err = $1; }
+ if ( $@ =~ /timed out/ ) { $err = "check_tcp timed out"; }
+ if ( $@ =~ /connect:(.*) at/ ) { $err = $1; }
- return ($err, $line);
+ return ($err,$line);
}