Forum Discussion
error code 503 redirect irule
Hello, I want to create a logical path in F5 where if one server pool is down, we get an error code 503, then a redirect happens to a second pool. This is what I have written, but does not seem to redirect when the second pool is offline. Is the i-rule OK but need to set priority activation on the pools or is there something flawed with the irule?
here is it below;
when HTTP_RESPONSE {
# Check if the response status code from the server is 503
if {[HTTP::status] == 503} {
# Log the action (optional, for troubleshooting)
log local0. "Received 503 from backend. Reselecting to fallback_pool."
# Attempt to select an alternate pool
pool ta55-web-lb-dev-f5-ssl-pool2
} else {
pool ta55-web-lb-dev-f5-ssl-pool
}
}
Injeyan, thanks for reaching out with your help. I wanted to share that we got this to work and I wanted to show how.
I applied this i-rule intially;
when HTTP_REQUEST {
if { [HTTP::uri] contains "/pssmetrics" }{
pool web-lb-dev-f5-ssl-pool2
} else {
pool web-lb-dev-f5-ssl-pool
}
}
That specifies I want that uri to go to pool2. In pool 2 I have server 1 and server 2. Pool (1) only has server 1. Within pool2, I have a custom healh monitor, and when you mentioned a health monitor, that got me thinking along that track. Within the custom monitor, the pool member with the active service for pssmetrics will get the traffic load balanced to it, the condition being anytime there is a 503 error code.
So as follows;
Send String:
GET /pssmetrics HTTP/1.1\r\nHost: webfrontendalias.domain.org\r\nConnection: Close\r\n\r\n
Receive String:
302
(No OK after this, the regex gets cranky)
Receive Disable Strng:
503
6 Replies
- Injeyan_Kostas
Nacreous
This will never work that way.
You cannot assign a pool at Response event
You should have proper monitor on your pool and select a different pool if all members of first pool are down.
Try something like this on Request event
if { {[active_members poolName] < 1} } { pool fallbackPool } Hi,
i am also suggest the same method
when HTTP_REQUEST {
if { [active_members pool_primary] > 0 } {
pool pool_primary
} elseif { [active_members pool_secondary] > 0 } {
pool pool_secondary
} else {
HTTP::respond 503 content "Service Unavailable"
}
}BR
Aswin- cgwin12
Altocumulus
I thank you for this feedback. I need to include another detail. We have a situation where the pools will be up, but a specific application will be up on one pool and down on another. For example, https://webserver/pssmetrics may serve on pool 2, but not pool 1. If I get a 503 error code on pool 1 (the default), I want to failover to pool 2. I had an irule to look point to a pool based off uri. It won;t work for our purposes, but gives you an idea of how I want to redirect.
when HTTP_REQUEST {
if { [HTTP::uri] contains "/pssmetrics" }{
pool ta55-web-lb-dev-f5-ssl-pool2
} else {
pool ta55-web-lb-dev-f5-ssl-pool
}
}- Injeyan_Kostas
Nacreous
The approach is still the same
In your case you should just treat the specific path as unique application, meaning a dedicated pool with a specific health monitor. So the monitor is the one that will catch the 503 response beforehand.
If you wait to check the response to the clint it's already too late
when HTTP_REQUEST { if { [HTTP::uri] contains "/pssmetrics" }{ if { [active_members ta55-web-lb-dev-f5-ssl-pool2] > 0 } { pool ta55-web-lb-dev-f5-ssl-pool2 } else { pool ta55-web-lb-dev-f5-ssl-pool } } }
- cgwin12
Altocumulus
Injeyan, thanks for reaching out with your help. I wanted to share that we got this to work and I wanted to show how.
I applied this i-rule intially;
when HTTP_REQUEST {
if { [HTTP::uri] contains "/pssmetrics" }{
pool web-lb-dev-f5-ssl-pool2
} else {
pool web-lb-dev-f5-ssl-pool
}
}
That specifies I want that uri to go to pool2. In pool 2 I have server 1 and server 2. Pool (1) only has server 1. Within pool2, I have a custom healh monitor, and when you mentioned a health monitor, that got me thinking along that track. Within the custom monitor, the pool member with the active service for pssmetrics will get the traffic load balanced to it, the condition being anytime there is a 503 error code.
So as follows;
Send String:
GET /pssmetrics HTTP/1.1\r\nHost: webfrontendalias.domain.org\r\nConnection: Close\r\n\r\n
Receive String:
302
(No OK after this, the regex gets cranky)
Receive Disable Strng:
503
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com