2015-04-02 93 views
1

我尝试在Grok过滤器中使用多行,但其工作不正常。Logstash - grok multiline

我的日志是

H3|15:55:04:760|exception|not working properly 
message:space exception 
at line number 25 

我的conf文件

input { file { 

    path => "logs/test.log" 
    start_position => beginning 
    sincedb_path => "/dev/null" 
    }} 
filter{ 

multiline { 

    pattern => "^(\s|[A-Z][a-z]).*" 
    what => "previous" 
    } 
if [message] =~ /H\d+/{ 

grok { 

match => ["message", "(?m)%{USERNAME:level}\|%{TIME:timestamp}\|%{WORD:method}\|%{GREEDYDATA:error_Message}" ] 
    } 
    } 

    else { 

    grok { 

match => ["message", "(?m)%{GREEDYDATA:error_Message}" ] 
    } 
    } 
    } 

output {elasticsearch { host => "localhost" protocol => "http" port => "9200" }} 

我能够处理日志文件的第一行,但日志文件的第二行不工作,我想使用多

输出我想有

{ 

"@timestamp" => "2014-06-19 00:00:00,000" 
"path" => "logs/test.log" 
"level"=>"H3" 
"timestamp"=>15:55:04:760 
"method"=>exception 
"error_message"=>not working properly 
}, 
{ 
"@timestamp" => "2014-06-19 00:00:00,000" 
"path" => "logs/test.log" 
"error_message" => "space exception at line 25" 
} 

请帮助我获得所需的输出。

+0

你认为你的正则表达式匹配了什么? “^(\ s | [A-Z] [a-z])*” – 2015-04-02 16:16:21

+0

嗨,Alain是logstash和这个多行的新手,我认为它会检查第一个字母是从空格开始 – raj 2015-04-06 09:29:25

回答

1

你的多行配置说:“如果我找到这种模式,请保留它的前一行”。

您的模式“^(\ s | [A-Z] [a-z])。”“要么是空格,要么是大写字母后跟小写字母,然后是其他东西。

所以,“foo”或“California”会匹配,但“H3”不会。

我建议你多表达的开始相匹配的模式,并使用“否定”功能有不匹配的图案线条都加盟原线路:

filter { 
    multiline { 
     pattern => "^[A-Z][0-9]\|" 
     negate => 'true' 
     what => 'previous' 
    } 
    } 
} 

这会采取“H3 |”行作为开始,并加入所有其他行。根据行开始处的值范围,您可能需要编辑正则表达式。