Forum Discussion

Algebraic_Mirror's avatar
Algebraic_Mirror
Icon for Cirrostratus rankCirrostratus
Nov 14, 2019
Solved

LTM Request Logging Profile: How can it log HTTP headers?

I've been looking at the "Request Logging" profile in LTM, wanting to use it to log details of each HTTP request that LTM sees. But in additional to logging standard things like timestamp, URI, etc, I want to log the value of various headers like "User-Agent" and "Referrer".

This profile has pretty sparse documentation, but the very last line of this document seems to hint that logging headers is possible. Here is what the last line says with regard to what you can enter into the logging template:

NULL      Undelineated strings return the value of the respective header.

The problem is, I don't know what the "NULL" reference means, or what "Undelineated strings" refers to. Can someone explain how to get this profile to log these headers?

WHAT I AM LOOKING FOR IN AN ANSWER:

  • I am not looking for iRule solutions that might do the same thing, so I respectfully request that you please don't post one as an answer. I know this can be done with an iRule, but to make this easy to maintain for those that come after me (who may not understand iRules), I am trying to find out if this request logging profile can do this in an out of the box way, and if so how.
  • If you can confirm that this is definitely not possible to do with this profile, that would be a good answer. But please make sure it's confirmed for certain.
  • If there is another out of the box way to do this that I'm missing, that would also be a good answer. But other modules like ASM, APM, etc, are not licensed or provisioned, so I can't use features specific to those modules. I only have LTM to work with.
  • That NULL can be ignored.

    The PARAMETERS are specified with $

    - eg $HTTP_METHOD

    to get a header, just specify the header with a leading $

    However, you may need to escape the header text with "{" and "}"

    Here is an example template that extracts header values

    $DATE_NCSA - |-REQ-| -- virtual=$VIRTUAL_NAME - http_class=$HTTP_CLASS -- client_ip=$CLIENT_IP client_port=$CLIENT_PORT snat_ip=$SNAT_IP snat_port=$SNAT_PORT lb_server=$SERVER_IP lb_port=$SERVER_PORT host=${host} username=${username} request=\"$HTTP_REQUEST\" user_agent=\"${User-agent}\" referer=\"${Referer}\"
    [14/Nov/2019: 16:53:06 -0800] - |-REQ-| -- virtual=/Common/http_vs - http_class= -- client_ip=172.16.0.147 client_port=45380 snat_ip= snat_port= lb_server=10.0.0.145 lb_port=80 host=172.16.0.250 username= request=\"GET / HTTP/1.1\" user_agent=\"curl/7.60.0\" referer=\"\"

    You can see the example logged output

2 Replies

  • That NULL can be ignored.

    The PARAMETERS are specified with $

    - eg $HTTP_METHOD

    to get a header, just specify the header with a leading $

    However, you may need to escape the header text with "{" and "}"

    Here is an example template that extracts header values

    $DATE_NCSA - |-REQ-| -- virtual=$VIRTUAL_NAME - http_class=$HTTP_CLASS -- client_ip=$CLIENT_IP client_port=$CLIENT_PORT snat_ip=$SNAT_IP snat_port=$SNAT_PORT lb_server=$SERVER_IP lb_port=$SERVER_PORT host=${host} username=${username} request=\"$HTTP_REQUEST\" user_agent=\"${User-agent}\" referer=\"${Referer}\"
    [14/Nov/2019: 16:53:06 -0800] - |-REQ-| -- virtual=/Common/http_vs - http_class= -- client_ip=172.16.0.147 client_port=45380 snat_ip= snat_port= lb_server=10.0.0.145 lb_port=80 host=172.16.0.250 username= request=\"GET / HTTP/1.1\" user_agent=\"curl/7.60.0\" referer=\"\"

    You can see the example logged output

    • Algebraic_Mirror's avatar
      Algebraic_Mirror
      Icon for Cirrostratus rankCirrostratus

      Thank you so much for explaining this. That was exactly what I needed. I had managed to figure out how to get the built in variables to work with the dollar signs in front, but that NULL thing just threw me off. I didn't realize you could directly put headers in there like that. (I actually did try it, but just my luck, I tried it out on user-agent without escaping it, and the "-" broke it, so I thought that meant it didn't work that way. But had I known to escape it, it would have!)