Forum Discussion

tidenz_92110's avatar
tidenz_92110
Icon for Nimbostratus rankNimbostratus
May 13, 2010

select member based on cookie in request

Hi Guys,

 

 

Is it possible to select a specific pool member based on a cookie in the request?

 

 

so if my cookie had a value of "cookie1" then it should select pool member 1 etc.

 

 

The dev team wants to be able to select a specific pool member behind the F5.

 

 

I am hoping then the insert cookie option will take care of the subsequent requests to that pool member.

 

 

 

in pseudo code

 

 

On a http request we will check for a cookie "mycookie" and "mycookie2" if only "mycookie" exsists and the value matches a "entry" in a data class and it is coming from a trusted ip address then we will select a specific pool member.

 

 

If "mycookie" and "mycookie2" exists then we should do nothing as mycookie2 was inserted by the F5 in the previous response.

 

 

In the http response we want to insert an encrypted cookie using the cookie persist and encrypt options in the profiles.

 

 

is my pseudo code workable on a 9.4.7 LTM?

 

 

Thanks in advance.

 

4 Replies

  • Hi Tidenz,

     

     

    It might be simpler to allow admins to select the pool member using a query string parameter. Here is an example you could start with:

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/Select_pool_member_based_on_HTTP_query_string_parameter.html

     

     

    If that doesn't work for your scenario, reply back here and we can try to come up with an example for your original description.

     

     

    Aaron
  • I think this is a start to what you are wanting to do. I would suggest looking at the HTTP::cookie Wiki entry to see what else you can do with it and then maybe searching DevCentral for more uses of HTTP::cookie.

    Perhaps some of the others know of a better / different way:

    This iRule should compare looking for two different values of the cookie. If neither match then the traffic should proceed to the Pool assigned to the Virtual Server.

    
     when HTTP_REQUEST {
    if { [HTTP::cookie value "some.cookie.value"] } {
    node 192.168.1.1 80
    }
    elseif { [HTTP::cookie value "some.different.cookie.value"] } {
    node 192.168.1.2 80
    }
    }
    

    HTTP::cookie Wiki Entry:

    http://devcentral.f5.com/wiki/default.aspx/iRules/http__cookie.html

    node Wiki Entry:

    http://devcentral.f5.com/Wiki/default.aspx/iRules/node.html
  • Thanks for the responses,

     

     

    The "node" option looks interesting but reading into it stats on the node are ignored. i think pool pool_member is a better option for selecting a pool member

     

     

    As for selection based on the query string that looks like a good option and far easier to manage. The only issue i can see is what happens with pool members that are disabled? are they candidates for LB selection?

     

     

    I have asked if we can use this.

     

     

    On another note they want us to insert the currently selected member in a new cookie on the response not to be used for persistance but rather monitoring stats.

     

     

    Can the HTTP::cookie value also look at set-cookie values?

     

     

     

     

     

     

     

  • As for selection based on the query string that looks like a good option and far easier to manage. The only issue i can see is what happens with pool members that are disabled? are they candidates for LB selection?

     

     

    In the current version of the iRule only members not marked down are considered in the matching. If you are on 10.x, you can chance active_members to members and then all pool members, regardless of state, are considered.

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/members

     

     

    HTTP::cookie value in HTTP_REQUEST will return information on request cookie values. It will return cookie values in the response in HTTP_RESPONSE.

     

     

    Aaron