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.
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
You can give a grok filter a list of patterns to match against. Given that you need your pattern to match the entire line you should definitely anchor it using ^ -- otherwise grok has to retry the pattern match starting at every position in the field you are matching against.
If that is not clear try to understand that
grok { match => { "message" => "HTTP/%{NUMBER:httpVersion}" } }
will match both your messages. grok does not care what comes before or after the fragment of your field that matches the pattern.
I had to adjust the spaces in some of your patterns to match the messages, but that might have been an issue with cut and paste and my editor automatically wrapping.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.