Skip to content

Latest commit

 

History

History
22 lines (20 loc) · 1 KB

parse_and_log_username_from_http_req.md

File metadata and controls

22 lines (20 loc) · 1 KB

#Parse and Log Username from HTTP requests

HTTP logging is essential from most of the Web/App deployments where you want to capture the traffic details passing through. Authorization header in HTTP request carries the username which is important data to log for accountability of changes. This example shows how to parse and log the username from the Authorization header of HTTP Requests.

--HTTP_REQUEST
authorization_header = avi.http.get_header("Authorization")
basic_authorization = authorization_header:find("Basic")
if basic_authorization == 1 then
  credentials = {}
  -- user_id = credentials[1]
  -- password = credentials[2]
  authorization_decoded = avi.utils.base64_decode(authorization_header:sub(7))
  for match in authorization_decoded:gmatch("([^:]+),?") do
          table.insert(credentials,match)
  end
  user_id = credentials[1]
  avi.http.set_userid(user_id)
  -- avi.vs.log optional, as user_id logged through avi.http.set_userid method
  avi.vs.log("Authorization Username:"..user_id)
end