Forum Discussion

qliang_231469's avatar
qliang_231469
Icon for Nimbostratus rankNimbostratus
Sep 11, 2018

Get URI and Direct to the pool with part of the URI number

Hi Pros,

 

I have a questions, I have a irule

 

like this

 

set uri_info [string tolower [HTTP::uri]] switch -glob $uri_info { "/sj-01/" {pool marketing-lead-01 } "/sj-02/" {pool marketing-lead-02} "/sj-03/*" {pool marketing-lead-03} ... default {pool marketing-lead-default-pool}

 

So every time, i will need to manually add the URI conditions when I have different URI serving different pool.

 

I wonder if any pros could help on my pool tclsh, how it could be done with something like this

 

switch -glob $uri_info { "/sj-$variable/" {pool marketing-lead-$variable } if no "/sj-/*" match, then go to default pool

 

i appreciate anyone could give me some light on the syntax for the tclsh irule.

 

Thanks.

 

2 Replies

  • Something like below, haven't tested.

    when HTTP_REQUEST {
    set variable ""
    set variable [getfield [getfield [HTTP::uri] "/sj-" 2] "/" 1]
     here variable would have 01 or 02 .... 
     Check if the pools exists first with the variable using catch command, example marketing-lead-01 does exists or not
    if [ catch { pool "marketing-lead-$variable" } ] {
        log local0. "URI contain /sj-$variable/ - pool assigned is marketing-lead-$variable"
        pool marketing-lead-$variable
    } else {
    pool marketing-lead-default-pool
    }
    }
    
  • you can get the ID with scan command

    when HTTP_REQUEST {
         If the variable uri doesn't match the pattern or pool doesn't exist.
        if {![scan [HTTP::uri] {/sj-%[^/]} ID] || [ catch {pool "marketing-lead-${ID}"}]} {
            pool marketing-lead-default-pool
        } 
    }