简体   繁体   English

Logstash-希腊多行

[英]Logstash - grok multiline

I tried using multiline in grok filters but its not working properly. 我尝试在grok过滤器中使用多行,但无法正常工作。

My Logs are 我的日志是

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

My conf file is 我的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" }}

I am able to process the first line of log file, but second line of log file is not working where I would like to use multiline 我能够处理日志文件的第一行,但是在我想使用多行的地方,日志文件的第二行不起作用

Output i would like to have 我想要的输出

{

"@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"
}   

Kindly help me to get required output. 请帮助我获得所需的输出。

Your multiline config says, "if I find this pattern, keep it with the previous line". 您的多行配置说:“如果找到此模式,请与上一行保持一致”。

Your pattern "^(\\s|[AZ][az]).*" says "either a space, or a capital letter followed by a lowercase letter, then followed by other stuff". 您的模式“ ^(\\ s | [AZ] [az])。*”表示“空格或大写字母后跟小写字母,再跟其他内容”。

So, " foo" or "California" would match, but "H3" wouldn't. 因此,“ foo”或“ California”将匹配,但“ H3”将不匹配。

I would suggest a pattern that matches the start of your multiline expression, and use the 'negate' feature to have all lines that don't match that pattern join to the original line: 我建议一个匹配多行表达式开始的模式,并使用“求反”功能使所有不匹配该模式的行都连接到原始行:

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

This would take the "H3|" 这将采用“ H3 |” line as the beginning, and join all other lines to it. 行作为开始,然后将所有其他行加入其中。 Depending on the range of values at the beginning of the line, you may need to edit the regexp. 根据行开头的值范围,您可能需要编辑regexp。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM