我的日志行如下:
11:05:44,924 DEBUG DataFeed:? - Data received: data=TextMessage={ Header={ JMSMessageID={ID:someId} JMSDestination={Topic[someTopic]} JMSReplyTo={null} JMSDeliveryMode={NON_PERSISTENT} JMSRedelivered={false} JMSCorrelationID={null} JMSType={null} JMSTimestamp={Tue Aug 30 11:05:44 BST 2016} JMSExpiration={Tue Aug 30 11:06:44 BST 2016} JMSPriority={4} } Properties={ ACTION={String:ADD} XT_S_USER={String:someString} APPNAME={String:someFeeName} XT_BOOK={String:someBook} } Text={<?xml version="1.0"?><!DOCTYPE PSRequest><PSRequest><trade>..XML Tags..</trade></PSRequest>} }
我正在尝试在上面的日志行中应用XML过滤器,该过滤器失败了:
:exception=>#<NoMethodError: undefined method `start_with?' for nil:NilClass>, :backtrace=>["/jruby/1.9/gems/logstash-core-event-2.3.2-java/lib/logstash/event.rb:130:in `[]='", "/jruby/1.9/gems/logstash-filter-xml-2.1.4/lib/logstash/filters/xml.rb:166:in `filter'", "/jruby/1.9/gems/logstash-core-2.3.2-java/lib/logstash/filters/base.rb:151:in `multi_filter'", "org/jruby/RubyArray.java:1613:in `each'", "/jruby/1.9/gems/logstash-core-2.3.2-java/lib/logstash/filters/base.rb:148:in `multi_filter'", "(eval):41:in `filter_func'", "/jruby/1.9/gems/logstash-core-2.3.2-java/lib/logstash/pipeline.rb:267:in `filter_batch'", "org/jruby/RubyArray.java:1613:in `each'", "org/jruby/RubyEnumerable.java:852:in `inject'", "/jruby/1.9/gems/logstash-core-2.3.2-java/lib/logstash/pipeline.rb:265:in `filter_batch'", "/jruby/1.9/gems/logstash-core-2.3.2-java/lib/logstash/pipeline.rb:223:in `worker_loop'", "/jruby/1.9/gems/logstash-core-2.3.2-java/lib/logstash/pipeline.rb:201:in `start_workers'"], :level=>:warn}
某些行也没有XML内容,我想将它们发送到grok过滤器,我该如何实现呢?
编辑: 关于如何实现以下的小片段 我的情况是这样的:
if(message.contains(certainText)) {
//apply grok filter and extract xml from it and send it to xml filter and then to ES
} else if(message.contains(someOtherText)) {
//Apply grok filter and extract key value pairs and send it to kv filter and then to ES
} else {
//straight away send that message to ES without any parsing.
}
答案 0 :(得分:0)
XML过滤器失败,因为输入不是有效的XML 您必须提取XML然后使用XML过滤器。要提取XML,您必须使用具有此模式的grok过滤器:
%{GREEDYDATA} Text={%{GREEDYDATA:xml}} }
它将创建一个名为xml的字段,其中包含:<?xml·version="1.0"?><!DOCTYPE·PSRequest><PSRequest><trade>..XML·Tags..</trade></PSRequest>
然后你可以在这个字段上使用xml过滤器。
要将不包含XML的行发送到另一个grok过滤器,可以使用conditionals分隔部分配置。如果您想要更精确的答案,则必须在日志中添加更多信息(如果您使用其他问题则更好)。
编辑:
if [message] ~= /certainText/ {
...
} else if [message] ~= /someOtherText/ {
...
} else {
...
}