Options

Reselect rserver depending of the server response URL after a 302

BTIGSBTIGS Member
Hello

We have a web server that is configured in a way that, if it detects an internal failure like in the DB, it returns a 302 code redirecting the request to a sorry page in a URL format

http://<domain>/error

I need to create an script or maybe a healthcheck that allows me to detect that response, and then reselect another rserver in the same service-group. The server can also returns code 302 for a "normal" redirect answer, so I must detect betweend both situations.
The code should be like

when HTTP_RESPONSE {
set destino HTTP::host
if { [HTTP::is_redirect] } {
if { [HTTP::host] contains "error" } {
LB::reselect }
}
}

But of course LB::reselect is not available in HTTP_RESPONSE event, and the line that searchs for "error" string in the URL response doesn't seems to work.
Does anyone have an enviroment like this? How can I force a "reselect" action depending on the server answer to a HTTP query?
Thanks a lot.

PD. I also asked the customer to use another code for this situation so I could set the server to maintenance mode if I receive in a healthcheck but he doesn't want that change...
Tagged:

Comments

  • Options
    edited February 2016
    In this aFleX, the HTTP::retry command retries sending a client’s request to a service port that replies with an HTTP 302 status code.
    If the first server continues to redirect and to reply with a 302 status code after 3 retries, the LB::reselect command reassigns the client request to another server in the same service group.
    It causes SLB to select the next available member from the same service group used for the initial server selection.

    aFlex;

    when CLIENT_ACCEPTED {
    set retry 0
    set max_retry 3
    set reselect 0
    }
    when LB_SELECTED {
    if { $retry > 0 } {
    LB::reselect
    incr reselect
    }
    }
    when HTTP_RESPONSE {
    if { [HTTP::is_redirect] } {
    if { $retry < $max_retry } {
    if { [HTTP::status] contains "302" } {
    incr retry
    }
    }
    }
    }

    I Hope this helps.
  • Options
    BTIGSBTIGS Member
    edited February 2016
    Hi

    Ok, thanks. I'll try it and update if it works.
    Anyway I have a doubt about this script. There's no way to tell the SLB not to select the same server a second time , isn't it? I mean, if we only make it reselect another server of the pool, it could select the same server with the error over and over.

    Again, thanks for your help.
Sign In or Register to comment.