'AWS log Insigts parse NGINX log
I am trying to use aws log insights to run query on my log group that contains nginx log.
This is my log format that I have setup on my ec2 machine:
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
Sample NGINX Log:
xx.xx.xx.xx - - [10/Nov/2020:15:28:30 +0530] "POST /xx HTTP/1.1" 200 57 "https://xxxx.in/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" "-"
I am trying to parse this using log insights with the following code:
parse @message '* - - [*] "* * *" * * "-" "*"' as remote_addr, timestamp, request_type, location, protocol, response_code, body_bytes_sent
I am getting the following error:
Expression is invalid: parse@message'* - - [*] "* * *" * * "-" "*"'asremote_addr,timestamp,request_type,location,protocol,response_code,body_bytes_sent
Any help would be appreiciated
Solution 1:[1]
It would be even better with referrer and user_agent
fields @timestamp, @message
| parse @message '* - - [*] "* * *" * * "*" "*"' as remote_addr, timestamp, request_type, location, protocol, response_code, body_bytes_sent, referrer, user_agent
| display @timestamp, remote_addr, request_type, location, protocol, response_code, body_bytes_sent, referrer, user_agent
| sort @timestamp desc
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ChiChing Shek |
