Module: Fluent::Mixin::RewriteTagName

Includes:
RecordFilterMixin
Defined in:
lib/fluent/mixin/rewrite_tag_name.rb

Defined Under Namespace

Classes: PlaceholderExpander

Constant Summary collapse

DEFAULT_HOSTNAME_COMMAND =
'hostname'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#enable_placeholder_hostnameObject

Returns the value of attribute enable_placeholder_hostname.



6
7
8
# File 'lib/fluent/mixin/rewrite_tag_name.rb', line 6

def enable_placeholder_hostname
  @enable_placeholder_hostname
end

#enable_placeholder_upcaseObject

Returns the value of attribute enable_placeholder_upcase.



6
7
8
# File 'lib/fluent/mixin/rewrite_tag_name.rb', line 6

def enable_placeholder_upcase
  @enable_placeholder_upcase
end

#hostname_commandObject

Returns the value of attribute hostname_command.



5
6
7
# File 'lib/fluent/mixin/rewrite_tag_name.rb', line 5

def hostname_command
  @hostname_command
end

#tagObject

Returns the value of attribute tag.



5
6
7
# File 'lib/fluent/mixin/rewrite_tag_name.rb', line 5

def tag
  @tag
end

Instance Method Details

#configure(conf) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fluent/mixin/rewrite_tag_name.rb', line 10

def configure(conf)
  super

  @placeholder_expander = PlaceholderExpander.new

  if enable_upcase = conf['enable_placeholder_upcase']
    @enable_placeholder_upcase = enable_upcase
  end
  if @enable_placeholder_upcase
    @placeholder_expander.enable_placeholder_upcase
  end

  if enable_hostname = conf['enable_placeholder_hostname']
    @enable_placeholder_hostname = enable_hostname
  end
  if @enable_placeholder_hostname
    hostname_command = @hostname_command || DEFAULT_HOSTNAME_COMMAND
    hostname = `#{hostname_command}`.chomp
    @placeholder_expander.enable_placeholder_hostname
    @placeholder_expander.set_hostname(hostname)
  end
end

#filter_record(tag, time, record) ⇒ Object



33
34
35
36
37
38
# File 'lib/fluent/mixin/rewrite_tag_name.rb', line 33

def filter_record(tag, time, record)
  super
  if @tag
    rewrite_tag!(tag)
  end
end

#rewrite_tag!(tag) ⇒ Object



40
41
42
43
44
45
# File 'lib/fluent/mixin/rewrite_tag_name.rb', line 40

def rewrite_tag!(tag)

  @placeholder_expander.set_tag(tag)
  emit_tag = @placeholder_expander.expand(@tag)
  tag.gsub!(tag, emit_tag)
end