Forum Discussion
Waiting room iRule
Hi Guys,
I am working on the below iRule. The logic is to send the user to a waiting room once we have enough sessions already active on a website. However after applying the iRule I am getting the server unreachable error. Please check the logic below and advise how can I make it work. The datagroup is created separately with the values as mentioned in the iRule;
when HTTP_REQUEST priority 1 {
Lookup and set value for maxActiveClients using the max_active_clients value in the datagroup_customer data group.
set static::maxActiveClients "[class search -all -value datagroup_customer starts_with "max_active_clients"]"
Hardcoded subtable name used to make sure the sub table is consistent across any VIPS the iRule is applied to
set subtableName "sessionLimit"
Lookup and set value for sessionCookieName using the session_cookie_prefix value in the datagroup_customer data group.
set sessionCookieName "[class search -all -value datagroup_customer starts_with "session_cookie_prefix"]"
Lookup and set value for holdingPage using the holding_page_url value in the datagroup_customer data group.
set holdingPage "[class search -all -value datagroup_customer starts_with "holding_page_url"]"
Set need_cookie to zero. If the user requries a cookie, this value gets changed to 1
set need_cookie 0 ; test cookie presence if {[HTTP::cookie exists $sessionCookieName]} { set client_id [HTTP::cookie $sessionCookieName]
Check the session still exists
set sessiondata [table lookup -subtable $subtableName $client_id] if { $sessiondata != "" } {
Valid session found in sub table. The lookup resets the cookie timer so continue on. log local0. "Valid session $client_id - continuing"
return } }
If there is no cookie present, there is not a valid session in the sub table so need to issue cookie. Check capacity before issuing a cookie log local0. "No session. Checking for free slot (Max $static::maxActiveClients)"
set sessionCount [table keys -subtable $subtableName -count]
log local0. "No session. Checking for free slot (Current $sessionCount)"
if {$sessionCount < $static::maxActiveClients} {
There is enough capacity. Allocate the session and set the session cookie on the client
set need_cookie 1 set client_id [format "%08d" [expr { int(1000000000 * rand()) }]] set sessionValue [IP::client_addr]
Add session information to the sub table
table add -subtable $subtableName $client_id $sessionValue $static::sessionTimeout
log local0. "New Session ($client_id) added value $sessionValue Timeout $static::sessionTimeout"
} else {
No available capacity. Redirect client to holding page.
HTTP::redirect $holdingPage } } when HTTP_RESPONSE priority 1 { ; insert cookie if needed if {$need_cookie == 1} { HTTP::cookie insert name $sessionCookieName value $client_id path "/" } }
6 Replies
- Absarkhan_15403
Nimbostratus
For Clarity, here is the iRule without comments;
when HTTP_REQUEST priority 1 {
set static::maxActiveClients "[class search -all -value datagroup_customer starts_with "max_active_clients"]"
set subtableName "sessionLimit"
set sessionCookieName "[class search -all -value datagroup_customer starts_with "session_cookie_prefix"]"
set holdingPage "[class search -all -value datagroup_customer starts_with "holding_page_url"]"
set need_cookie 0
if {[HTTP::cookie exists $sessionCookieName]} { set client_id [HTTP::cookie $sessionCookieName]
set sessiondata [table lookup -subtable $subtableName $client_id] if { $sessiondata != "" } {
return } }
set sessionCount [table keys -subtable $subtableName -count]
if {$sessionCount < $static::maxActiveClients} {
set need_cookie 1 set client_id [format "%08d" [expr { int(1000000000 * rand()) }]] set sessionValue [IP::client_addr]
table add -subtable $subtableName $client_id $sessionValue $static::sessionTimeout
} else {
HTTP::redirect $holdingPage } } when HTTP_RESPONSE priority 1 {
if {$need_cookie == 1} { HTTP::cookie insert name $sessionCookieName value $client_id path "/" } } - nitass
Employee
However after applying the iRule I am getting the server unreachable error.
is there any error in /var/log/ltm?
- Absarkhan_15403
Nimbostratus
Good point "nitass"
The logs are given below;
TCL error: - can't read "static::sessionTimeout": no such variable while executing "table add -subtable $subtableName $client_id $sessionValue $static::sessionTimeout"
- nitass
Employee
so, did you define static::sessionTimeout variable? - Absarkhan_15403
Nimbostratus
Yes I did and it is WORKING - Thank you "Nitass" for pointing out. However I will need to change the maximum sessions to maximum connections to the website, do you know which variable to use?
- nitass
Employee
However I will need to change the maximum sessions to maximum connections to the website, do you know which variable to use?
i understand it limits number of session in static::sessionTimeout window. the maximum number of session is value of max_active_clients key in datagroup_customer data group.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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