Class: Fluent::Plugin::DictMapFilter

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

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/fluent/plugin/filter_dict_map.rb', line 14

def configure(conf)
  super

  if !@dictionary and !@dictionary_path
    raise Fluent::ConfigError, "dictionary or dictionary_path parameter is required"
  end

  @dict = @dictionary ? @dictionary : load_dict(@dictionary_path)
  @target = @destination_key_name.nil? ? @key_name : @destination_key_name
end

#filter(tag, time, record) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fluent/plugin/filter_dict_map.rb', line 25

def filter(tag, time, record)
  value = record[@key_name]
  return record unless value

  value = value.to_s

  if @dict.include?(value)
    record[@target] = @dict[value]
  elsif !@default_value.nil?
    record[@target] = @default_value
  end

  record
end