I have an event whose message field I want to match against multiple patterns, if the message matches any of the patterns, then simply stop searching the remaining patterns in the list/array and write to output.
For reference this is all I could find on the site.
It says
If you need to match multiple patterns against a single field, the value can be an array of patterns:
The issue here is that both of the following filters work , by work I mean Logstash doesn't error out, so they're both syntactically correct.
What exactly is the difference between the following 2 filters ?
FILTER 1
filter {
if [fields][component][0] in ["data_vm"] {
grok {
patterns_dir => "/usr/share/logstash/patterns"
match => ["message", "(?m)^%{TIMESTAMP_ISO8601:date}%{SPACE}%{LOGLEVEL:loglevel}%{DATA:tr}%{SPACE}-%{SPACE}", "(?m)^%{TIMESTAMP_ISO8601:date}%{DATA:tr}%{SPACE}:%{SPACE}", "(?m)^%{TIMESTAMP_ISO8601:date}%{SPACE}%{DATA:tr}%{DATA:logger_class}:%{SPACE}"]
add_field => {"dhiwakar_new" => "%{message_r}"}
}
}
}
FILTER 2
filter {
if [fields][component][0] in ["data_vm"] {
grok {
patterns_dir => "/usr/share/logstash/patterns"
match => { "message" => ["(?m)^%{TIMESTAMP_ISO8601:date}%{SPACE}%{LOGLEVEL:loglevel}%{SPACE}%{DATA:tr}%{SPACE}-%{SPACE}", "(?m)^%{TIMESTAMP_ISO8601:date}%{SPACE}%{DATA:tr}%{SPACE}:%{SPACE}", "(?m)^%{TIMESTAMP_ISO8601:date}%{SPACE}%{DATA:tr}%{SPACE}-%{SPACE}%{DATA:logger_class}:%{SPACE}"]}
add_field => {"dhiwakar_new" => "%{message_r}"}
}
}
}