Forum Discussion
iRule to redirect based on path plus fallback host
when HTTP_REQUEST {
switch -glob -- [string tolower [HTTP::path]] {
"/a*" -
"/b*" {
if {[active_members pool_1] < 1} {
Log and direct the client to Maintenance pool
log local0. "!!Maintenance page called for Pool1!!"
pool Fallback_Pool }
else {
pool pool_1
}
"/c*" -
"/d*" {
if {[active_members pool_2] < 1} {
Log and direct the client to Maintenance pool
log local0. "!!Maintenance page called for Pool2!!"
pool Fallback_Pool }
else {
pool pool_2
}
default { discard }
}
}
7 Replies
- Shahram_83722
Nimbostratus
Anyone? - Brian_69413
Nimbostratus
rather than an if statement inside the cases, just use the LB_FAILED event to catch when no pool members are available and assign to the fallback pool. I think this would be a more efficient way to handle this since both cases use the same fallback pool. - hoolio
Cirrostratus
The rule you have looks okay. The curly braces weren't exactly correct, but I assume that's just an issue with the editing you did for the post.
Here's your original version with balanced braces:when HTTP_REQUEST { switch -glob -- [string tolower [HTTP::path]] { "/a*" - "/b*" { if {[active_members pool_1] < 1} { Log and direct the client to Maintenance pool log local0. "!!Maintenance page called for Pool1!!" pool Fallback_Pool } else { pool pool_1 } } "/c*" - "/d*" { if {[active_members pool_2] < 1} { Log and direct the client to Maintenance pool log local0. "!!Maintenance page called for Pool2!!" pool Fallback_Pool } else { pool pool_2 } } default { discard } } }
You could move the active_members check of the pool outside the switch statement to simplify the rule a little:when HTTP_REQUEST { switch -glob -- [string tolower [HTTP::path]] { "/a*" - "/b*" { pool pool_1 } "/c*" - "/d*" { pool pool_2 } default { discard return } } if {[active_members [LB::server pool]] < 1} { Log and direct the client to Maintenance pool log local0. "!!Maintenance page called for [LB::server pool]!!" pool Fallback_Pool } }
Aaron - hoolio
Cirrostratus
Posted By Brian on 06/18/2012 01:01 PM
...use the LB_FAILED event to catch when no pool members are available and assign to the fallback pool.
That would work too :)
Aaron - Shahram_83722
Nimbostratus
Thank you guys for the input. I greatly appreciate it.
I've tried using the LB_FAILED before and it did not work for me, but the check for active members did so I'm not quite sure I want to use that. It could have been an error on my part...
Aaron, the reason I kept the members check within the switch statement is because I don't want the absence of a member on one of the pools to trigger a fallback for the whole VS, although my fallback server can serve all paths.
I saw you use the 'return' command. I've read the online documentation on it but haven't quite gotten an understanding of it. Could you tell me what it exactly does? - hoolio
Cirrostratus
return exits out of the current event of the current iRule. So basically, the active_members check on the currently selected pool won't be run if the request is to a URI that's set for being dropped.
The [LB::server pool] command will return the name of the currently selected pool. So it should work fine to move that check out of the switch statement.
Aaron - Shahram_83722
Nimbostratus
Thank you Aaron. I'll use your rule and see how it goes.
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
