Multiple matches in same line using grok


#1

Hey guys, new-ish to Elastic and was hoping to get help for the following question.

To start off, I want to use logstash to parse a log file using grok statements.
Say I have an input as follows:

'Test failed with the following exception: Waiting for items to load: [selector: .do-something does.somethingElse, selector: do.another-thing, does.anotherThing... - '

Currently, I could use the 'selector:' as the start , and ' - ' as the end of the string captured, but within that I was hoping to get multiple matches in this same line. So in the end, I would like for the captured field to obtain:

created_field_in_elastic: .do-something does.somethingElse, do.another-thing, does.anotherThing.

However, it only captures the first one. Is this where I use multiline? How do I get this?


#2

not sure what your config is but have you tried setting break_on_match => false? By default the GROK will exit as soon as a mach is made.


#3

Yep, I do have that setting in there as well in the grok block


#4

It is unclear what you want in the created field. Do you want a string with the 4 things concatenated (which you can do using grok and mutate+gsub), or an array of 2 strings, or an array of 4 strings (both of which can be done using ruby).


#5

Preferably an array of 4 strings. So I should use ruby like this? https://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.helpers.step.StepContext.ruby


#6

Try something like

grok { match => { "message" => "selector: %{DATA:foo} - " } }
mutate {
    gsub => [
        "foo", ", selector: ", " ",
        "foo", ", ", " "
    ]
}
mutate { split => { "foo" => " " } }