Forum Discussion
MarcoP
Jul 20, 2022Nimbostratus
iRule with JSESSIONID including the server id with jvmRoute
Dears, unfortunately I did not find a fitting post to my problem: We have two or more servers they creating a JSESSIONID where the id of the server is added on the end like so: 7B0DE3926CF23C2...
xuwen
Jul 20, 2022Cumulonimbus
PLAN B:
Firstly, create 2 pool:
pool_web member is 10.10.10.1:80 10.10.10.2:80
pool_default is standby(its member is 20.20.20.1:80 20.20.20.2:80) when pool_web all members is down
Dynamically add elements to the array according to pool member select
# create pool_web member is 10.10.10.1:80 10.10.10.2:80
# create pool_default is standby(its member is 20.20.20.1:80 20.20.20.2:80) when pool_web all members is down
when RULE_INIT priority 500 {
array set static::pool_array {}
}
when HTTP_RESPONSE priority 500 {
set node_ip [IP::server_addr]
set node_port [TCP::server_port]
log local0. "node_ip is $node_ip, port is $node_port"
if { [HTTP::cookie exists "JSESSIONID"] } {
# serverID0,serverID1
set node_x [findstr [HTTP::cookie "JSESSIONID"] "serverID" 8 1]
log local0. "node_x is $node_x"
# dynamic add element in array ,key is ID, value is pool member
set static::pool_array($node_x) "$node_ip:$node_port"
log local0. "response event pool array is [array get static::pool_array]"
}
}
when HTTP_REQUEST priority 500 {
if { [HTTP::cookie exists "JSESSIONID"] } {
set server_x [findstr [HTTP::cookie "JSESSIONID"] "serverID" 8 1]
log local0. "server_x is $server_x"
if { [active_members pool_web] == 0 } {
log local0. "exists cookie, select slave pool pool_default"
pool pool_default
} else {
# 0 10.10.10.1:80
# 1 10.10.10.2:80
if { [array get static::pool_array $server_x] != "" } {
set mem_ip [getfield [lindex [array get static::pool_array $server_x] 1] ":" 1]
set mem_port [getfield [lindex [array get static::pool_array $server_x] 1] ":" 2]
if { [LB::status pool pool_web member $mem_ip $mem_port] eq "up" } {
pool pool_web member $mem_ip $mem_port
} else {
pool pool_web
}
} else {
reject
log local0. "client send fake invalid cookie JSESSIONID!"
}
}
} else {
if { [active_members pool_web] == 0 } {
pool pool_default
log local0. "no cookie, select slave pool pool_default"
} else {
pool pool_web
}
}
log local0. "request event pool array is [array get static::pool_array]"
}
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