Forum Discussion
abeny_894
Nimbostratus
Dec 03, 2008How to combine two iRules into one?
Dears,
First of all, I would like to say thanks to all of you that I have learned much on iRules in here.
I have a question on how can I combine separate iRules into ONE? The situation is I have got several separate iRules on hand as below: They are all using HTTP_REQUEST, the different is iRules One is using [HTTP::host], iRules Two is using [HTTP::uri], iRules Three is using [HTTP::host][HTTP::uri]. If test separatly, they all work fine for apply to One VS.
As the real case may involve ALL of the below case in one VS, I would like to ask can they be combine into one? How can I do this?? Thank you very much for you guys help.
___________________________________________________________________________________
****iRules One****
when HTTP_REQUEST {
switch [HTTP::host] {
abc.com {
log local0. "hit abc.com"
Details scriptes
xyz.com {
log local0. "hit xyz.com"
Details scripts
****iRules Two****
when HTTP_REQUEST {
switch [HTTP::uri] {
/app1/index.html {
log local0. "hit abc/app1/index.html"
Details scriptes
/app2/index.html {
log local0. "hit xyz/app1/index.html"
Details scriptes
****iRules Three****
when HTTP_REQUEST {
switch [HTTP::host][HTTP::uri] {
abc.com/app1/index.html {
log local0. "hit abc.com"
Details scriptes
xyz.com/app2/index.html {
log local0. "hit xyz.com"
Details scripts
___________________________________________________________________________________
8 Replies
- Colin_Walker_12Historic F5 AccountWhat you would probably want to do is combine all of the cases into one large switch. You could use switch -glob [HTTP::host][HTTP::uri] to accomplish this. Then for the host only matches use something like "abc.com*" for the match, and for the uri only matches use "*/app1/index.html". Then you would leave the host and uri comparisons the same, and one switch should handle all of the above cases.
Let me know if this doesn't make sense and I'll show you what it would look like combined.
Colin - abeny_894
Nimbostratus
Sorry that I can't make the combine irules well. Always got error... Would you kindly help to give me a sample look like?? Thanks a lot. - abeny_894
Nimbostratus
Colin, I have combine the iRules into one and shown as below:
Is there need changes and match the suggestion?? Thanks a lot~
--------------------------------------------------------
when HTTP_REQUEST {
switch -glob [HTTP::host][HTTP::uri] {
"test1.f5lab.com*" {
log local0. "hit test1.f5lab.com"
set site a
incr ::total_active_clients_a
log local0. "total requests are $::total_active_clients_a"
set start_time_a $cur_time_a
if { [LB::status pool websrv_REMOTE_pool member 10.1.1.1 80] eq "down" } {
pool websrv_busypool
return
}
if { $cur_time_a == $start_time_a } {
if { $::total_active_clients_a <= $::max_active_clients_a } {
pool websrv11_pool
return
}
}
if { $cur_time_a == $start_time_a } {
if { $::total_active_clients_a >= $::max_active_clients_a } {
pool websrv_busypool
return
}
}
}
}
switch -glob [HTTP::host][HTTP::uri] {
"*/app1/index.html" {
log local0. "hit test1.f5lab.com/app1/index.html"
set site a
incr ::total_active_clients_a
log local0. "total requests are $::total_active_clients_a"
set start_time_a $cur_time_a
if { [LB::status pool websrv_REMOTE_pool member 10.1.1.1 80] eq "down" } {
pool websrv_busypool
return
}
if { $cur_time_a == $start_time_a } {
if { $::total_active_clients_a <= $::max_active_clients_a } {
pool websrv11_pool
return
}
}
if { $cur_time_a == $start_time_a } {
if { $::total_active_clients_a >= $::max_active_clients_a } {
pool websrv_busypool
return
}
}
}
default {
log local0. "hit default"
set site a
incr ::total_active_clients_a
log local0. "total requests are $::total_active_clients_a"
set start_time_a $cur_time_a
if { [LB::status pool websrv_REMOTE_pool member 10.1.1.1 80] eq "down" } {
pool websrv_busypool
return
}
if { $cur_time_a == $start_time_a } {
if { $::total_active_clients_a <= $::max_active_clients_a } {
pool websrv11_pool
return
}
}
if { $cur_time_a == $start_time_a } {
if { $::total_active_clients_a >= $::max_active_clients_a } {
pool websrv_busypool
return
}
}
}
}
}
________________________________________________________ - abeny_894
Nimbostratus
Thanks a lot Colin. You really help me lots. For real situation, i need check the pool status in every condition, but i found that it seems can't work under "switch -glob", it prompt error " [parse error: PARSE syntax 924 {syntax error in expression " How can I use switch -glob to switch case also monitor the pool status at the same time??
__________________________________________________
when HTTP_REQUEST {
switch -glob {[HTTP::host][HTTP::uri]} {
"test1.f5lab.com*" {
log local0. "hit test1.f5lab.com"
set site a
incr ::total_active_clients_a
log local0. "total requests are $::total_active_clients_a"
set start_time_a $cur_time_a
if { $cur_time_a == $start_time_a } {
if { $::total_active_clients_a <= $::max_active_clients_a } {
pool websrv11_pool
return
}
}
if { $cur_time_a == $start_time_a } {
if { $::total_active_clients_a >= $::max_active_clients_a } {
if { [LB::status pool websrv_REMOTE_pool member 218.189.236.228 80] eq "down"
pool websrv_busypool
return
}
}
}
} - abeny_894
Nimbostratus
Hi Colin,
I found that the iRules can't work after i modify as below:
________________________________________________________
when HTTP_REQUEST {
incr requestCount -1
switch -glob {[HTTP::host][HTTP::uri]} {
"test1.f5lab.com*" {
log local0. "hit test1.f5lab.com"
set site a
incr ::total_active_clients_a
log local0. "total requests are $::total_active_clients_a"
set start_time_a $cur_time_a
if { $cur_time_a == $start_time_a } {
if { $::total_active_clients_a <= $::max_active_clients_a } {
pool websrv11_pool
return
}
}
if { $cur_time_a == $start_time_a } {
if { $::total_active_clients_a >= $::max_active_clients_a } {
pool websrv_busypool
return
}
}
if { $cur_time_a == $start_time_a } {
if { $::total_active_clients_a >= $::max_active_clients_a } {
pool websrv_busypool
return
}
}
}
"xyz.com*" {
log local0. "hit xyz.com"
set site a
incr ::total_active_clients_a
log local0. "total requests are $::total_active_clients_a"
set start_time_a $cur_time_a
if { $cur_time_a == $start_time_a } {
if { $::total_active_clients_a <= $::max_active_clients_a } {
pool websrv11_pool
return
}
}
}
________________________________________________________
Am I miss something?? When i use httpwatch to see deep in, it shows "No response headers received because request failed : ERROR_INTERNET_CANNOT_CONNECT"
Thanks for your help - abeny_894
Nimbostratus
AnyBody can help?
If the HTTP_REQUEST using
__________________
switch [HTTP::host]
test1.f5lab.com {
--------------------------------
It works fine.
if the HTTP_REQUEST using
___________________________________
switch -glob {[HTTP::host][HTTP::uri]} {
"test1.f5lab.com*" {
-------------------------------------------------------------
It can't works.
Is the switch -glob got some problem inside?? - hwidjaja_37598
Altostratus
Try this:when HTTP_REQUEST { switch -glob "[HTTP::host][HTTP::uri]" { "test1.f5lab.com*" { - hoolio
Cirrostratus
If you're only checking the host in the switch statement, you could leave off the -glob flag and the URI:switch [string tolower [HTTP::host]] { "test1.f5lab.com" {
As the host header value is case insensitive, it would make sense to set it to lowercase and use lowercase in the hosts.
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
