I have a simple irule that works fine for what I need. A request comes in (say to www.mypage.co.uk), if the LB pool has no active nodes the client request is redirected to a " sorry" page.
If you want to redirect to the host or URI that the client made a request to, you’d need to save the host or URI in HTTP_REQUEST for every request and then reference it in LB_FAILED:
when HTTP_REQUEST {
Save the host header value
set host [HTTP::host]
Save the URI (not sure you want to do anything with the URI though)
set uri [HTTP::uri]
}
when LB_FAILED {
Send 302 redirect with the host header value from the request
HTTP::respond 302 Location "http://$host/sorry/"
}
but because there are no servers available (LB_FAILED) i redirect them to another url : www.sorry.com.
However, I want to retain their original url in the browser so if they just click refresh it comes back www.mypage.com and if there are any servers available they get the content they expected, if not back through the above cycle.
sorry about the convoluted description, but as you can guess irules and not my expertise!
when CLIENT_ACCEPTED {
Initialise a variable to track whether the load balancing attempt has failed
set retries 0
}
when HTTP_REQUEST {
Check if there has been a load balancing failure
if { $retries > 0 } {
Rewrite the URI if it hasn't already been rewritten
if {not ([HTTP::path] contains "sorry")}{
Rewrite the URI for the sorry page
HTTP::uri "/sorry/sorry.html"
}
} else {
This isn't a retry, so save the request headers and data
set request [HTTP::request]
}
}
when LB_SELECTED {
Check if there has been a load balancing failure
if { $retries >= 1 } {
Select a new pool member from the sorry pool
LB::reselect pool sorry_pool
}
}
when LB_FAILED {
Track that the load balancing attempt failed
incr retries
Retry the HTTP request
HTTP::retry $request
}
when HTTP_RESPONSE {
There was a successful response, so we could reset retries to 0?
set retries 0
}
If the sorry.html page references images or other content, you might need to add logic to HTTP_REQUEST to specify the sorry pool for any request which has “sorry” in the path.
If this doesn’t work for you, can you add logging to the iRule and post the log output from /var/log/ltm?