Forum Discussion

lunitic_56137's avatar
lunitic_56137
Icon for Nimbostratus rankNimbostratus
Aug 15, 2012

Switch statement not working

I have an 11.2 deployment that is using this iRule. The issue is that the Switch statement will not work.

 

 

"when HTTP_REQUEST {

 

switch -glob [HTTP::uri] {

 

"/uri1" -

 

"/uri2" {

 

HTTP::redirect "https://newvirtual.server.com"

 

}

 

"/uri3" -

 

"/uri4" {

 

node 1.1.1.1 80

 

}

 

}

 

if { [matchclass [HTTP::uri] contains uri_address_external_file ] } {

 

log local0. "Match found Sending to J2EE_Pool"

 

pool J2EE_Pool

 

}

 

else {

 

log local0. "No match in the list. Forwarding to Offsite destination"

 

HTTP::redirect "http://other.site.com"

 

}

 

}"

 

 

Originally I had it between the IF and the ELSE and it worked. Moving it up to the top makes it not work at all. Ideas?

 

6 Replies

  • Can you provide any more details? It's hard to figure out from here without knowing the test cases you are passing in and what results you are seeing (or not).

    The one thing that sticks out is that I'm not sure if you can call the "node" command and then call the "pool" command. If the URI is "/uri3" and it also is returned from the matchclass command, you could have both commands executing. That may work, but I'm not sure.

    I'd start with some logging. You can throw in "log local0. 'blah blah blah'" before each of the other commands and look in the /var/log/ltm file to see if the logic is working.

    If you don't want the if/else logic processed if one of the previous "switch" matches passes, then you can include it in a default case for the switch

    switch -glob [HTTP::uri] {
      "/uri1" -
      "/uri2" {
        HTTP::redirect ...
      }
      "/uri3" -
      "/uri4" {
        node 1.1.1.1 80
      }
      default {
        if { [matchclass ... } {
          pool J2EE_pool
        } else {
          HTTP::redirect http://other.site.com
        }
      }
    }

    Not sure if that will help or not, but hopefully lead you in the right direction.

    -Joe

  • ok, more details then.

     

     

    When I go to the VS, with a URI in either the data group list or one of the ones in the IF/ELSE statement, it works fine. If I use URI 1,2,3,or 4 they do not redirect to the node or the URL. I can move the switch statement down between the IF and the ELSE and test any of the URI's 1-4 and they get redirected.

     

     

    I will try adding the IF/ELSE to the switch statement as you suggested. Thanks Joe.
  • I changed the rule and I still cannot get it to match on uri1-4. The other statements work fine.
  • Can you log the value of the URI and verify it's what you're expecting fo rthe URI1-4 cases? If you want to compare paths and not the full URI (path + query string = URI), you can use [HTTP::path] instead of [HTTP::uri].

     

     

    Aaron
  • Yes the logs show the correct URI's. I will try the path statement instead of uri.

     

     

    Thanks Hoolio
  • Just trying to clarify things. Are you saying that with a URI of "/uri3" the switch is not matching and falling through and executing the "node 1.1.1.1 80" command, or are you saying that it is calling the command but the command has no effect?