Forum Discussion
jkstraw_44238
Nimbostratus
Apr 20, 2007Tracking requests and responses
Hi,
I am working with an iRule provided by System Engineer at F5. The iRule was designed to give us the same information our custom apache log gives us (we are moving from Apace to F5).
Here is the Custom Apache Log:
CustomLog /opt/apache/logs/ssl_request_log "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %T %{JSESSIONID}C %{SSL_PROTOCOL}x %{SSL_CIPHER}x %D"
and here is the iRule I was provided:
when HTTP_REQUEST {
set http_request_time [clock clicks -milliseconds]
log local0. "Client IP: [IP::remote_addr], requesting: [HTTP::method]/[HTTP::host][HTTP::uri], browser: [HTTP::header User-Agent], Referer: [HTTP::header exists Referer], HTTP version [HTTP::version], JSESSION Cookie: [HTTP::cookie exists JSESSIONID], SSL: [SSL::cipher name]/[SSL::cipher version]/[SSL::cipher bits]"
}
when HTTP_RESPONSE {
set http_response_time [ clock clicks -milliseconds ]
log local0. "HTTP status: [HTTP::status], Response Size: [HTTP::payload length], Duration: [expr $http_response_time - $http_request_time] "
}
The iRule seems to provide all the information - but it logs it on two separate lines with no unique identifier in each entry to correlate the data.
Does anyone know of a way to insert a unique value that would tie together the http_request and http_response lines?
Thanks
- JRahm
Admin
use HTTP::request_num: - jkstraw_44238
Nimbostratus
Thank you for the tip - but unfortunately these are not unique numbers. I tailed the output after updating the iRule and found that the http::request_num was showing many duplicates for different unique requests. - JRahm
Admin
Why not just set the variables in the request and print everything in the response?when HTTP_REQUEST { set http_request_time [clock clicks -milliseconds] set client_ip [IP::remote_addr] set client_request "[HTTP::method]/[HTTP::host][HTTP::uri]" set client_browser [HTTP::header User-Agent] set client_referer [HTTP::header exists Referer] set http_version [HTTP::version] set jsess_cookie [HTTP::cookie exists JSESSIONID] } when HTTP_RESPONSE { set http_response_time [ clock clicks -milliseconds ] log local0. " Client IP: $client_ip, \ Requesting: $client_request, \ Browser: $client_browser, \ Referer: $client_referer, \ HTTP version $http_version, \ JSESSION Cookie: $jsess_cookie, \ HTTP status: [HTTP::status], \ Response Size: [HTTP::payload length], \ Duration: [expr $http_response_time - $http_request_time]" }
- That's the suggestion I would have given, but with one modification. I'd suggest using a single string instead of multiple ones. Less overhead is always better...
when HTTP_REQUEST { set http_request_time [clock clicks -milliseconds] set request_log_line "Client IP: [IP::remote_addr], requesting: [HTTP::method]/[HTTP::host][HTTP::uri], browser: [HTTP::header User-Agent], Referer: [HTTP::header exists Referer], HTTP version [HTTP::version], JSESSION Cookie: [HTTP::cookie exists JSESSIONID], SSL: [SSL::cipher name]/[SSL::cipher version]/[SSL::cipher bits]" } when HTTP_RESPONSE { set http_response_time [ clock clicks -milliseconds ] log local0. "$request_log_line, HTTP status: [HTTP::status], Response Size: [HTTP::payload length], Duration: [expr $http_response_time - $http_request_time] " }
- JRahm
Admin
what's efficiency, anyway... :-) - jkstraw_44238
Nimbostratus
Thank you both! - jkstraw_44238
Nimbostratus
Hello, - Looks like you didn't escape the terminating quote on the "HTTP::cookie JSESSIONID" line...
when HTTP_REQUEST { set http_request_time [clock clicks -milliseconds] set request_log_line "\ [HTTP::request_num],\ [IP::remote_addr],\ [HTTP::method],\ [HTTP::version],\ [HTTP::host],\ \"[HTTP::uri]\",\ \"[HTTP::header Referer]\", \"[HTTP::header User-Agent]\",\ \"[HTTP::cookie JSESSIONID]\",\ [SSL::cipher name],\ [SSL::cipher version],\ [SSL::cipher bits]" }
- hoolio
Cirrostratus
[HTTP::header exists HEADER_NAME] will return 1 if the header HEADER_NAME has a value set and 0 if the header doesn't have a value. To get the actual value, you can use [HTTP::header value HEADER_NAME]. If the header isn't set, I think the command will return a null string. So you could just use 'value' instead of 'exists'. - jkstraw_44238
Nimbostratus
Thanks Aaron,
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects