Forum Discussion
Logging sessionid in irule to select pool based on host header
I've been trying to add sessionid to my logs for my irule to select pools based on host-header. It seems easy enough, but I've still managed to fail somehow 😞
The basic iRule isn't very complicated:
when HTTP_REQUEST {
set req_start [clock clicks -milliseconds]
set clientip [IP::client_addr]
set method [HTTP::method]
set uri [HTTP::uri]
set referer [HTTP::header Referer]
set uid [string range [AES::key 256] 8 end]
set ua [HTTP::header User-Agent]
switch [string tolower [HTTP::host]] {
monitoring.domain.com {
set doSSL 1
pool monitoring
}
tickets.domain.com {
set doSSL 2
pool ticketsystem
}
default { reject }
}
log local0. "URI_LOG\t[ACCESS::session data get "session.user.sessionid"]\t$uid\t$clientip\t[clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S"]\t[expr {[clock clicks -milliseconds] - $req_start}]\t[LB::server addr]\t$referer\t[URI::query $uri]"
when SERVER_CONNECTED {
if {$doSSL == 1} {
SSL::profile MonitoringSSLProfile
} elseif {$doSSL == 2} {
SSL::profile TicketSystemSSLProfile
}
}
Of course, I do get a few log entries, but not the sessionid. I believe it is because I can only get that in HTTP_RESPONSE? But if I try to add HTTP_RESPONSE in this iRule, it turns out that my sites aren't accessible any longer.
I feel that there is a simple answer out there, I just haven't been able to think about it or find it yet. Anyone have a good tip here?
Thank you.
- youssef1
Cumulonimbus
Hi,
You have to use event "ACCESS_ACL_ALLOWED", is triggered when a resource request passes the access control criteria and is allowed to go through the ACCESS filter.
when ACCESS_ACL_ALLOWED { set req_start [clock clicks -milliseconds] set clientip [IP::client_addr] set method [HTTP::method] set uri [HTTP::uri] set referer [HTTP::header Referer] set uid [string range [AES::key 256] 8 end] set ua [HTTP::header User-Agent] switch [string tolower [HTTP::host]] { "monitoring.domain.com" { set doSSL 1 pool monitoring } "tickets.domain.com" { set doSSL 2 pool ticketsystem } default { reject } } log local0. "URI_LOG\t[ACCESS::session data get "session.user.sessionid"]\t$uid\t$clientip\t[clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S"]\t[expr {[clock clicks -milliseconds] - $req_start}]\t[LB::server addr]\t$referer\t[URI::query $uri]" when SERVER_CONNECTED { if {$doSSL == 1} { SSL::profile MonitoringSSLProfile } elseif {$doSSL == 2} { SSL::profile TicketSystemSSLProfile } }
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