Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Clear all filters
Answers

Session ID persistence based on SessionID parameter in JSON

Hello ,

Iam trying to write I-rule based on following requirement

  1. Client requests to initiate a session  F5 forwards the call to available Node in the pool.

  2. Node sends response to F5 containing sessionid  F5 extracts sessionid and creates a new persistence.

  3. F5 then forwards the HTTP response to client  Client stores the sessionid .

  4. 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

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

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

0
Comments on this Answer
Comment made 1 month ago by sidkhan 1

Hi Kai ,

Thanks for your reply , The Session ID will be in JSON response from the application/node which F5 forwards based on the initial request from the client , Below is the JSON code

Response Body (JSON) to Parse to create sticky session

{ "MyModuleInfo": { "CouponsAvailable": false, "ShoppingListsAvailable": false, "ShoppingListNames": null }, "Session": { "DatabaseUrl": "", "SessionId": "e5f992bb-3aad-4850-969c-8455a98ab123",

The Client will get this session id once he enters the details and click submit on the Webpage .

The client will use this session id in the URL to make subsequent calls and the F5 should persist to the same node .

Eg: Request URL to Parse => /SelfscanEnginePlugin/AddItem?sessionId=e5f992bb-3aad-4850-969c-8455a98ab123&barcode=043000032275&quantity=6&linkedBarcode=false&deviceId=

Thanks Uzair

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

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 persist incomming requests based on the value of the Query-String parameter "sessionid" .

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 STREAM inspect every outgoing JSON response for a string in the regex format of "SessionId": "([a-z0-9-]+)",. If a match is found, the iRule would extract the ([a-z0-9-]+) portion and create/update the persistence database with the currently selected pool member IP.

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 (tmsh)# show ltm persistence persist-records. Once you have verified the functionality of this iRule, you may want to remove the individual log lines from the script...

Cheers, Kai

0
Comments on this Answer
Comment made 1 month ago by Kai Wilke 6860

Additional Note: The persist database entry will last 900 seconds in the provided iRule. If you need to support long lasting sessions, then simply increase the value "900" to a value of your choice.

0