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

Raises:

  • (Fluent::ConfigError)


33
34
35
36
37
# File 'lib/fluent/plugin/filter_array_splitter.rb', line 33

def configure(conf)
  super
  raise Fluent::ConfigError, "'array_key' parameter is required" unless conf.has_key?('array_key')
  log.info "Configuring Array Splitter Filter"
end

#filter_stream(tag, es) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fluent/plugin/filter_array_splitter.rb', line 39

def filter_stream(tag, es)
  new_es = Fluent::MultiEventStream.new

  es.each do |time, record|
    if record[@array_key].is_a?(Array)
      record[@array_key].each do |value|
        new_record = record.dup
        new_record.delete(@array_key)

        if value.is_a?(Hash)
          value.each { |k, v| new_record[k] = v }
        else
          new_record[@key_name.nil? ? @array_key : @key_name] = value
        end

        new_es.add(time, new_record)
      end
    else
      new_es.add(time, record)
    end
  end

  new_es
end