Forum Discussion

ashk's avatar
ashk
Icon for Cirrus rankCirrus
Apr 10, 2024

Capture live traffic into the browser

Hello everyone.

Iam trying to capture the live traffic to the virtual server into the table in a browser using below irule. Am unable to execute this iRule and giving errors. could someone assist if they use any different method to capture the live logs for troubleshooting instead of packetcapture. 

 

when HTTP_REQUEST {
     if { [HTTP::uri] equals "/f5logs" } {
     # Respond with HTTP 200 OK and content type
        HTTP::respond 200 content "<html><head><title>Live Logs</title></head><body><table border='1'><tr><th>Time</th><th>Full URL</th><th>Status Code</th><th>LB Pool</th><th>LB Server</th><th>Source IP</th></tr>"
     
     # Log request details in the table
        log local0 "<tr><td>[clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S"]</td><td>[HTTP::host][HTTP::uri]</td><td></td><td></td><td></td><td>[IP::client_addr]</td></tr>"
 }
}

when HTTP_RESPONSE {
     if { [HTTP::uri] equals "/f5logs" } {
     # Log response details in the table
         log local0 "<tr><td>[clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S"]</td><td>[HTTP::host][HTTP::uri]</td><td>[HTTP::status]</td><td>[LB::server pool]</td><td>[LB::server]</td><td>[IP::client_addr]</td></tr>"
     }
}

1 Reply

  • First error:

    log local0 must be log local0. (You forgot the ending dot).

     

    Second error:

    [HTTP::URI] and some other functions are not valid in the HTTP_RESPONSE event. Set a variable in the HTTP_REQUEST event and use is in the HTTP_RESPONSE event.

     

    All your errors should be logged to /var/log/ltm.