Forum Discussion

Koni_51721's avatar
Aug 02, 2013

How to get the session duration with iRule

Hello

 

We need to log the authenticated session-duration with an iRule. But with following rule, we can't get any information, the ACCESS::session variables are empty.

 

Has anybody an idea?

 

Thanks

 

 

when ACCESS_SESSION_CLOSED {

 

set sessionId [ACCESS::session data get "session.user.sessionid"]

 

set startSession [ACCESS::session data get "session.user.starttime"]

 

set endSession [clock seconds]

 

set status [ACCESS::session data get "session.policy.result"]

 

log 10.10.10.10 local6.info "\|SessionID: $sessionId \|StartSession: $startSession \|EndSession: $endSession \|AuthStatus: $status \|\n"

 

}

 

 

 

1 Reply

  • The ACCESS_SESSION_CLOSED event is only triggered when "user logging out explicitly, timeout or if terminated explicitly by admin" (https://devcentral.f5.com/wiki/iRules.ACCESS_SESSION_CLOSED.ashx). Otherwise it is extremely difficult to know for certain when a user session ends - when the user closes the browser, the machine blows up, the user locks the screen and leaves for lunch, etc. Your best bet, potentially, would be to catalog the time for each new request, overwriting the last time, so that when a user stops making requests (for whatever reason) you have a general idea when the user stopped working within the application. You could simply store that time in a custom session variable in every ACCESS_ACL_ALLOWED event.