Forum Discussion

Jeff_Morrison_4's avatar
Jeff_Morrison_4
Icon for Nimbostratus rankNimbostratus
Dec 05, 2007

Combine iRules

When I try and combine these 2 rules into one, the second half of the rule (elseif) doesn't seem to work properly. I have the rules listed seperately on the VIP, but I have 40 rules and would like to combine them into one rule to administor.

 

 

 

1st rule:

 

 

when HTTP_REQUEST {

 

if { [HTTP::uri] contains "/ABC"

 

}{

 

pool WLS-V10

 

} elseif { [HTTP::uri] contains "/XX3333"}{

 

HTTP::uri [string map {/XX3333/ /ABC/} [HTTP::uri]]

 

pool WLS-V10

 

}}

 

 

 

 

2nd Rule:

 

 

when HTTP_REQUEST {

 

if { [HTTP::uri] contains "/DEF"

 

}{

 

pool WLS-V10

 

} elseif { [HTTP::uri] contains "/XX4279"}{

 

HTTP::uri [string map {/XX4279/ /DEF/} [HTTP::uri]]

 

pool WLS-V10

 

}}

 

 

 

Thanks for help in advance.

 

 

Jeff

 

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    Combined, those would look something like:

    
    when HTTP_REQUEST {
      if { ([HTTP::uri] contains "/ABC") or ([HTTP::uri] contains "/DEF") } {
        pool WLS-V10
      } elseif { [HTTP::uri] contains "/XX3333"}{
        HTTP::uri [string map {/XX3333/ /ABC/} [HTTP::uri]]
        pool WLS-V10
      } elseif { [HTTP::uri] contains "/XX4279"}{
        HTTP::uri [string map {/XX4279/ /DEF/} [HTTP::uri]]
        pool WLS-V10
      }
    }

    HTH,

    Colin
  • Hi Jeff,

    A switch statement (Click here) would help you organize the two rules into one:

    
    when HTTP_REQUEST {
       log local0. "Client [IP::client_addr] requested [HTTP::host][HTTP::uri]"
       switch -glob [HTTP::uri] {
          */ABC* -
          */DEF* {
             log local0. "Client [IP::client_addr] matched first case, sending to pool WLS-V10."
             pool WLS-V10
          }
          */XX3333* {
             log local0. "Client [IP::client_addr] matched second case, rewriting URI to /ABC/, sending to pool WLS-V10."
             HTTP::uri [string map {/XX3333/ /ABC/} [HTTP::uri]]
             pool WLC-V10
          }
          */XX4279* {
             log local0. "Client [IP::client_addr] matched third case, rewriting URI to /ABC/, sending to pool WLS-V10."
             HTTP::uri [string map {/XX4279/ /ABC/} [HTTP::uri]]
             pool WLC-V10
          }
          default {
             log local0. "Client [IP::client_addr] didn't match any case."
          }
       }
    }

    This should exactly replicate your two rules. Note that the -glob flag on switch enables wildcard matching. So the *'s will match any number of any characters. If you only want to match requests with URIs starting with /ABC or /DEF, use /ABC* and /DEF*.

    If you're not sure that the rule is working correctly, uncomment the log statements and check the /var/log/ltm log file (tail -f /var/log/ltm).

    Aaron

  • Thanks Colin and Aaron. On my next maintenance window I will try both of these rules.

     

     

    Jeff