Forum Discussion

abeny_894's avatar
abeny_894
Icon for Nimbostratus rankNimbostratus
Dec 03, 2008

How 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_12's avatar
    Colin_Walker_12
    Historic F5 Account
    What 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
  • 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.
  • 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

     

    }

     

    }

     

    }

     

    }

     

    }

     

     

     

    ________________________________________________________

     

     

     

  • 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

     

    }

     

    }

     

    }

     

    }

     

  • 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
  • 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??

     

  • Try this:

     
     when HTTP_REQUEST { 
     switch -glob "[HTTP::host][HTTP::uri]" {  
     "test1.f5lab.com*" {  
     
  • 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