Forum Discussion
Hille_de_Graaf_
Nimbostratus
Mar 25, 2008Simplify iRule
I have an iRule which would look at the content of the HTTP-header and loadbalance on behalve of that content.
Is there a more efficient way to build an iRule with the same results as the example below?
when HTTP_REQUEST {
if { [HTTP::uri] ends_with "ACCBPMv1" } {
pool xml-fw
} elseif { [HTTP::uri] ends_with "ACCTVIv1" } {
pool xml-fw
} elseif { [HTTP::uri] ends_with "ACCDVSv1" } {
pool xml-fw
} elseif { [HTTP::uri] ends_with "BPMv1" } {
pool xml-fw
} elseif { [HTTP::uri] ends_with "TVIv1" } {
pool xml-fw
} elseif { [HTTP::uri] ends_with "DVSv1" } {
pool xml-fw
} else {
pool ws-accxml
}
}
Regards,
Hille
2 Replies
- The_Bhattman
Nimbostratus
There are 2 ways I can see this work.
1) Using SWITCH
You can use the switch statementwhen HTTP_REQUEST { switch [HTTP::uri] { "ACCBPMv1" {pool xml-fw } "ACCTVIv1" { pool xml-fw } "ACCTDSv1" { pool xml-fw } "BPMv1" { pool xml-fw } "TVIv1" { pool xml-fw } "DVSv1" { pool xml-fw } } }
orwhen HTTP_REQUEST { switch -glob [HTTP::uri] { "ACC*" {pool xml-fw } "BPMv1" { pool xml-fw } "TVIv1" { pool xml-fw } "DVSv1" { pool xml-fw } } }
orwhen HTTP_REQUEST { switch -glob [HTTP::uri] { "*v1" {pool xml-fw } } }
You would then set the virtual server to the default pool to ws-accxml for any of the switch irules listed above.
2) Using Datagroup the solution looks a bit cleaner.class uricontains { "ACCBPMv2" "ACCBPMv1" "ACCTVIv1" "ACCTDSv1" "BPMv1" "TVIv1" "DVSv1" } when HTTP_REQUEST { if { [matchclass [HTTP::uri] contains $::uricontains] } { pool xml-fw } else {pool xml-accxml } }
Hope this helps
/CB - Nicolas_Menant
Employee
Hi,
Switch is the most efficient way to do the job if you have < 100 entries. If you have more entries then datagroup is the most efficient one
HTH
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
