Forum Discussion
Sven_89244
Nimbostratus
Aug 27, 2009Trying Cookie persistance
Hello to all,
I've trying to implement a cookie-based persistance.
The scenario is:
The client asks webserver with a /GET /es? and was balanced.
If they ask GET /hrs/... the server responds with a Header context: env=hrs
If this occurs the LTM should insert a Cookie "bigippersistance" with 4h(=14400 sec) timeout.
This rule is attached to a VS "test.hrpa.siemens.com" with a pool "test.hrpa.siemens.com"
My rule
when HTTP_REQUEST {
if { [HTTP::uri] contains "/es1/" } {
pool test.hrpa.siemens.com member 139.25.231.229
persist none
} elseif { [HTTP::uri] contains "/es2/" } {
pool test.hrpa.siemens.com member 139.25.231.230
persist none
} elseif { [HTTP::uri] contains "/es/" } {
pool test.hrpa.siemens.com
persist none
} elseif { [HTTP::uri] contains "/hrs/" } {
pool test.hrpa.siemens.com
persist uie [HTTP::cookie bigippersistance] 14400
} else {
drop
}
}
when HTTP_RESPONSE {
if {[HTTP::header context] contains "env=hrs"} {
set a_cookie [format "%08d" [expr { int(100000000 * rand()) }]]
HTTP::cookie insert name bigippersistance value [concat $a_cookie [LB::server] [IP::client_addr]]
persist add uie [HTTP::cookie bigippersistance] 14400
log local0. "Cookie persist - client IP: [IP::client_addr], Cookie: [HTTP::cookie names], Server IP: [IP::server_addr]"
}
}
The iRule-parser says it's o.k.
when invoked I get folling /var/log/ltm- msg
Aug 27 15:45:58 tmm tmm[1572]: 01220001:3: TCL error: URL_eshrs_Testif - bad option "test.hrpa.siemens.com": must be any, virtual, service, or pool while executing "persist add uie [HTTP::cookie bigippersistance] 14400"
What's the mistake?
Please advise - thanks
3 Replies
- hoolio
Cirrostratus
Hi Sven,
If you want to use cookie insert persistence for requests to a URI containing hrs, I'd suggest replacing the 'persist add uri [HTTP::cookie bigippersistance] 14400' line with 'persist cookie insert $cookie_name $timeout'.
What you're using will fail because the client won't have a persistence cookie on the first request. So [HTTP::cookie bigippersistance] will return a null length string and the persist command will fail with a runtime error.
Aaron - Sven_89244
Nimbostratus
Thanks Aaron,
so to avoid the mistake that the first persist causes an error, i've refined the rule to
...} elseif {
[HTTP::uri] contains "/hrs/"
} {
if {
[HTTP::cookie exist "bigippersistance"]
} {
pool test.hrpa.siemens.com
persist uie [HTTP::cookie bigippersistance] 14400
} else {
pool test.hrpa.siemens.com
persist none
}
} ...
but if I change according to your suggestion the line persist add uie [HTTP::cookie bigippersistance] 14400' line with 'persist cookie insert $cookie_name $timeout'
I get following
"Persistence mode (Cookie) called out in rule (URL_eshrs_Testif3) requires a corresponding persistence profile for virtual server (test.hrpa.siemens.com)."
So this means that i add a default persistance profile to the Server. This not desired. The cookie should only be set if the HTTP::response contains a header with "hrs"
What's the meaning of the message: TCL error: URL_eshrs_Testif - bad option "test.hrpa.siemens.com": must be any, virtual, service, or pool while executing "persist add uie [HTTP::cookie bigippersistance] 14400"
Sven - hoolio
Cirrostratus
Hi Sven,
I'm not sure I follow your exact logic for when to apply persistence. It looks like you want to only use persistence if the server sets an HTTP header in the response named context with a value that contains "env=hrs". The cookie will then be presented by the client on every request until it expires. I assume the client won't be including a "context" header, so you'll not be able to selectively apply persistence only when the client has just previously received a response with the context header.
So I think you'd get the same functionality by just specifying cookie insert peristence from the iRule on requests to URIs containing "/hrs/".
Rereading the TCL runtime error, I'm not sure exactly what it's indicating. I think the value of the persistence cookie should be a single string, but it seems that it might have spaces in it which aren't being handled by the persist command. If you do want to use this approach, can you log the cookie value before trying to use it in the HTTP_RESPONSE event to persist?
log local0. '\[HTTP::cookie bigippersistance\]: [HTTP::cookie bigippersistance]"
Aaron
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects