Class: Fluent::Plugin::DedotFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/fluent/plugin/filter_dedot/version.rb,
lib/fluent/plugin/filter_dedot.rb

Constant Summary collapse

VERSION =
"1.0.0"

Instance Method Summary collapse

Constructor Details

#initializeDedotFilter

Returns a new instance of DedotFilter.



12
13
14
# File 'lib/fluent/plugin/filter_dedot.rb', line 12

def initialize
  super
end

Instance Method Details

#configure(conf) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fluent/plugin/filter_dedot.rb', line 16

def configure(conf)
  super

  if @de_dot && @de_dot_separator.include?(".")
    raise Fluent::ConfigError, "Invalid de_dot_separator: cannot be or contain '.'"
  end

  if @de_dot && @de_dot_nested
    log.info "DeDot will recurse nested hashes and arrays"
  end

end

#de_dot(record) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fluent/plugin/filter_dedot.rb', line 37

def de_dot(record)
  newrecord = {}

  record.each do |key, value|
    newkey = key.gsub(/\./, @de_dot_separator)

    # Recurse hashes and arrays:
    if @de_dot_nested
      if value.is_a? Hash
        value = de_dot value
      elsif value.is_a? Array
        value = value.map { |v| v.is_a?(Hash) ? de_dot(v) : v }
      end
    end

    newrecord[newkey] = value
  end

  newrecord
end

#filter(tag, time, record) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/fluent/plugin/filter_dedot.rb', line 29

def filter(tag, time, record)
  begin
    de_dot(record) if @de_dot
  rescue => e
    router.emit_error_event(tag, time, record, e)
  end
end