Class: Fluent::ScriptAppendOutput

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

Constant Summary collapse

SUPPORTED_SCRIPT_NAME =
%w(ruby sh shell)

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fluent/plugin/out_script_append.rb', line 14

def configure(conf)
  super
  ensure_param_set!(:key, @key)
  ensure_param_set!(:run_script, @run_script)
  ensure_param_set!("new_tag or prefix", (@new_tag or @prefix))

  @script_runner = Object.new

  unless SUPPORTED_SCRIPT_NAME.include? @language
    warn "Plugin out_script_append would not accept 'language' value other than 'ruby'. Ignoring."
    @language = 'ruby'
  end

  case @language
  when 'ruby'
    eval <<-RUBY
      def @script_runner.run(#{@record_var_name})
        #{@run_script}
      end
    RUBY
  when 'sh', 'shell'
    script = @run_script.gsub(/`/, '\\\`')
    eval <<-RUBY
      def @script_runner.run(*)
        `#{@run_script}`
      end
    RUBY
  end
end

#emit(tag, event_stream, chain) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/fluent/plugin/out_script_append.rb', line 44

def emit(tag, event_stream, chain)
  event_stream.each do |time, record|
    rewrited_tag = get_new_tag(tag)
    record[@key] = @script_runner.run(record)
    Fluent::Engine.emit(rewrited_tag, time, record)
  end
  chain.next
end