From: Stephen L Johnson Date: Wed, 26 Jul 2000 03:24:18 +0000 (+0000) Subject: changes esclaton code to not report downgraded 'red' status messages X-Git-Tag: spong-2_7-alpha8~3 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db690d4f5dde55330acce316aa2a368b80a84f4b;p=spong.git changes esclaton code to not report downgraded 'red' status messages --- diff --git a/src/spong-network.pl b/src/spong-network.pl index 23c1732..a510a5b 100755 --- a/src/spong-network.pl +++ b/src/spong-network.pl @@ -188,11 +188,13 @@ sub do_check { # 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'; } @@ -211,7 +213,9 @@ sub do_check { 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("$@"); } @@ -239,8 +243,7 @@ sub check_simple { $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"); @@ -276,30 +279,32 @@ sub check_tcp { $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); }