From faa8445007d74caaca99566e041f09b2e2c33018 Mon Sep 17 00:00:00 2001 From: Stephen L Johnson Date: Mon, 7 Feb 2000 03:05:37 +0000 Subject: [PATCH] expanded check to HTTP 1.1 for multiple virtual web servers and different ports --- src/lib/Spong/Network/plugins/check_http | 80 ++++++++++++++++++------ 1 file changed, 61 insertions(+), 19 deletions(-) diff --git a/src/lib/Spong/Network/plugins/check_http b/src/lib/Spong/Network/plugins/check_http index 1e77210..ec9c110 100755 --- a/src/lib/Spong/Network/plugins/check_http +++ b/src/lib/Spong/Network/plugins/check_http @@ -10,32 +10,74 @@ sub check_http { my( $host ) = @_; my( @http_files ) = ( @{$HTTPDOCS{"ALL"}}, @{$HTTPDOCS{$host}} ); my( $http_port ) = $HTTPPORT{$host} || $HTTPPORT{"ALL"} || 80; + my( @http_urls ) = ( @{$HTTPURLS{$host}} ); + @http_urls = (@{$HTTPURLS{'DEFAULT'}}) if ! @http_urls; my( $file, $tmessage ) = ( "", "" ); my( $color, $summary ) = ( "green", "" ); - foreach $file ( @http_files ) { - my $message = - &check_tcp( $host, $http_port, "HEAD $file HTTP/1.0\r\n\r\n" ); + # If HTTP URLS are defined use the URL check + if ( @http_urls ) { + foreach my $url (@http_urls) { + # Parse the URL into it's components + $url =~ s|^http://||; # Remove the protocol id if present + my($hpart,$urlpath) = ( $url =~ m|^([^/]+)(/.*)| ); + my($hname,$port) = split(/:/,$hpart); + $port = 80 if ! $port; + $hname = $host if ( ! $hname || $hname eq '_HOST_' ); + + my $message = + &check_tcp( $hname, $port, + "HEAD $urlpath HTTP/1.1\r\nHost: $host:$port\r\n\r\n" ); + + if( $message =~ /HTTP\S+\s+(\d\d\d)\s.*$/m ) { + my $code = $1; + + if( $code >= 500 ) { + $color = "red"; $summary = "error - $code - $url"; + # Treat a 401 (authorization Required) code as a green + } elsif( $code >= 400 && $code != 401) { + if( $color ne "red" ) { + $color = "yellow"; $summary = "warning - $code - $url"; } + } else { + if( $color ne "red" && $color ne "yellow" ) { + $color = "green"; $summary = "ok - $code"; } + } + } elsif( $message !~ /HTTP/m ) { + $color = "red"; $summary = "no response from http server"; + } else { + if( $color ne "red" ) { + $color = "yellow"; $summary = "can't determine status code";} + } + $tmessage .= "->HEAD $urlpath HTTP/1.1\nHost: $hname:$port\n$message\n"; + } + + } else { + + foreach $file ( @http_files ) { + my $message = + &check_tcp( $host, $http_port, "HEAD $file HTTP/1.0\r\n\r\n" ); - if( $message =~ /HTTP\S+\s+(\d\d\d)\s.*$/m ) { - my $code = $1; + if( $message =~ /HTTP\S+\s+(\d\d\d)\s.*$/m ) { + my $code = $1; - if( $code >= 500 ) { - $color = "red"; $summary = "error - $code - $file"; - } elsif( $code >= 400 ) { + if( $code >= 500 ) { + $color = "red"; $summary = "error - $code - $file"; + # Treat a 401 (authorization Required) code as a green + } elsif( $code >= 400 && $code != 401) { + if( $color ne "red" ) { + $color = "yellow"; $summary = "warning - $code - $file"; } + } else { + if( $color ne "red" && $color ne "yellow" ) { + $color = "green"; $summary = "ok - $code"; } + } + } elsif( $message !~ /HTTP/m ) { + $color = "red"; $summary = "no response from http server"; + } else { if( $color ne "red" ) { - $color = "yellow"; $summary = "warning - $code - $file"; } - } else { - if( $color ne "red" && $color ne "yellow" ) { - $color = "green"; $summary = "ok - $code"; } - } - } elsif( $message !~ /HTTP/m ) { - $color = "red"; $summary = "no response from http server"; - } else { - if( $color ne "red" ) { - $color = "yellow"; $summary = "can't determine status code";} + $color = "yellow"; $summary = "can't determine status code";} + } + $tmessage .= "->HEAD $file HTTP/1.0\n$message\n"; } - $tmessage .= "->HEAD $file HTTP/1.0\n$message\n"; } &debug( "http - $host - $color, $summary" ); -- 2.30.2