Forum Discussion
Kim_Stephan_510
Nimbostratus
Nov 19, 2012URL to Node persistency
Hello,
I have to write some iRule for Customers and i'm not sure that i'm done correctly, but I can't test it.
Following situation:
Some Application-Servers (Nodes) do sent directly (bypass LTM) to Client some Content and a defined URL. The Client has to work with this content (could be from 5 minutes to 10h) and then use the URL given from the Server (something like this):https://customer.integration.vendor.com/application
So I've copied ( 😉 ) and changed following iRule:
when HTTP_REQUEST {
switch -glob [HTTP::uri] {
"*customer.integration.vendor.com/application 1" { pool poolname member ip port }
"*customer.integration.vendor.com/application 2" { pool poolname member ip port }
}}
is this working for me? Do I need some case when none of the URLs are matched?
Thank you and kind regards,
Kim11 Replies
- What_Lies_Bene1
Cirrostratus
As you are switching on the URI, your switch statements should only contain "/application1*" and end with a wildcard *. Yes, you should use 'default' to catch anything not matched. Here's my take;when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/application1*" { pool poolname member ip port } "*application2*" { pool poolname member ip port } default { pool some-pool-name } } }
Also see here for how you might check that each pool member is up: https://devcentral.f5.com/wiki/iRules.pool.ashx - Kim_Stephan_510
Nimbostratus
Hello Steve,
thank you for your answer.
What have i to use when "customer", "vendor" and "application" are variable?
Kind regards,
Kim - What_Lies_Bene1
Cirrostratus
How many possible URIs are there? - Kim_Stephan_510
Nimbostratus
maximum ten to twelth possibilities.
I thought i manually actualize the iRule when something is changing (should not be so often)...
why i can't use switch with the whole URL? Should i use regex instead?
Thank you and kind regards,
Kim - What_Lies_Bene1
Cirrostratus
You can switch with the whole URL, use something like this instead;
when HTTP_REQUEST {
set clienturl [string tolower [HTTP::host]][string tolower [HTTP::uri]]
switch -glob $clienturl {
"*/application1*" { pool poolname member ip port }
"*application2*" { pool poolname member ip port }
default { pool some-pool-name }
}
}
I can rewrite the rule for that number no problem and I might have suggested a Data Group if there were a great number of URLs but 12 should be manageable, I might do it anyway as it reduces the risk of errors when updating the URLs.
A regex would be far more CPU intensive.
Before I do the final rewrite, can I just check, are all 12 URLs going to the same member? - Kim_Stephan_510
Nimbostratus
I do not understand why you use now[string tolower [HTTP::host]]
My TCL Programming Skills are very low, i'm sorry.
I do have 4 Members (2 Members in 2 Pools). What is the Problem when I'm using the whole URL insted of only "*/application1"?
Kind regards,
Kim - What_Lies_Bene1
Cirrostratus
string tolower just makes everything lower case which makes the matching easier as you don't have to worry about case sensitivity.
You can do it with the whole URL if you want, it's just simpler not to if you can use wildcards and be sure everything you need to gets matched. - Kim_Stephan_510
Nimbostratus
I did not mean the command tolower, but [HTTP::host] for what I do need this one in this case? - What_Lies_Bene1
Cirrostratus
If you wanted to include the full URL in the switch statements you would need [HTTP::host] as well as [HTTP:uri]. Host is the www.xxx.com bit, URI is the the first / onwards. - Kim_Stephan_510
Nimbostratus
ah, ok. Thank you.
Now I think i could write this iRule... if I need further support I will go to write here again.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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