Forum Discussion

djkromarek's avatar
djkromarek
Icon for Nimbostratus rankNimbostratus
Jan 28, 2015

iRule to set pool based on URI then persist based on clientIP

I have the following iRule that based on the URI, sends the clientIP to a specific pool. Once they are in that pool, no matter what host or URI they go to, I need them to persist to that pool. when HTTP_REQUEST { if { [HTTP::host] matches_regex "abc.com" }{ if { [string tolower [HTTP::uri]] starts_with "/test" } { pool "pool_thispool" log local0.alert [HTTP::host] } else {pool "pool_defaultpool"} } } If they are in the pool_thispool, how do I keep them there even if they go to cde.com or abc.com/test2?

 

5 Replies

  • Hi djschul,

     

    depending on your applied type of persistence you can lookup the persistence table before testing the conditions or in case of cookie (insert mode) persistence you can check the incoming request for a persistence cookie.

     

    If a persistence record is found or the client provides a persistence cookie the test for conditions would be skipped and persistence applies.

     

    What persistence method are you using?

     

    Thanks, Stephan

     

  • On the VIP, it is a cookie persistence profile. HTTP Cookie Insert, cookie name VIPCookie, expiration - Session Cookie is checked. I need to persist the client IP to the pool_thispool only if they hit the URI /test first. But once they click into /test, I need them to stay in that pool for 3 hours.

     

  • Hi djschul,

    in case there is a VIPCookie in the client request we probably can assume we have to handle a returning client:
    when HTTP_REQUEST { 
        if { [HTTP::cookie exists VIPCookie] } {
            pool pool_thispool
        } elseif { [string tolower [HTTP::host]] matches_regex "abc.com" } { 
            if { [string tolower [HTTP::uri]] starts_with "/test" } { 
                pool pool_thispool
                log local0.alert [HTTP::host] 
            } else {
                pool pool_defaultpool
            }
        }
    }
    

    Maybe using "ends_with" would be better than "matches_regex"?

    Thanks, Stephan
  • Hi djschul,

    maybe this iRules in combination with slightly modified persistence settings and default pool set to pool_thispool helps to solve the requirement.

    Please use "source address affinity" as fallback persistence profile for your virtual server (perhaps with a modified timeout of 10,800 seconds).
    when HTTP_REQUEST { 
        set persist_record [persist lookup source_addr "[IP::client_addr] any virtual"]
         log local0. "persist lookup: $persist_record"
        if { $persist_record equals "" } {
            if { [HTTP::host] matches_regex "abc.com" }{ 
                if { [string tolower [HTTP::uri]] starts_with "/test" } { 
                    pool pool_thispool
                     log local0.alert [HTTP::host] 
                } else {
                    pool pool_defaultpool
                    persist none
                }
            }
        }
    }
    

    Thanks, Stephan

  • I'm watching the logs and I can see the IP going to the correct pool when they hit /test, but then, they leave that pool when clicking /imhere or the page is just loading pictures from the page.