Forum Discussion
Natalia_Wolosec
Nimbostratus
Aug 01, 2011Irule for rerouting to different pools
Hi All,
I currently have an in production virtual server on my F5 which also has a SSL certification. My organisation would like to be able to use the same URL to take advantage of the certificate, but to reroute to another pool of test servers which using a /test on the url.
So for example www.example.com to go to the existing pool members (poollive) and www.example.com/test to go to a new test pool of members (pooltest)
I've created an irule to try to get this to do this procedure.
Can anyone confirm if this irule is correct, or needs some additional work.
when HTTP_REQUEST {
if { [HTTP::uri] contains "test" }
pool pooltest
}
else {
pool poollive
}
}
Can someone advise if this would be correct?
Thanks,
11 Replies
- Peter_72728
Nimbostratus
Looks like a reasonable start...
I'd suggest this minor change...
if { [HTTP::uri] starts_with "/test" }
That's a little more specific and would avoid the situation where a URL with "test" in the middle is sent to the wrong pool (e.g. /application/testpage.htm should go to poollive)
Once you start using logic like this, it's common to have more URI patterns that need to be sent to another pool. When that happens, I'd recommend going to a format like the following. As the list grows, this tends to be easier to read. (*note this example code is untested)switch -glob [HTTP::uri] { "/test*" - "/another_url_that_shouldnt_be_live/index.htm" { pool pooltest } "/someOtherPool*" {pool poolother) default { pool poollive } }
See here for more info about switch...
http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/244/Switch-Gone-Wild-Using-Wildcards-with-the-Tcl-switch-command.aspx - The_Bhattman
Nimbostratus
Hi Natalia,
I would also recommend using the following statement;
[string tolower [HTTP::uri]] instead of just [HTTP::uri].
This will ensure your strings in the switch match up to the URI without being concerned about capitalization.
Bhattman - Pconlan_71037
Altocumulus
I use yet another variation similar to what Peter and Bhattman suggested:
switch -glob [string tolower [HTTP::path]]
{
"/test*" -
"/another_url_that_shouldnt_be_live/index.htm" { pool pooltest }
"/someOtherPool*" {pool poolother)
default {
pool poollive
}
}
I use HTTP::path, which just excludes the querystring, since I don't need that to makemy switching decision. I have about 8 paths in my switch statement and it works very well. - Natalia_Wolosec
Nimbostratus
Hi Guys,
Thanks for your comments.
I'm now ready to execute the irule on my F5, but would like to clarify the configuration.
switch -glob [string tolower [HTTP::path]]
{
"/test*" { pool pooltest }
default {
pool poollive
}
}
Pool live is the default which all connections need to go to except when /test URL is requested.
This is only temporary for a migration process, and just wondered if the above will do the trick?
I'm just conceous as this is on a live environment.
Thanks,
Natalia - JRahm
Admin
yep, that should work fine. If you want another layer of feel-good before applying to your live virtual, you could create a dummy virtual with the same parameters and apply your rule there to make sure it does as you expect before applying to the prod traffic. - nwoloseckyj_684
Nimbostratus
Hi It's Natalia,
Unfortunately when I applied that irule it told me I didnt have an up to date version. running v9.
So can you confirm this would do the same thing?
when HTTP_REQUEST {
if { [HTTP::uri] contains "\new" }{
pool new
} else {
pool default
}
} - hoolio
Cirrostratus
The switch command should work in any LTM version. What's the exact iRule you tried and what error did you see?
Aaron - nwoloseckyj_684
Nimbostratus
switch -glob [string tolower [HTTP::path]]
{
"/new*" { pool new}
default {
pool default}
} - nwoloseckyj_684
Nimbostratus
This is the error I get:
01070151:3: Rule [OSS_TestPool] error:
line 1: [command is not valid in the current scope] [switch -glob [string tolower [HTTP::path]] ]
line 1: [command is not valid in the current scope] [string tolower [HTTP::path]]
line 1: [command is not valid in the current scope] [HTTP::path]
line 2: [undefined procedure:
"/new*" { pool oss-pci-dmz-pool }
default {
pool oracle10g-oss-pool
}
] [{
"/new*" { pool oss-pci-dmz-pool }
default {
pool oracle10g-oss-pool
} - hoolio
Cirrostratus
Can you put it in the HTTP_REQUEST event?when HTTP_REQUEST { switch -glob [string tolower [HTTP::path]] { "/new*" { pool new} default { pool default } } }
Aaron
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects
