Forum Discussion

Wackitron_36350's avatar
Wackitron_36350
Icon for Altocumulus rankAltocumulus
Jul 23, 2018

When HTTP Request has specific hostname and URI, redirect to diff Pool

Hi All,

 

I have been trying to make this below IRule work, But no success. My Client's requirement is to redirect HTTP Traffic for specific Host URL and specific URI to a different Pool. But I am constantly getting this error: TCL error: /Common/poolname - extra switch pattern with no body while executing "switch -glob [string tolower [HTTP::uri]] { "/someURI" { pool "XYZ" } if {$..."

 

when RULE_INIT { set static::Poolxyz_select_debug 1 log local0. "Poolxyz_select" } when HTTP_REQUEST { if {[string tolower [HTTP::host]] starts_with "api-dev" } { switch -glob [string tolower [HTTP::uri]] { "/someURI" { pool XYZ } if {$static::Pool_select_debug eq 1} {log local0. "[IP::client_addr] with URI of [HTTP::uri] went to XYZ Pool"} } } }

 

Please help me out, I am kind of new to switch statement, tried using it different ways but still no success. Thank you in advance.

 

Abe

 

8 Replies

  • Slight modified existing iRule. you can write something like below....

        when RULE_INIT {
         Change to "1" to enable debugging log statements
        set static::Poolxyz_select_debug 0
      }
    
    when HTTP_REQUEST {
        if {[string tolower [HTTP::host]] contains "api-dev" } {
         switch -glob [string tolower [HTTP::uri]] {
          "/someuri" { pool XYZ }
           default     { pool big_pool }
        }
    
        if { $static::Pool_select_debug eq 1 } {
        log local0. "[IP::client_addr] with URI of [HTTP::uri] went to XYZ Pool" 
                 } 
            }
     }
    
    • Wackitron_36350's avatar
      Wackitron_36350
      Icon for Altocumulus rankAltocumulus

      Thank You for the quick response. It looks like this above IRule is working, I do not see the failures on the Statistics Tab. But on the /var/log/ltm, It is hard to trace the URI being redirected to diff pool. Because Other URIs which we did not mention in the Irule also logged as IP with /xyz or /someuri went to the XYZ Pool. It would be easier if we set up a variable for the Pool.

       

      Thank You again for the help.

       

    • Samir_Jha_52506's avatar
      Samir_Jha_52506
      Icon for Noctilucent rankNoctilucent

      Cool, because traffic is going to default pool if uri didn't match. Plz modify URI in lower case('/someuri') and comments these lines in iRule. Rest no change...

       default { pool big_pool }
      

      Update the comments... Cheers...

    • Wackitron_36350's avatar
      Wackitron_36350
      Icon for Altocumulus rankAltocumulus

      Thanks again, I will do that. Also wondering If we can log someruri to XYZ Pool and the rest uris to default pool. Makes lot easier for debugging. Also I will ask the QA to run the tests tomorrow and confirm here if it was successful.

       

  • It looks like you have incorrectly balanced braces.

    Try:
    when RULE_INIT {
      set static::Poolxyz_select_debug 1 
      log local0. "Poolxyz_select" 
    }
    when HTTP_REQUEST { 
      if {[string tolower [HTTP::host]] starts_with "api-dev" } { 
        switch -glob [string tolower [HTTP::uri]] { 
          /someURI { 
            pool XYZ
            if {$static::Pool_select_debug eq 1} {
              log local0. "[IP::client_addr] with URI of [HTTP::uri] went to XYZ Pool"
            }
          }
        }
      }
    }
    

    I think this is the logic you are trying to implement.