Class: Fluent::Plugin::ArraySplitterFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/fluent/plugin/filter_array_splitter.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



10
11
12
13
# File 'lib/fluent/plugin/filter_array_splitter.rb', line 10

def configure(conf)
  super
  log.info "Configuring Array Splitter Filter"
end

#filter_stream(tag, es) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fluent/plugin/filter_array_splitter.rb', line 15

def filter_stream(tag, es)
  new_es = Fluent::MultiEventStream.new
  es.each do |time, record|
    if record['message'].is_a?(Array)
      record['message'].each do |value|
        new_record = record.dup
        new_record['message'] = value
        new_es.add(time, new_record)
      end
    elsif record['target_field'].is_a?(Array)
      record['target_field'].each do |hash|
        hash.each do |k, v|
          new_record = record.dup
          new_record.delete('target_field')
          new_record[k] = v
          new_es.add(time, new_record)
        end
      end
    else
      new_es.add(time, record)
    end
  end
  new_es
end