Hi,

The current ldirectord does not support proxy HTTP for health checks, so
checking web proxy backends is not possible. This patch adds a service
type 'http_proxy', in which the proxy backends are health-checked by
requesting a specified URI through them.

Julius

diff -r e3c1760760f9 ldirectord/ldirectord.in
--- a/ldirectord/ldirectord.in  Tue Sep 23 11:45:53 2008 +0200
+++ b/ldirectord/ldirectord.in  Thu Sep 25 16:33:47 2008 +0200
@@ -347,7 +347,7 @@ On means no checking will take place and
 On means no checking will take place and real servers will always be
 activated. Default is I<negotiate>.
 
-B<service = 
>B<dns>|B<ftp>|B<http>|B<https>|B<imap>|B<imaps>|B<ldap>|B<mysql>|B<nntp>|B<none>|B<oracle>|B<pgsql>|B<pop>|B<pops>|B<radius>|B<simpletcp>|B<sip>|B<smtp>
+B<service = 
>B<dns>|B<ftp>|B<http>|B<https>|B<http_proxy>|B<imap>|B<imaps>|B<ldap>|B<mysql>|B<nntp>|B<none>|B<oracle>|B<pgsql>|B<pop>|B<pops>|B<radius>|B<simpletcp>|B<sip>|B<smtp>
 
 The type of service to monitor when using checktype=negotiate. None denotes
 a service that will not be monitored. 
@@ -387,6 +387,8 @@ Default:
 
 =item * Virtual server port is 1812: radius
 
+=item * Virtual server port is 3128: http_proxy
+
 =item * Virtual server port is 3306: mysql
 
 =item * Virtual server port is 5432: pgsql
@@ -431,6 +433,10 @@ This object will be requested each check
 This object will be requested each checkinterval seconds on each real
 server.  The string must be inside quotes. Note that this string may be
 overridden by an optional per real-server based request-string.
+
+For an HTTP/HTTPS check, this should be a relative URI, while it has to
+be absolute for the 'http_proxy' check type. In the latter case, this
+URI will be requested through the proxy backend that is being checked.
 
 For a DNS check this should the name of an A record, or the address
 of a PTR record to look up.
@@ -1260,6 +1266,7 @@ sub read_config
                                                          $1 eq "ftp"   ||
                                                          $1 eq "http"  ||
                                                          $1 eq "https" ||
+                                                         $1 eq "http_proxy"    
||
                                                          $1 eq "imap"  ||
                                                          $1 eq "imaps" ||
                                                          $1 eq "ldap"  ||
@@ -1278,6 +1285,7 @@ sub read_config
                                                             "service must " .
                                                             "be dns, ftp, " .
                                                             "http, https, " .
+                                                            "http_proxy, " .
                                                             "imap, imaps, " .
                                                             "ldap, nntp, "  .
                                                             "mysql, none, " .
@@ -1525,6 +1533,7 @@ sub ld_port_to_service
        if ($port eq 995)       { return "imaps"; }
        if ($port eq 1521)      { return "oracle"; }
        if ($port eq 1812)      { return "radius"; }
+       if ($port eq 3128)      { return "http_proxy"; }
        if ($port eq 3306)      { return "mysql"; }
        if ($port eq 5060)      { return "sip"; }
        if ($port eq 5432)      { return "pgsql"; }
@@ -1556,6 +1565,7 @@ sub ld_service_to_port
        if ($service eq "pops")         { return 995; }
        if ($service eq "oracle")       { return 1521; }
        if ($service eq "radius")       { return 1812; }
+       if ($service eq "http_proxy")   { return 3128; }
        if ($service eq "mysql")        { return 3306; }
        if ($service eq "sip")          { return 5060; }
        if ($service eq "pgsql")        { return 5432; }
@@ -1923,18 +1933,29 @@ sub ld_setup
                for my $r (@$real) {
                         $$r{forw} = get_forward_flag($$r{forward});
                        my $port=ld_checkport($v, $r);
+
+                       my $schema = $$v{service};
+                       if ($$v{service} eq 'http_proxy') {
+                               $schema = 'http';
+                       }
+
                        if (defined $$r{request} && defined $$r{receive}) {
                                my $uri = $$r{request};
                                $uri =~ s/^\///g;
-                               if ($$r{request} =~ /$$v{service}:\/\//) {
+                               if ($$r{request} =~ /$schema:\/\//) {
                                        $$r{url} = "$uri";
                                } else {
-                                       $$r{url} = 
"$$v{service}:\/\/$$r{server}:$port\/$uri";
+                                       $$r{url} = 
"$schema:\/\/$$r{server}:$port\/$uri";
                                }
                        } else {
                                my $uri = $$v{request};
                                $uri =~ s/^\///g;
-                               $$r{url} = 
"$$v{service}:\/\/$$r{server}:$port\/$uri";
+
+                               if ($$v{service} eq 'http_proxy') {
+                                       $$r{url} = "$uri";
+                               } else {
+                                       $$r{url} = 
"$schema:\/\/$$r{server}:$port\/$uri";
+                               }
 
                                $$r{request} = $$v{request} unless defined 
$$r{request};
                                $$r{receive} = $$v{receive};
@@ -2347,7 +2368,7 @@ sub _check_real
 
         if ($$v{checktype} eq "negotiate" || 
$$r{num_connects}>=$$v{num_connects}) {
                 &ld_debug(2, "Checking negotiate: real server=$real_id 
(virtual=$virtual_id)");
-                if ($$v{service} eq "http" || $$v{service} eq "https") {
+                if (grep $$v{service} eq $_, ("http", "https", "http_proxy")) {
                         $$r{num_connects} = 0 if (check_http($v, $r) == 
$SERVICE_UP);
                 } elsif ($$v{service} eq "pop") {
                         $$r{num_connects} = 0 if (check_pop($v, $r) == 
$SERVICE_UP);
@@ -2421,7 +2442,7 @@ sub check_http
        }
        my ($v, $r) = @_;
 
-       $$r{url} =~ /$$v{service}:\/\/([^:\/]+)(:([^\/]+))?(\/.*)/;
+       $$r{url} =~ /(http|https):\/\/([^:\/]+)(:([^\/]+))?(\/.*)/;
        my $host = $1;
        #my $port = $3;
        my $uri = $4;
@@ -2431,7 +2452,15 @@ sub check_http
                . "virtualhost=\"$virtualhost\"");
        
        my $ua = new LWP::UserAgent();
-       my $h = new  HTTP::Headers("Host" => $virtualhost);
+
+       my $h = undef;
+       if ($$v{service} eq "http_proxy") {
+               my $port = ld_checkport($v, $r);
+               $ua->proxy("http", "http://$$r{server}:$port/";);
+       } else {
+               $h = new HTTP::Headers("Host" => $virtualhost);
+       }
+
        my $req = new HTTP::Request("$$v{httpmethod}", "$$r{url}", $h);
        my $res;
 

_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to