Forum Discussion

Yugandhar's avatar
Yugandhar
Icon for Nimbostratus rankNimbostratus
Oct 16, 2018

iRule to Log all the HTTP Requests.

Hi,

  1. Can we log each HTTP request (GET / POST) coming to a VS i.e. when a client connects to a virtual server on port 80 then can we add a log entry for every HTTP request from that connection or session.

  2. The Below iRule logs the IP of the client, Does this iRule get triggered for every HTTP Request ( GET / POST) with in a single connection so that there will be multiple entries of same client ip for a single connection.

when HTTP_REQUEST {

        set VS [IP::local_addr]
            set URI [HTTP::uri]
                log "Client [IP::client_addr]:[TCP::client_port] connected to VS ($vip)for URI $URI"

}

Thanks,

Yugandhar.

4 Replies

    • Yugandhar's avatar
      Yugandhar
      Icon for Nimbostratus rankNimbostratus

      Thank you it was a typo.. in the log stmt.

       

  • You should to log to a facility and a log level using

    log local0.
    ( see iRule wiki log reference) also your reference for the Virtual Server address is wrong and pointing to an invalid variable name
    $vip
    where you set
    $VS
    .

    This should work for you:

    when HTTP_REQUEST {
        set vip [IP::local_addr]
        set uri [HTTP::uri]
        log local0.info "Client [IP::client_addr]:[TCP::client_port] connected to VS ($vip)for URI $uri"
    }
    
  • Hi,

    You can use this:

    when HTTP_REQUEST {
    
    log local0. "LOGS: VS Name: [virtual]"
    log local0. "LOGS: Request: [HTTP::method] [HTTP::host][HTTP::uri]"
    
    foreach aHeader [HTTP::header names] {
        log local0. "LOGS: $aHeader: [HTTP::header value $aHeader]"
    }
    }
    

    You will retrieve Virtual Name, Method, Request and all request header.

    Regards,