Grok pattern for data separated by pipe
Asked Answered
H

4

8

I have a logfile in which the data is separated by a pipe symbol. "|". An example is below. Does anyone know how to write a GROK pattern to extract it for logstash?

2014-01-07 11:58:48.7694|LOGLEVEL|LOGSOURCE|LOGMESSAGE

Harrietteharrigan answered 7/1, 2014 at 20:54 Comment(0)
O
13

You can use gsub API to change the pipe "|" to space and the use GROK to extract it.

For example:

filter {
    grok {
            match => ["message","%{DATESTAMP:time}\|%{WORD:LOGLEVEL}\|%{WORD:LOGSOURCE}\|%{WORD:LOGMESSAGE}"]
    }
}

The above configuration is worked on me with your log. Hope this can help you.

Outgrow answered 8/1, 2014 at 6:43 Comment(2)
grok { match => ["message","%{DATESTAMP:time}\|%{WORD:LOGLEVEL}\|%{WORD:LOGSOURCE}\|%{WORD:LOGMESSAGE}"] } This also will work, it worked for meReynoso
@ArulT, your comment has more upvotes than the answer, can you please change it to a proper answer?Rob
E
6

use this filter:

it works for me. use this site to verify grok patern, https://grokdebug.herokuapp.com/

(?<date>(([0-9]+)-*)+ ([0-9]+:*)+.*)\|%{WORD:LOGLEVEL}\|%{WORD:LOGSOURCE}\|%{WORD:LOGMESSAGE}
Ensconce answered 28/4, 2016 at 11:13 Comment(0)
R
1

This worked for me

grok { match => ["message","%{DATESTAMP:time}\|%{WORD:LOGLEVEL}\|%{WORD:LOGSOURCE}\|%{WORD:LOGMESSAGE}"] }
Reynoso answered 9/10, 2020 at 16:30 Comment(0)
A
0

The LOGMESSAGE part can contain a long content. For this reason, I recommend the following usage.

%{GREEDYDATA:LOGMESSAGE}

Animalize answered 29/9, 2021 at 5:52 Comment(2)
Use grokdebug.herokuapp.comAnimalize
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Mcvay

© 2022 - 2024 — McMap. All rights reserved.