[Nagiosplug-devel] Problem with HTTP redirect, check_http v1759 (nagios-plugins 1.4.10)

Holger Weiss holger at CIS.FU-Berlin.DE
Mon Oct 1 19:44:02 CEST 2007


* Rodrigo Andés Godoy Schichaschwili <rgodoysch at gmail.com> [2007-10-01 11:20]:
> The "check_http" included in nagios-plugins 1.4.10 fails on redirect for web
> servers that verify the virtual host, because it uses the server_adress
> instead of the host_name when follows redirect links.

D'oh!  Yes, I introduced this problem by fixing the case that only "-I"
but not "-H" is used.  You'll run into the problem if you use both "-H"
and "-I" against a virtual host which redirects to a relative URL.
While check_http supports relative redirection targets ("be liberal in
what you accept"), the HTTP RFC only allows the server to redirect to
absolute URLs:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30

Therefore, I'd be interested in whether the redirection was generated by
some server (which?) or by some script (just to get a rough idea of how
many sites might be bitten by this problem).

> Change server_address to host_name in lines 154, 879, 1158, 1203 and 1207
> solved the problem for me.

Could you verify that the attached patch fixes the problem?

Thank you, Holger
-------------- next part --------------
Index: check_http.c
===================================================================
--- check_http.c	(revision 1800)
+++ check_http.c	(working copy)
@@ -151,7 +151,7 @@
 
   if (display_html == TRUE)
     printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">", 
-      use_ssl ? "https" : "http", server_address,
+      use_ssl ? "https" : "http", host_name ? host_name : server_address,
       server_port, server_url);
 
   /* initialize alarm signal handling, set socket timeout, start timer */
@@ -1155,7 +1155,7 @@
       }
       i = server_port;
       strcpy (type, server_type);
-      strcpy (addr, server_address);
+      strcpy (addr, host_name ? host_name : server_address);
     }           
 
     else {
@@ -1204,8 +1204,8 @@
          display_html ? "</A>" : "");
 
   if (verbose)
-    printf (_("Redirection to %s://%s:%d%s\n"), server_type, server_address,
-            server_port, server_url);
+    printf (_("Redirection to %s://%s:%d%s\n"), server_type,
+            host_name ? host_name : server_address, server_port, server_url);
 
   check_http ();
 }


More information about the Devel mailing list