| 
2 | 2 |   require "logstash/filters/base"  | 
3 | 3 |   require "logstash/namespace"  | 
4 | 4 |   require "logstash/environment"  | 
 | 5 | +  require "logstash/event"  | 
5 | 6 |   require "logstash/patterns/core"  | 
6 | 7 |   require "grok-pure" # rubygem 'jls-grok'  | 
7 | 8 |   require "set"  | 
@@ -237,6 +238,14 @@ class LogStash::Filters::Grok < LogStash::Filters::Base  | 
237 | 238 |     # will be parsed and `hello world` will overwrite the original message.  | 
238 | 239 |     config :overwrite, :validate => :array, :default => []  | 
239 | 240 | 
 
  | 
 | 241 | +    # If this attribute is set, the output of this filter will be an array  | 
 | 242 | +    # of objects written to the key supplied in this config value.  | 
 | 243 | +    #  | 
 | 244 | +    # If this attribute is not set and the input is an array then context of  | 
 | 245 | +    # the captures will be lost and values will be grouped by capture name  | 
 | 246 | +    # rather than the message it came from.  | 
 | 247 | +    config :output_objects, :validate => :string, :default => nil  | 
 | 248 | + | 
240 | 249 |     attr_reader :timeout_enforcer  | 
241 | 250 | 
 
  | 
242 | 251 |     # Register default pattern paths  | 
@@ -334,18 +343,27 @@ def match(groks, field, event)  | 
334 | 343 | 
 
  | 
335 | 344 |     private  | 
336 | 345 |     def match_against_groks(groks, field, input, event)  | 
 | 346 | +      target_event = @output_objects ? LogStash::Event.new : event  | 
 | 347 | + | 
337 | 348 |       input = input.to_s  | 
338 | 349 |       matched = false  | 
339 | 350 |       groks.each do |grok|  | 
340 | 351 |         # Convert anything else to string (number, hash, etc)  | 
341 | 352 | 
 
  | 
342 | 353 |         matched = @timeout_enforcer.grok_till_timeout(grok, field, input)  | 
343 | 354 |         if matched  | 
344 |  | -          grok.capture(matched) {|field, value| handle(field, value, event)}  | 
 | 355 | +          grok.capture(matched) {|field, value| handle(field, value, target_event)}  | 
345 | 356 |           break if @break_on_match  | 
346 | 357 |         end  | 
347 | 358 |       end  | 
348 |  | -        | 
 | 359 | + | 
 | 360 | +      if @output_objects  | 
 | 361 | +        output_array = event.get(@output_objects)  | 
 | 362 | +        output_array = [] unless output_array.is_a? Array  | 
 | 363 | +        output_array << target_event.to_hash  | 
 | 364 | +        event.set(@output_objects, output_array)  | 
 | 365 | +      end  | 
 | 366 | + | 
349 | 367 |       matched  | 
350 | 368 |     end  | 
351 | 369 | 
 
  | 
 | 
0 commit comments