Forum Discussion
Session ID persistence based on SessionID parameter in JSON
Hello ,
Iam trying to write I-rule based on following requirement
-
Client requests to initiate a session F5 forwards the call to available Node in the pool.
-
Node sends response to F5 containing sessionid F5 extracts sessionid and creates a new persistence.
-
F5 then forwards the HTTP response to client Client stores the sessionid .
-
Client uses the sessionid to create a new request using sessionid in the URL F5 will parse the URL to retrieve the sessionid and use the existing persistence data to redirect the request to the right Node.
The F5 script should be clever enough to retrieve sessionid in a case-insensitive way and persist. F5 can distinguish first call from the subsequent calls by parsing the URL as the first call will not contain any sessionid text.
Can some one please help iam completely new to F5 .
Thanks Uzair
Hi sidkhan,
its basically impossible for us, to help you without knowing how the SessionID is initially send by your backend application and how the SessionID is send by your clients on subsequent requests.
You would need to provide a detailed traffic flow including the request/response headers/bodies. The SessionID values could be embedded anywhere in the ongoing conversation...
Cheers, Kai
Hi sidkhan,
a very generic (aka. not very much optimized) iRule based on the provided application logic may look like that...
when HTTP_REQUEST { STREAM::disable if { [set sessionid [URI::query [HTTP::uri] "sessionid"]] ne "" } then { log local0.debug "Found incomming Session ID: [URI::query [HTTP::uri] "sessionid"]" persist uie $sessionid } } when HTTP_RESPONSE { if { [HTTP::header value "Content-Type"] equals "application/json" } then { STREAM::expression {@"SessionId": "([a-z0-9-]+)",@} STREAM::enable } } when STREAM_MATCHED { if { [set sessionid [getfield [STREAM::match] {"} 4]] ne "" } then { log local0.debug "Extracted outgoing Session ID: $sessionid" eval "persist add uie \$sessionid 900" } }
The iRule will
incomming requests based on the value of the Query-String parameter "sessionid" .persist
If the persist database does not hold an entry for that value, or if the client does not send any "sessionid" parameter, the request will be balanced based on your pool settings.
The iRule will furthermore
inspect every outgoing JSON response for a string in the regex format ofSTREAM
. If a match is found, the iRule would extract the"SessionId": "([a-z0-9-]+)",
portion and create/update the persistence database with the currently selected pool member IP.([a-z0-9-]+)
Note: You MUST apply a STREAM and ONECONNECT profile to your Virtual Server in order to make this iRule work. You may use the defaults profiles without any further configuration.
Note: You may monitor the functionality with LTMs log files and using the TMSH command
. Once you have verified the functionality of this iRule, you may want to remove the individual log lines from the script...(tmsh) show ltm persistence persist-records
Cheers, Kai
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