Forum Discussion
irule for F5 to return a message/string
Folks,
i need to do load-balancing based on the "uri" in the url. I have this working BUT need the F5 to return a http code/message like"Use /dev or /qa to go to your environments" if no uri is matched. I don`t need to do a re-direct to another webserver as I do not have one that can send the same message.
Have the folowing irule -
when HTTP_REQUEST {
if {[HTTP::uri] contains "/dev"} {
pool dev-suite-pool
if {[HTTP::uri] contains "/qa"} {
pool qa-suite-pool
} else {
*****test message: please use /dev, or /qa or /uat to go to your respective environments"
}
}
Please advise?
23 Replies
- sandy16
Altostratus
Lastly, This is how my irule looks like - BUT the VIP is showing down as I do not have a default pool configured on it. Also the vip is displaying a blank webpage when opened instead of sending the http response 200.
when HTTP_REQUEST {
if {[HTTP::uri] contains "/dev"} {
pool dev-pool
if {[HTTP::uri] contains "/qa"} {
pool qa-pool
if {[HTTP::uri] contains "/uat"} {
pool uat-pool
}
}
}
else {
HTTP::respond 200 contains "Please use /dev to go to the dev-webserivces-proxies, /qa to go to the qa-webserivces-proxies, /uat to go to the uat-webserivces-proxies"
}
} - What_Lies_Bene1
Cirrostratus
HTTP::respond 200 contains "Please use... should be HTTP::respond 200 content "Please use...
What type of VS is it? If it's a standard VS it's status should show as unknown, not down, with no Pool associated. - Kevin_Stewart
Employee
Try this:when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/dev*" { pool dev-pool } "/qa*" { pool qa-pool } "/uat*" { pool uat-pool } default { HTTP::respond 200 content "Please use /dev to go to the dev-webserivces-proxies, /qa to go to the qa-webserivces-proxies, /uat to go to the uat-webserivces-proxies" noserver Content-Type "text/html" Connection Close } } }
Also add a default pool. - What_Lies_Bene1
Cirrostratus
You're too fast Kevin! Thanks
Here's a slightly more efficient version of your rule;
when HTTP_REQUEST { switch -glob { [string tolower [HTTP::uri]] }{ "/dev*" { pool dev-pool } "/qa*" { pool qa-pool } "/uat*" { pool uat-pool } default { HTTP::respond 200 content "Please use /dev to go to the dev-webserivces-proxies, /qa to go to the qa-webserivces-proxies, /uat to go to the uat-webserivces-proxies" noserver Content-Type "text/html" Connection "Close" } } } - sandy16
Altostratus
I do not get an option of using contents in the irule editor. (It gives contains,concat and continue) only. Even though i used contents, it`s still displaying a blank page. The vip is a standard one, it`s in red displaying "offline/enabled - children pool members are down". - What_Lies_Bene1
Cirrostratus
That's fine, just keep typing, it'll let you enter content (not contents), just tried it myself.
It shouldn't be showing as down unless a pool is assigned and it's members are down. Please doublecheck (and don't miss the Resources tab) - sandy16
Altostratus
yeah it worked with "content".. :)
thnx - What_Lies_Bene1
Cirrostratus
Great news. - sandy16
Altostratus
Another issue -
Its always displaying the default message for response 200 everytime I try different "uris". /dev or /qa..... please advise?
My pools are up. Network is setup in the following way - My vip is in a diff vlan, and my end servers are in different vlan (dev,qa,uat are in different vlans) and the F5 has a arm/self-ip and a floating ip in all these vlans. - Kevin_Stewart
Employee
If you're using either of the two examples given, there's a good chance your URI isn't matching one of the conditions. Please add the following line directly after the 'when HTTP_REQUEST' line and report back the logs from /var/log/ltm:
log local0. "URI = [HTTP::uri]"
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
