Forum Discussion
andrew_deackes_
Nimbostratus
Jul 13, 2009How log only specific source IP's?
Hi,
I did a little research and found the following i-Rule which seems to be exactly what I want for logging response times.
http://devcentral.f5.com/wiki/default.aspx/iRules/LogTcpAndHttpRequestResponseInfo.html
However, I'd like to be able to only log specific source IP's. I tried adding a data list of ips and using a line to match that list. So instead of:
when CLIENT_ACCEPTED {
Get time for start of TCP connection in milleseconds
set tcp_start_time [clock clicks -milliseconds]
the i-Rule starts:
when CLIENT_ACCEPTED {
if { [matchclass [IP::remote_addr] equals $::REQ_IP] }{
Get time for start of TCP connection in milleseconds
set tcp_start_time [clock clicks -milliseconds]
but I get errors when I try to install that. Can someone please advise how I change this i-Rule to only log for traffic from a specific IP?
Thanks
Andy
- hoolio
Cirrostratus
Hi Andy,when CLIENT_ACCEPTED { Check the REQ_IP datagroup to see whether this is a client IP address we want to log for if { [matchclass [IP::remote_addr] equals $::REQ_IP] }{ set log_connection 1 Get time for start of TCP connection in milleseconds set tcp_start_time [clock clicks -milliseconds] Log the start of a new TCP connection log "New TCP connection from [IP::client_addr]:[TCP::client_port] to [IP::local_addr]:[TCP::local_port]" } else { set log_connection 0 } } when HTTP_REQUEST { If we're not logging for this client IP, exit this event in this iRule if {$log_connection != 1}{ return } Get time for start of HTTP request set http_request_time [clock clicks -milliseconds] Log the start of a new HTTP request set LogString "Client [IP::client_addr]:[TCP::client_port] -> [HTTP::host][HTTP::uri]" log local0. "$LogString (request)" } when HTTP_RESPONSE { If we're not logging for this client IP, exit this event in this iRule if {$log_connection != 1}{ return } Received the response headers from the server. Log the pool name, IP and port, status and time delta log local0. "$LogString (response) - pool info: [LB::server] - status: [HTTP::status] (request/response delta: [expr [clock clicks -milliseconds] - $http_request_time]ms)" } when CLIENT_CLOSED { If we're not logging for this client IP, exit this event in this iRule if {$log_connection != 1}{ return } Log the end time of the TCP connection log "Closed TCP connection from [IP::client_addr]:[TCP::client_port] to [IP::local_addr]:[TCP::local_port] (open for: [expr [clock clicks -milliseconds] - $tcp_start_time]ms)" }
- andrew_deackes_
Nimbostratus
Hi 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