Forum Discussion

Brian_Kenworthy's avatar
Brian_Kenworthy
Icon for Nimbostratus rankNimbostratus
Jul 31, 2009

Rule Modification Help with Switch

Hi all, I have the following existing rule that we will be adding another pool to. I am using the switch command, but am wondering if I need to add some if/else clauses. Here's the existing rule:

 

when HTTP_REQUEST {

 

switch -glob [string tolower [HTTP::uri]] {

 

"/xml/order.asp*" -

 

"/xml/status.asp*" -

 

"/vmsxml/order.asp*" -

 

"/vmsxml/status.asp*" -

 

"/_xmlbeta/status_mismo21.asp*" -

 

"/_xmlbeta/status.asp*" -

 

"/_xmlbeta/rels_status_mismo21.asp*" -

 

"/vendor/status.asp*" {

 

host.mydomain.com_B2B_HTTPS

 

}

 

default {

 

host.mydomain.com_GUI_HTTPS

 

}

 

}

 

}

 

We are adding a new URI to the existing URL which will forward the traffic to the new pool:

 

"/BatchProcessing*" -

 

host.mydomain.com_BatchPro_HTTPS

 

I'm not quite sure how to add this with the switch command...do I need to use an if/else clause in my rule, or can I add another switch command? You help is much appreciated!

 

Thanks in advance,

 

Brian

4 Replies

  • Just added it before the "default" case.

     when HTTP_REQUEST { 
       switch -glob [string tolower [HTTP::uri]] { 
         "/xml/order.asp*" - 
         "/xml/status.asp*" - 
         "/vmsxml/order.asp*" - 
         "/vmsxml/status.asp*" - 
         "/_xmlbeta/status_mismo21.asp*" - 
         "/_xmlbeta/status.asp*" - 
         "/_xmlbeta/rels_status_mismo21.asp*" - 
         "/vendor/status.asp*" { 
           pool host.mydomain.com_B2B_HTTPS 
         } 
         "/BatchProcessing*" { 
           pool host.mydomain.com_BatchPro_HTTPS 
         } 
         default { 
           pool host.mydomain.com_GUI_HTTPS 
         } 
       } 
     }

    The dashes after the ones you already have are a way to do a logical "or" for a match for any of them. You can add as many match strings as you want like I did above if you want to expand your iRule.

    BTW, I assume you accidentally omitted the "pool" statement from the match cases. If not, I didn't know you could just add a pool name without the actual "pool" command before it.

    -Joe
  • Hi Joe, I did omit the "pool" from the original post, but am I missing a "-" somewhere? I am getting a 404 after modifying the rule now, but not seeing anything in my weblogs. Here's the exact syntax I am using on the rule:

     

     

    when HTTP_REQUEST {

     

    switch -glob [string tolower [HTTP::uri]] {

     

    "/clientmismo/order.asp*" -

     

    "/vendormismo2/status.asp*" -

     

    "/vmsxml/order.asp*" -

     

    "/vmsxml/status.asp*" -

     

    "/_xmlbeta/ors/status_mismo21.asp*" -

     

    "/_xmlbeta/ors/status.asp*" -

     

    "/_xmlbeta/ors/rels_status_mismo21.asp*" -

     

    "/vendornla/status.asp*" {

     

    pool beta3.res-direct.com_B2B_HTTPS

     

    }

     

    "/BPro*" {

     

    pool beta3.res-direct.com_BatchPro_HTTPS

     

    }

     

    default {

     

    pool beta3.res-direct.com_GUI_HTTPS

     

    }

     

    }

     

    }

     

     

    Thanks!
  • The only thing I can see is that you are doing a "string tolower" on your URI but comparing it to "/BPro*" which is not lower case. That was my bad for not noticing that in the previous post. First thing I would do would be to replace "/BPro*" with "/bpro*". If that doesn't work, you'll need to do some logging to look at the inbound URI's and then where they are getting matched. This can be done with something like this:

    when HTTP_REQUEST {  
       log local0. "Request for URI [string tolower [HTTP::uri]]" 
       switch -glob [string tolower [HTTP::uri]] {  
         "/clientmismo/order.asp*" -  
         "/vendormismo2/status.asp*" -  
         "/vmsxml/order.asp*" -  
         "/vmsxml/status.asp*" -  
         "/_xmlbeta/ors/status_mismo21.asp*" -  
         "/_xmlbeta/ors/status.asp*" -  
         "/_xmlbeta/ors/rels_status_mismo21.asp*" -  
         "/vendornla/status.asp*" {  
           log local0. "Matched first case" 
           pool beta3.res-direct.com_B2B_HTTPS  
         }  
         "/bpro*" {  
           log local0. "Matched /bpro*" 
           pool beta3.res-direct.com_BatchPro_HTTPS  
         }  
         default {  
           log local0. "Match not found, defaulting to beta3.res-direct.com_GUI_HTTPS pool" 
           pool beta3.res-direct.com_GUI_HTTPS  
         }  
       }  
     }

    Run a request through this and look in your /var/log/ltm logfile on your BIG-IP to see where it's going wrong.

    Hope this helps...

    -Joe
  • Yep, that was it...forgot that we lower the string so that the client can use any case. Not sure how I missed that either. Thanks again, it's working like a charm.