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" );