Class: Fluent::ConfigExpanderOutput

Inherits:
MultiOutput
  • Object
show all
Defined in:
lib/fluent/plugin/out_config_expander.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#outputsObject (readonly)

Returns the value of attribute outputs.



30
31
32
# File 'lib/fluent/plugin/out_config_expander.rb', line 30

def outputs
  @outputs
end

#pluginObject

Returns the value of attribute plugin.



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

def plugin
  @plugin
end

Instance Method Details

#builtin_mappingObject



19
20
21
# File 'lib/fluent/plugin/out_config_expander.rb', line 19

def builtin_mapping
  {'__hostname__' => @hostname, '__HOSTNAME__' => @hostname, '${hostname}' => @hostname, '${HOSTNAME}' => @hostname}
end

#configure(conf) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fluent/plugin/out_config_expander.rb', line 32

def configure(conf)
  super

  configs = conf.elements.select{|e| e.name == 'config'}
  if configs.size != 1
    raise Fluent::ConfigError, "config_expander needs just one <config> ... </config> section"
  end
  ex = expand_config(configs.first)
  @plugin = Fluent::Plugin.new_output(ex['type'])
  @plugin.configure(ex)

  @outputs = [@plugin]

  mark_used(configs.first)
end

#emit(tag, es, chain) ⇒ Object



56
57
58
# File 'lib/fluent/plugin/out_config_expander.rb', line 56

def emit(tag, es, chain)
  @plugin.emit(tag, es, chain)
end

#expand_config(conf) ⇒ Object



23
24
25
26
27
28
# File 'lib/fluent/plugin/out_config_expander.rb', line 23

def expand_config(conf)
  ex = Fluent::Config::Expander.expand(conf, builtin_mapping())
  ex.name = ''
  ex.arg = ''
  ex
end

#mark_used(conf) ⇒ Object



14
15
16
17
# File 'lib/fluent/plugin/out_config_expander.rb', line 14

def mark_used(conf)
  conf.keys.each {|key| conf[key] } # to suppress unread configuration warning
  conf.elements.each{|e| mark_used(e)}
end

#shutdownObject



52
53
54
# File 'lib/fluent/plugin/out_config_expander.rb', line 52

def shutdown
  @plugin.shutdown
end

#startObject



48
49
50
# File 'lib/fluent/plugin/out_config_expander.rb', line 48

def start
  @plugin.start
end