Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grok pattern for data separated by pipe

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

like image 456
CodeRunner Avatar asked Jan 07 '14 20:01

CodeRunner


3 Answers

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.

like image 129
Ben Lim Avatar answered Nov 18 '22 18:11

Ben Lim


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}
like image 6
Jeeva N Avatar answered Nov 18 '22 20:11

Jeeva N


This worked for me

grok { match => ["message","%{DATESTAMP:time}\|%{WORD:LOGLEVEL}\|%{WORD:LOGSOURCE}\|%{WORD:LOGMESSAGE}"] }
like image 1
AD14 Avatar answered Nov 18 '22 20:11

AD14