Forum Discussion
Tracy_Butler_90
Nimbostratus
Jul 06, 2006writing an irule to log all traffic
Need assistance with writing an irule to log all traffic flow. Support suggested that this should be done versus making changes to the syslog-ng file. I've tried making changes to syslog-ng file with no luck. Please let me know if this is worth pursuing or should I go back to the syslog-ng file.
I'm looking to log source and destination IP addresses along with the corresponding ports.
Thanks
50 Replies
- nitass
Employee
HTTP::cookie is not valid in CLIENT_ACCEPTED.
HTTP::cookie wiki
http://devcentral.f5.com/wiki/iRules.HTTP__cookie.ashx[root@iris:Active] config b virtual bar list virtual bar { snat automap pool foo destination 172.28.17.33:http ip protocol tcp rules myrule profiles { http {} tcp {} } } [root@iris:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { set flag 0 if {[HTTP::cookie exists "testcookie"]} { set flag 1 set http_request_time [clock clicks -milliseconds] set LogString "Client [IP::client_addr]:[TCP::client_port] -> [HTTP::host][HTTP::uri]" } } when HTTP_RESPONSE { if {$flag} { log local0. "$LogString (response) - pool info: [LB::server] - status: [HTTP::status] (request/response delta: [expr [clock clicks -milliseconds] - $http_request_time]ms)" } } } GET / is not shown in log since testcookie has not been presented at the first request (it is set by pool member in the first response). log is written in /var/log/ltm file. if you want to write to another file, you can customize syslog-ng config. [root@iris:Active] config tail -f /var/log/ltm Oct 19 17:59:17 local/tmm info tmm[4601]: Rule myrule : Client 192.168.206.102:63807 -> 172.28.17.33/dog.gif (response) - pool info: foo 10.10.70.110 80 - status: 200 (request/response delta: 1ms) Oct 19 17:59:17 local/tmm info tmm[4601]: Rule myrule : Client 192.168.206.102:63807 -> 172.28.17.33/favicon.ico (response) - pool info: foo 10.10.70.110 80 - status: 404 (request/response delta: 2ms) Oct 19 17:59:17 local/tmm info tmm[4601]: Rule myrule : Client 192.168.206.102:63807 -> 172.28.17.33/favicon.ico (response) - pool info: foo 10.10.70.110 80 - status: 404 (request/response delta: 2ms) - Pav_70755
Nimbostratus
Thanks Nitass
I've added the following irule to the VS i want to log the traffic fromwhen HTTP_REQUEST { set flag 0 if {[HTTP::cookie exists "mxdata"]} { set flag 1 set http_request_time [clock clicks -milliseconds] set LogString "Client [IP::client_addr]:[TCP::client_port] -> [HTTP::host][HTTP::uri]" } } when HTTP_RESPONSE { if {$flag} { log local0. "$LogString (response) - pool info: [LB::server] - status: [HTTP::status] (request/response delta: [expr [clock clicks -milliseconds] - $http_request_time]ms)" } }
It doesnt seem to be logging anything in the ltm file? - nitass
Employee
is mxdata cookie really existing? can you try to remove if condition first just for testing? - nitass
Employee
sorry for duplicated message.
- Pav_70755
Nimbostratus
it does exist as searchprovider = mxdata although we know the ip address of the destination where the search is being called from so could just specify that instead of trying to use the cookie i guess?
could this just be done with a simple if {[HTTP::host] == "X.X.X.X"]} {? - nitass
Employee
could this just be done with a simple if {[HTTP::host] == "X.X.X.X"]} {?that's fine. by the way, using equals instead of == may be better.
additionally, you may capture packet to see how it is going.
tcpdump -nni 0.0:nnn -s0 -w /var/tmp/output.pcap port 80 - Pav_70755
Nimbostratus
I did try a tcpdump but there is too much data ultimatley we just want to find out how long the transfer time to and from this external host is
I modified the rule to this:when HTTP_REQUEST { set flag 0 if { [HTTP::host] eq "78.42.24.X" } { set flag 1 set http_request_time [clock clicks -milliseconds] set LogString "Client [IP::client_addr]:[TCP::client_port] -> [HTTP::host][HTTP::uri]" } } when HTTP_RESPONSE { if {$flag} { log local0. "$LogString (response) - pool info: [LB::server] - status: [HTTP::status] (request/response delta: [expr [clock clicks -milliseconds] - $http_request_time]ms)" } }
and in the ltm file got the following:
Oct 19 14:02:33 sys-bip-01 mcpd[1726]: 01070151:3: Rule [Data_Cookie_Log] error: line 3: [wrong args] [HTTP::host equals "78.42.24.X"] line 12: [use curly braces to avoid double substitution] [[clock clicks -milliseconds]] - nitass
Employee
this is time. can you double check square bracket of HTTP::host? i think your irule is correct.when HTTP_REQUEST { set flag 0 if {[HTTP::host] eq "172.28.17.33"} { set flag 1 set http_request_time [clock clicks -milliseconds] set LogString "Client [IP::client_addr]:[TCP::client_port] -> [HTTP::host][HTTP::uri]" } } when HTTP_RESPONSE { if {$flag} { log local0. "$LogString (response) - pool info: [LB::server] - status: [HTTP::status] (request/response delta: [expr [clock clicks -milliseconds] - $http_request_time]ms)" } } Oct 19 21:15:07 local/tmm info tmm[4601]: Rule myrule : Client 192.168.206.102:65430 -> 172.28.17.33/ (response) - pool info: foo 10.10.70.110 80 - status: 200 (request/response delta: 3ms) Oct 19 21:15:07 local/tmm info tmm[4601]: Rule myrule : Client 192.168.206.102:65430 -> 172.28.17.33/dog.gif (response) - pool info: foo 10.10.70.110 80 - status: 200 (request/response delta: 1ms) - Pav_70755
Nimbostratus
ok the ltm file hasnt been updated yet and i've changed it to this:when HTTP_REQUEST { set flag 0 if {[HTTP::host] eq "78.42.24.X" or [HTTP::cookie exists "mxdata"] } { set flag 1 set http_request_time [clock clicks -milliseconds] set LogString "Client [IP::client_addr]:[TCP::client_port] -> [HTTP::host][HTTP::uri]" } } when HTTP_RESPONSE { if {$flag} { log local0. "$LogString (response) - pool info: [LB::server] - status: [HTTP::status] (request/response delta: [expr [clock clicks -milliseconds] - $http_request_time]ms)" } } - Pav_70755
Nimbostratus
OK i've checked after about an hour and the ltm file doesnt seem to be getting any info logged from the irule?
this particular VS is making an external request to this host so i'm asuming it should be logged?
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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