Class: Fluent::Plugin::TagNormaliserOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_tag_normaliser.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



34
35
36
37
38
# File 'lib/fluent/plugin/out_tag_normaliser.rb', line 34

def configure(conf)
  super
  @key_accessors = get_key_accessors
  @tag_map = Hash.new { |k, v| k[v] = "" }
end

#get_key_accessorsObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/fluent/plugin/out_tag_normaliser.rb', line 73

def get_key_accessors
  key_accessors = {}
  keywords = @format.scan(/\$\{([\w\.\/\-\\]+)}/)
  keywords.each do |key|
    placeholder = "${#{key[0]}}"
    if contains_escaped_period?(key[0])
      path = create_path_with_bracket_notation(key[0])
    else
      path = create_path(key[0])
    end
    key_accessors[placeholder] = record_accessor_create(path)
  end
  return key_accessors
end

#multi_workers_ready?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/fluent/plugin/out_tag_normaliser.rb', line 40

def multi_workers_ready?
  true
end

#process(tag, es) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fluent/plugin/out_tag_normaliser.rb', line 44

def process(tag, es)
  if @sticky_tags
    if @tag_map.has_key?(tag)
      router.emit_stream(@tag_map[tag], es)
      return
    end
  end
  new_tag = ""
  es.each do |time, record|
    new_tag = render_tag(record)
    router.emit(new_tag, time, record)
  end
  if @sticky_tags
    @tag_map[tag] = new_tag
  end
end

#render_tag(record) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fluent/plugin/out_tag_normaliser.rb', line 61

def render_tag(record)
  new_tag = @format.dup
  @key_accessors.each do |placeholder, accessor|
    value = accessor.call(record).to_s
    if value.empty?
      value = @unknown
    end
    new_tag = new_tag.gsub(placeholder, value)
  end
  return new_tag
end