Forum Discussion
HELP!!!!!!!!!!!, Got Crazy of Session persistence with irule and cookie
To answer your question first, no there is no such persistence that will do this out of the box - the idea with persistence is that you should be able to have different persistence entries for different pool members depending of which pool is selected. So in order to do this we must do some custom persistence to make it happen.
Now for the solution. At first I had some quite elaborate code to take care of this but once I started wrapping my head around the solution I realized that it was actually a lot easier than that - all we need to do is to add another cookie once pool2 has been selected and the presence of this cookie should then force the BIG-IP to henceforth send the traffic to pool2.
I also made use of variables to set the pool name, URI and so on, since I suspect that "pool2" isn't the actual name of the pool in your implementation, so this makes it easier for you to change the pool name according to your configuration. So this is what I've got:
when RULE_INIT {
This variable defines the name of the custom cookie sent to
the client to keep track of that this user should persist to
the secondary pool only.
set static::St_Cookie "mycookie"
This variable contains the name of the pool to which the client
should stick once it has been selected
*** IMPORTANT ***
This MUST be the full name, including partition - for example
"/Common/pool2" - otherwise the iRule will not work as intended
set static::Pool_Name "/Common/pool2"
This is the URI that signifies that the secondary pool should be
selected. Note that the HTTP::uri command does not include the
hostname
set static::Select_URI "/regist.asp?id=321&pid=123"
}
when HTTP_REQUEST {
if { [HTTP::cookie exists $static::St_Cookie] }{
The sticky cookie is here so the secondary pool should be used
pool $static::Pool_Name
Clean up the request before sending it to the server
HTTP::cookie remove $static::St_Cookie
}
elseif {[ string tolower [HTTP::uri]] starts_with $static::Select_URI }{
pool $static::Pool_Name
}
}
when HTTP_RESPONSE {
if { [LB::server pool] eq $static::Pool_Name }{
Insert the sticky cookie, it has a value of 1, which is not used
for anything since we're looking for the presence of the cookie
and not the value
HTTP::cookie insert name $static::St_Cookie value "1" path "/"
}
}Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
