2016-08-30 91 views
0

多個過濾器我有日誌行作爲初級講座:logstash應用基於條件

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

的XML過濾器失敗,因爲輸入是不是有效的XML。
您必須提取XML,然後使用XML過濾器。爲了提取XML,你將不得不使用神交過濾器使用此模式:

%{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 { 
    ... 
} 
+0

喜將ü能夠提出小片段就如何實現上述片段request..no需要的內部細節,只是如何實現語法這 –