Forum Discussion
iRule for cookie based load balancing
I am trying to create an iRule to load balance on cookie data. cookie Name- gcbSessionServer
I am using below code but it is giving error
May 31 11:10:20 ttncltmxza-p err tmm[17866]: 01220001:3: TCL error: /Common/cct-cobrowse-ct-test_pool_switch_rule - expected boolean value but got "" while executing "if { [HTTP::cookie exist "gcbSessionServer"] } { switch -glob ([HTTP::cookie value "gcbSessionServer"]) { ".Co-browse_TENCBSD0_Node1" { pool cct..."
when HTTP_REQUEST { if { [HTTP::cookie exist "gcbSessionServer"] } { switch -glob ([HTTP::cookie value "gcbSessionServer"]) { ".Co-browse_TENCBSD0_Node1" { pool cct-cobrowse-ct-node-1_pool } ".Co-browse_TENCBSD0_Node2" { pool cct-cobrowse-ct-node-2_pool } ".Co-browse_TENCBSD0_Node3" { pool cct-cobrowse-ct-node-3_pool } } } else { pool /Common/cct-cobrowse-ct.app/cct-cobrowse-ct_pool log local0. " Selected pool [LB::select] " } }
I am using below iRule and it works. I have single servers in pool and if the server is down LTM was throwing error.
when HTTP_REQUEST {
if { ([HTTP::cookie exists gcbSessionServer]) } {
if { ([HTTP::cookie value "gcbSessionServer"] contains ".Co-browse_TENCBSD0_Node1") and ([active_members cct-cobrowse-ct-node-1_pool] > 0)} {
pool cct-cobrowse-ct-node-1_pool
log local0. " COOKIE->[HTTP::cookie value "gcbSessionServer"] Selected pool [LB::select] " }
elseif { ([HTTP::cookie value "gcbSessionServer"] contains ".Co-browse_TENCBSD1_Node2") and ([active_members cct-cobrowse-ct-node-2_pool] > 0)} {
pool cct-cobrowse-ct-node-2_pool
log local0. " COOKIE->[HTTP::cookie value "gcbSessionServer"] Selected pool [LB::select] " }
elseif { ([HTTP::cookie value "gcbSessionServer"] contains ".Co-browse_TENCBSD2_Node3") and ([active_members cct-cobrowse-ct-node-3_pool] > 0)} {
pool cct-cobrowse-ct-node-3_pool
log local0. " COOKIE->[HTTP::cookie value "gcbSessionServer"] Selected pool [LB::select] " }
else {
LB::mode rr
pool /Common/cct-cobrowse-ct.app/cct-cobrowse-ct_pool
log local0. " COOKIE FOUND Selected pool [LB::select] "
} }
else {
LB::mode rr
pool /Common/cct-cobrowse-ct.app/cct-cobrowse-ct_pool
log local0. " NO COOKIE Selected pool [LB::select] "
} }
- Ashish1982k_242Altostratus
Better view of iRule:
when HTTP_REQUEST {
if { [HTTP::cookie exists gcbSessionServer] } {
switch [HTTP::cookie value "gcbSessionServer"] {
".Co-browse_TENCBSD0_Node1" { pool cct-cobrowse-ct-node-1_pool } ".Co-browse_TENCBSD0_Node2" { pool cct-cobrowse-ct-node-2_pool } ".Co-browse_TENCBSD0_Node3" { pool cct-cobrowse-ct-node-3_pool }
} }
else {
pool /Common/cct-cobrowse-ct.app/cct-cobrowse-ct_pool log local0. " Selected pool [LB::select] "
}
}
- youssef1Cumulonimbus
Hi,
I don't think you need to check if the cookie exists first, as HTTP::cookie value will return a null length string even if the cookie name doesn't exist.
Your problem is that "[HTTP::cookie exist "gcbSessionServer"]" have to return 0 or 1 but it seems that in your irule is empty.
so try this, we can try another thing if it's not working
when HTTP_REQUEST { switch -glob ([HTTP::cookie value "gcbSessionServer"]) { ".Co-browse_TENCBSD0_Node1" { pool cct-cobrowse-ct-node-1_pool } ".Co-browse_TENCBSD0_Node2" { pool cct-cobrowse-ct-node-2_pool } ".Co-browse_TENCBSD0_Node3" { pool cct-cobrowse-ct-node-3_pool } default { pool /Common/cct-cobrowse-ct.app/cct-cobrowse-ct_pool log local0. " Selected pool [LB::select] " } } }
keep me in touch.
Regards
- Ashish1982k_242Altostratus
I am using below iRule and it works. I have single servers in pool and if the server is down LTM was throwing error.
when HTTP_REQUEST {
if { ([HTTP::cookie exists gcbSessionServer]) } {
if { ([HTTP::cookie value "gcbSessionServer"] contains ".Co-browse_TENCBSD0_Node1") and ([active_members cct-cobrowse-ct-node-1_pool] > 0)} {
pool cct-cobrowse-ct-node-1_pool
log local0. " COOKIE->[HTTP::cookie value "gcbSessionServer"] Selected pool [LB::select] " }
elseif { ([HTTP::cookie value "gcbSessionServer"] contains ".Co-browse_TENCBSD1_Node2") and ([active_members cct-cobrowse-ct-node-2_pool] > 0)} {
pool cct-cobrowse-ct-node-2_pool
log local0. " COOKIE->[HTTP::cookie value "gcbSessionServer"] Selected pool [LB::select] " }
elseif { ([HTTP::cookie value "gcbSessionServer"] contains ".Co-browse_TENCBSD2_Node3") and ([active_members cct-cobrowse-ct-node-3_pool] > 0)} {
pool cct-cobrowse-ct-node-3_pool
log local0. " COOKIE->[HTTP::cookie value "gcbSessionServer"] Selected pool [LB::select] " }
else {
LB::mode rr
pool /Common/cct-cobrowse-ct.app/cct-cobrowse-ct_pool
log local0. " COOKIE FOUND Selected pool [LB::select] "
} }
else {
LB::mode rr
pool /Common/cct-cobrowse-ct.app/cct-cobrowse-ct_pool
log local0. " NO COOKIE Selected pool [LB::select] "
} }
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