Forum Discussion

Shruti_Malik_84's avatar
Shruti_Malik_84
Icon for Nimbostratus rankNimbostratus
May 11, 2007

iRule to log domainname from http_request and location from http_response

Hi,

 

 

Can i write an i-Rule to log in ltm file where i can log domain name from http_request header and location from http_response header

 

Waiting for reply!!

 

 

Regards

 

Shruti
  • The request part is easy, when you say "location from the response header" what exactly do you mean by that? Do you mean the HTTP "Location" header that is returned on a 301 or 302 redirect?

     

     

    Here's the code the request and response (if a Location header is returned from the server).

     

     

    when HTTP_REQUEST {
      log local0. "Domain: [HTTP::host]"
      log local0. "URI: [HTTP::uri]"
    }
    when HTTP_RESPONSE {
      if { [HTTP::header exists "Location"] } {
        log local0. "Location: [HTTP::header Location]"
      }
    }

     

     

    Hope this helps...

     

     

    -Joe
  • Hi Joe,

     

    I wanted the HTTP "Location" header only(u were right) but when i applied this iRule it does not display the location

     

     

    The LTM logs are as follows:

     

     

    May 14 12:38:30 tmm tmm[26162]: Rule loc : Domain: www.testingf5.com

     

    May 14 12:38:30 tmm tmm[26162]: Rule loc : URI: /

     

     

    Is there any other alternative to display "Location"
  • As far as I know the Location header is specific to 301 and 302 based redirects where it's value is the new location the browser is supposed to request for the updated link. It is not returned for all HTTP responses (if that is what you were expecting). If the supplied rule does not display log the Location header, that is because it a header with the name of "Location" is not returned in the HTTP response. For non-redirect based responses, the only clue on the document location is given by the Request URI.

     

     

    -Joe
  • Hi,

     

    Thanks for the reply.

     

    I was able to get the logs in "ltm".

     

    I want to improve the i-Rule in a way that logging takes place in a customised file.

     

    I mean that i-Rule should create a file and logging of that i-Rule takes place in that file.

     

     

    Waiting for reply.

     

    Regards,

     

    Shruti