Forum Discussion

KevinA_246454's avatar
KevinA_246454
Icon for Cirrostratus rankCirrostratus
Oct 17, 2018

HTTP Session Limit with active clients report

HI Dev Central Community

I have irule configured to track sessions to a web server, the irule based on our testing is working thus far, but I need to add some modification to the rule. 1st I need to setup reporting on the rule for example if you enter /counter it needs to show how many sessions is currently on the server, I tried a few things but no luck and If there is clients in the waiting room I need to report on that that also... Here below is the rule

when RULE_INIT { set static::max_active_clients 1 log local0. "rule session limit reached"

}
when HTTP_REQUEST {
   test cookie presence
  if {[HTTP::cookie exists "ClientID"]} {
    set need_cookie 0
    set client_id [HTTP::cookie "ClientID"]
    if cookie not present & connection limit not reached, set up client_id
  if  { [HTTP::uri] eq "/counter"} { HTTP::respond 200 content "countsessions"}
 } else {
   if {not ([table keys -subtable httplimit] > $static::max_active_clients)} {
     set need_cookie 1
     set client_id [format "%08d" [expr { int(100000000 * rand()) }]]

      Only count this request if it's the first on the TCP connection
     if {[HTTP::request_num] == 1}{
       table set -subtable httplimit [IP::client_addr]:[TCP::client_port] "blocked"
       set countsessions [table keys -subtable $httplimit -count]
      set timer [after 60000 -periodic { table lookup -subtable httplimit [IP::client_addr]:[TCP::client_port] }]
     }  




   } else {

    HTTP::respond 200  content { 

    
    
    
    test irule
    
    

    
    
    Thank you for visisting this  webpage
    We are sorry to drop you in the maintenance page
     Please stay!
     If you stay we will try to redirect you to the realwebsite
    
    
    
    }
  }
 } 

}

when HTTP_RESPONSE { insert cookie if needed if {$need_cookie == 1} { HTTP::cookie insert name "ClientID" value $client_id path "/" } }

No RepliesBe the first to reply