Options

aflex for individual server cookie persist

Posted by jmaddox

Do we have an aflex where individual load balanced servers could each have a unique cookie and persistence is achieved by observing that cookie, as opposed to inserting one at the load balancer level?

Comments

  • Options
    edited July 2022
    Posted by ddesmidt

    We can indeed do that with aFleX
    Here is the aFleX script below.

    Note about assumptions done in the script:
    . servers are listening on 80
    . servers' cookie name is "cookie1"
    . servers' cookie value is "server1" for server1, "server2" for server2, etc
    Update the script if that's not the case.


    Code:

    when HTTP_REQUEST { # check if there is a server cookie "cookie1" if { [HTTP::cookie exists "cookie1"]} { set cookie_server [HTTP::cookie "cookie1"] #log "cookie_server = $cookie_server" # define variables server_ip based on the value of the cookie switch $cookie_server { "server1" { set server_ip "192.168.12.101" } "server2" { set server_ip "192.168.12.102" } "server3" { set server_ip "192.168.12.103" } } #check if that server is still UP and if so send the request to that server if {[string compare [LB::status node $server_ip port 80 tcp] up] == 0} { node $server_ip 80 #log "selection via cookie node = $server_ip 80" } # in all other cases: No cookie or cookie for a server DOWN # => Do nothing in aFleX # => Do the VIP configuration # => Send the request to a server UP in the VIP Service Group } }
  • Options
    edited July 2022
    Posted by ddesmidt

    As you know aFleX is pretty flexible and you may have multiple ways to achieve the same thing

    Here is another option available using aFleX persistence uie (universal inspection engine) table.
    Unlike the first solution proposed, this option can work in case servers' cookies are not always fixed.

    Note about assumptions done in the script:
    . servers' cookie name is "JSESSIONID"
    Update the script if that's not the case.

    Code:

    when HTTP_REQUEST { # Check if JSESSIONID exists if { [HTTP::cookie exists "JSESSIONID"] } { # JSESSIONID found in the request # we capture the first 32 characters set jsess_id [string range [HTTP::cookie "JSESSIONID"] 0 31] persist uie $jsess_id # Check if JSESSIONID exists in the uie persist table set p [persist lookup uie $jsess_id all] if { $p ne "" } { # JSESSIONID found in the persist table log "JSESSIONID = \"$jsess_id\" found in persistency-table ([lindex $p 0] [lindex $p 1])" } else { # unknown JSESSIONID # (could be a fake JSESSIONID inserted by a bad end-user # or a user inactive for 30 minutes) log "JSESSIONID = \"$jsess_id\" not found in persistency-table" } } else { # JSESSIONID not found in the request # (could be a new client) log "No JSESSIONID cookie" } } when HTTP_RESPONSE { if { [HTTP::cookie exists "JSESSIONID"] } { set jsess_cookie [HTTP::cookie "JSESSIONID"] persist add uie $jsess_cookie 1800 log "Add persist entry for JSESSIONID \"$jsess_cookie\"" } }
Sign In or Register to comment.