Forum Discussion

dr_tamfr_dhp_19's avatar
dr_tamfr_dhp_19
Icon for Nimbostratus rankNimbostratus
Sep 01, 2015

iRule for setting pool based on URI path

Hello,

 

I know it's possible to set a pool based on the URI path. But what I need to do past that is a bit more complex, and I'm not sure where to begin.

 

I have two pools I'm testing with:

 

preprod.domain.com preprodtr.domain.com

 

I want to direct a request to the proper pool based on the /path

 

So if preprod.domain.com/tr is requested the request is routed to the pool preprodtr.domain.com

 

So this I think would be pretty easy if hardcoded. However, I cannot hardcode it since *tr.domain.com is dynamic. That is, I have many pools that could be *tr.domain.com not just the example preprodtr.domain.com

 

So what I need to be able to do is if the F5 sees the request *.domain.com/tr requested, it finds {host}tr.domain.com

 

Anyone have any ideas?

 

Thank you!

 

10 Replies

  • Try this, it will check to see if you have a pool created that matches the http hostname_pool and if not go to your default pool. If it does it will go to the corresponding pool.

    when HTTP_REQUEST {
        if { [getfield [HTTP::host] "." 1] ends_with "tr"}{
            if { [catch {pool [string tolower "[HTTP::host]_pool"]}] }{
                pool "default_pool"
            }
            else {
                pool [string tolower "[HTTP::host]_pool"]
            }
        }
    }
    

    Updated.

    • Brad_Parker_139's avatar
      Brad_Parker_139
      Icon for Nacreous rankNacreous
      probably throw a string to lower in there in case someone requests with caps, when HTTP_REQUEST { if { [catch {pool [string tolower "[HTTP::host]_pool"]}] }{ pool "default_pool" } else { pool [string tolower "[HTTP::host]_pool"] } }
  • Try this, it will check to see if you have a pool created that matches the http hostname_pool and if not go to your default pool. If it does it will go to the corresponding pool.

    when HTTP_REQUEST {
        if { [getfield [HTTP::host] "." 1] ends_with "tr"}{
            if { [catch {pool [string tolower "[HTTP::host]_pool"]}] }{
                pool "default_pool"
            }
            else {
                pool [string tolower "[HTTP::host]_pool"]
            }
        }
    }
    

    Updated.

    • Brad_Parker's avatar
      Brad_Parker
      Icon for Cirrus rankCirrus
      probably throw a string to lower in there in case someone requests with caps, when HTTP_REQUEST { if { [catch {pool [string tolower "[HTTP::host]_pool"]}] }{ pool "default_pool" } else { pool [string tolower "[HTTP::host]_pool"] } }
  • Hmmm, I'm not using default pools which I assume is why I got the error that it doesn't know what the default_pool is.

     

    Also however, I don't see any thing in that logic that is looking for the "tr" delineation.

     

    • Brad_Parker's avatar
      Brad_Parker
      Icon for Cirrus rankCirrus
      you will have to define what you default pool is or if you want to just reject traffic that doesn't match a pool you've created. I will update the rule above to account for tr.
  • I'm may have the misunderstood but this will to route to pool prepended with hostname if the uri starts with /tr

    when HTTP_REQUEST {
      if { [HTTP::uri] starts_with "/tr" } {
        scan [HTTP::host] {%[^.]} host_pool   
        pool ${host_pool}tr.domain.com
      }
    }
    
  • You have the getfield string and split round the wrong way 🙂 but the getfield option looks good;

    when HTTP_REQUEST {
      if { [HTTP::uri] starts_with "/tr" } {   
        pool [getfield [HTTP::host] "." 1 ]tr.example.com
      }
    }