I am trying to extract certain fields from a single message field. I am trying to achieve this by grok regex on the logstash so that i could view them in kibana.
My log events is as below:
[2021-01-06 12:10:40] ApiLogger.INFO: API log data: {"endpoint":"/rest/thre_en/V1/temp-carts/13cEIQqUb6cUfxB/tryer-inform","http_method":"GET","payload":[],"user_id":0,"user_type":4,"http_response_code":200,"response":"{\"pay_methods\":[{\"code\":\"frane\",\"title\":\"R2 Partial redeem\"}],\"totals\":{\"grand_total\":0,\"base_grand_total\":0}}
The entire log has more information into different key value store- Basically, I needed these information -
- time stamp (i am able to get this)
- log level (I am able to get this) => on loglevel, i just want the info not the entire Api.INFO
- endpoint
- http-method
- user_id
- user_type
- http_response_code
- response
I am not able to get the information from 3-8 ... i tested it. it is due to the semi colon(:)
this is what i tried through grok debugger
%{SYSLOG5424SD:logtime} %{JAVACLASS:loglevel}: (?<API>\w+ \w+ \w+):
i tried uri and other but it did not work, may be due to the colon.
"response":
has no matching closing quote, is it correct? Did you forget to include it? – Wiktor Stribiżew.*?
in between,%{SYSLOG5424SD:logtime} %{JAVACLASS:loglevel}: (?<API>\w+ \w+ \w+):\s*\{"endpoint":"(?<endpoint>[^"]*)","http_method":"(?<http_method>[A-Z]++).*?"user_id":(?<user_id>[0-9]++).*?"user_type":(?<user_type>[0-9]++).*?"http_response_code":(?<http_response_code>[0-9]++).*?"response":"(?<response>.*)"
– Wiktor Stribiżew%{SYSLOG5424SD:logtime} ApiLogger.%{LOGLEVEL:loglevel}: API log data: %{GREEDYDATA:json_field}
and then you call the json filter on the json_field. – baudsp%{SYSLOG5424SD:logtime} ApiLogger.%{LOGLEVEL:loglevel}: (?<API>\w+ \w+ \w+):\s*%{GREEDYDATA:json_field}
and then parse thejson_field
with JSON filter. – Wiktor Stribiżew