Hey all, I am new to logstash and I am setting up logstash on a server which gets multiple formats of logs in the same type. I was wondering if there is a way i could write just one grok expressions for these logs by adding some exceptions or optional values, or do i need a separate grok expression for each log format as i wrote below.
here is the first log format:
1.2.3.4 5.6.7.8 - - [06/Jun/2019:13:38:24 +0000] "GET /homepage/v1?HTTP/1.0" 200 25853 "test.com" "https://test.com/homepage" "useragent" "-" - 0.05 0.24
and the grok expression i use for this is:
%{IP:internal-ip} %{IP:clientip} - - \[%{HTTPDATE:timestamp}\] \"(?:%{WORD:method} /%{DATA:page}/%{DATA:version}\? HTTP/%{NUMBER:httpversion})\" %{NUMBER:httpresponse} %{NUMBER:responsebytes} %{QS:hostname} %{QS:referrer} %{QS:useragent} %{QS:affaid} - %{NUMBER:requesttime} %{NUMBER:responsetime}
and the second log format is:
11.12.13.14 15.16.17.18 - - [06/Jun/2019:13:38:24 +0000] "GET /customersupport/form/v1?submission=yes&repeat=no&id=123HTTP/1.0" 200 25853 "test.com" "https://test.com/homepage" "useragent" "-" - 0.05 0.24
and the grok expression i wrote for the second format is:
%{IP:internal-ip} %{IP:clientip} - - \[%{HTTPDATE:timestamp}\] \"(?:%{WORD:method} /%{DATA:page}/%{DATA:value}/%{DATA:version}\?%{DATA:submission}&%{DATA:repeat}&%{DATA:id} HTTP/%{NUMBER:httpversion})\" %{NUMBER:httpresponse} %{NUMBER:responsebytes} %{QS:hostname} %{QS:referrer} %{QS:useragent} %{QS:affaid} - %{NUMBER:requesttime} %{NUMBER:responsetime}
they work well individually but if i try to mix both the format with optional grok values then they either mismatch or get an error.
if i do need to include both the grok expression in logstash can you guys advice me on how to differentiate on how logstash selects each grok expression for each of the logs format. Thanks