Forum Discussion

Rodney_Newton_7's avatar
Rodney_Newton_7
Icon for Nimbostratus rankNimbostratus
Sep 21, 2006

Pool selection using uri variables

I have a unit in test where test sites are added frequently so I am constantly adding pools to the bigip and using and iRule for pool selection similar to the following.

 

 

when HTTP_REQUEST {

 

if {[HTTP::uri] contains "test1"}

 

{pool testbed-test1}

 

elseif {[HTTP::uri] contains "test2"}

 

{pool testbed-test2}

 

elseif {[HTTP::uri] contains "test50"}

 

{pool testbed-test50}

 

else {pool defaultpool}

 

}

 

 

The uri hitting the vip looks like this... http://hostname/xx-test1, http://hostname/xx-test50, etc...

 

 

It would be nice if I could just add the new pool and not have to edit my iRule each time. Is there a way that I can parse the info from the uri into a variable then use that variable as part of the pool name in the selection statement? Keep in mind that the varaible portion of the pool name will be after the "xx-" in the uri and could be 4 or 5 characters in length. Thanks for any input.

 

2 Replies

  • Hi,

    You can set a pool using a variable like so:

    
    when HTTP_REQUEST {
       set my_pool "http_pool"
       pool $my_pool
    }

    So it would just be a matter of extracting the portion of the URI that contains the pool name using string functions following the TCL string reference (Click here).

    One thing to determine first is what delineates the string containing the pool name from the rest of the URI. Would the URI always and only be /xx-testD or /xx-testDD where D is a digit? Or would it be the start of the URI, like /xx-testDD/some/path/to/object.html?

    Try posting again here if you have questions on using string to get the pool name from the URI.

    Edit: here's a post from citizen_elah showing an example for extracting the node address from the URI and directing the request to that node. You should be able to adapt that for getting the pool from the URI.

    Click here

    Aaron
  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    hoolio is right, but you do sort of need to be a bit careful when using dynamic data to build a pool name, though.

    Something like this would work, I think:
    when HTTP_REQUEST {
        extract the pool info from the URI
       set uristring [findstr [HTTP::uri] "xx-" "/"]
        check if the pool exists and has avail members
       if {[active_members "testbed-$uristring"] > 0}{
          pool testbed-$uristring
       } else {
          pool defaultpool
       }
    }

    peace

    /deb