[英]Correct ELK multiline regular expression?
我是ELK的新手,我正在编写一个使用多行的配置文件,我们需要为输入数据写一个模式
110000|read|<soapenv:Envelope>
<head>hello<head>
<body></body>
</soapenv:Envelope>|<soapenv:Envelope>
<body></body>
</soapenv:Envelope>
210000|read|<soapenv:Envelope>
<head>hello<head>
<body></body>
</soapenv:Envelope>|<soapenv:Envelope>
<body></body>
</soapenv:Envelope>
370000|read|<soapenv:Envelope>
<head>hello<head>
<body></body>
</soapenv:Envelope>|<soapenv:Envelope>
<body></body>
</soapenv:Envelope>
和使用的配置文件是:
input {
file {
path => "/opt/test5/practice_new/xml_input.dat"
start_position => "beginning"
codec => multiline
{
pattern => "^%{INT}\|%{WORD}\|<soapenv:Envelope*>\|<soapenv"
negate => true
what => "previous"
}
}
}
filter {
grok {
match => [ "message", "%{DATA:method_id}\|%{WORD:method_type}\|%{GREEDYDATA:request}\|%{GREEDYDATA:response}" ]
}
}
output {
elasticsearch {
hosts => "http://localhost:9200"
index => "xml"
}
stdout {}
}
但是其中使用的模式不符合我的要求。
请给我建议正确的模式。
预期产量:
对于第一个日志
method_id- 110000
method type-
request-
response-
对于第二个日志
method id- 210000
method type-
request-
response-
其余的类似。
首先,您必须修复多行模式:
codec => multiline {
pattern => "^%{NUMBER:method_id}\|%{DATA:method_type}\|<soapenv:Envelope>"
negate => true
what => previous
}
之后,您可以使用Wiktor在注释中建议的模式:
(?m)^(?<method_id>\d+)\|(?<method_type>\w+)\|(?<request><soapenv:Envelope>.*?</soapenv:Envelope>)\|(?<response><soapenv:Envelope>.*?</soapenv:Envelope>)
在http://grokconstructor.appspot.com上发布以下三个日志行的结果:
您的整个配置可能如下所示:
input {
file {
path => "/opt/test5/practice_new/xml_input.dat"
start_position => "beginning"
codec => multiline {
pattern => "^%{NUMBER:method_id}\|%{DATA:method_type}\|<soapenv:Envelope>"
negate => true
what => previous
}
}
}
filter {
grok {
match => [ "message", "(?m)^(?<method_id>\d+)\|(?<method_type>\w+)\|(?<request><soapenv:Envelope>.*?</soapenv:Envelope>)\|(?<response><soapenv:Envelope>.*?</soapenv:Envelope>)" ]
}
}
output {
elasticsearch {
hosts => "http://localhost:9200"
index => "xml"
}
stdout {}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.