您好我正在尝试解析以下xml:
<msg time='2014-08-04T14:36:02.136+03:00' org_id='oracle' comp_id='rdbms'
msg_id='opistr_real:953:3971575317' type='NOTIFICATION' group='startup'
level='16' host_id='linux4_l' host_addr='127.0.0.1'
pid='8986' version='1'>
<txt>Starting ORACLE instance (normal)
</txt>
</msg>
使用此配置:
input {
stdin {
type => "stdin-type"
}
}
filter { multiline {
pattern => "^\s|</msg>|^[A-Za-z].*"
what => "previous"
}
xml {
store_xml => "false"
source => "message"
xpath => [
"/msg/@client_id", "msg_client_id",
"/msg/@host_id", "msg_host_id",
"/msg/@host_addr", "msg_host_addr",
"/msg/@level", "msg_level",
"/msg/@module", "msg_module",
"/msg/@msg_id", "msg_msg_id",
"/msg/@pid", "msg_pid",
"/msg/@org_id", "msg_org_id",
"/msg/@time", "msg_time",
"/msg/@level", "msg_level",
"/msg/txt/text()","msg_txt"
]
}
date {
match => [ "msg_time", "ISO8601" ]
}
mutate {
add_tag => "%{type}"
}
}
output { elasticsearch { host => localhost } stdout { codec => rubydebug } }
但是当我运行logstash时,我收到以下错误:
{:timestamp=>"2014-09-04T17:28:39.428000+0300", :message=>"Exception in filterworker", "exception"=>#<NoMethodError: undefined method `split' for ["msg_level", "msg_level"]:Array>, "backtrace"=>["/opt/logstash/lib/logstash/util/accessors.rb:19:in `parse'", "/opt/logstash/lib/logstash/util/accessors.rb:15:in `get'", "/opt/logstash/lib/logstash/util/accessors.rb:59:in `store_path'", "/opt/logstash/lib/logstash/util/accessors.rb:55:in `lookup'", "/opt/logstash/lib/logstash/util/accessors.rb:34:in `get'", "/opt/logstash/lib/logstash/event.rb:127:in `[]'", "/opt/logstash/lib/logstash/filters/xml.rb:117:in `filter'"
.... “/opt/logstash/lib/logstash/pipeline.rb:143:in`start_filters'”],:level =&gt;:error} {:timestamp =&gt;“2014-09-04T17:30:47.805000 + 0300”,:message =&gt;“中断收到。关闭管道。”,:level =&gt;:warn}
答案 0 :(得分:1)
我发现了我的问题,我在xpath,/ msg @ level apper上重复解析两次。
答案 1 :(得分:0)
multiline
编解码器不适合此类文件,但您可以使用以下内容:
multiline {
pattern => '<msg'
negate => true
what => previous
}
问题在于文件中的最后一个事件在下一个事件进入之前不会消失(因此您最终会丢失文件中的最后一个事件)。
答案 2 :(得分:0)
问题是文件中的最后一个事件在下一个事件进入之前不会消失(所以你最终会丢失文件中的最后一个事件)。
最好匹配结束标记。
multiline {
pattern => "</msg>$"
negate => true
what => next
}