Sha256: eb150117884ccefb759c831c3c85e62dc419e3a8717dc64221e47616f4ea3391
Contents?: true
Size: 1.04 KB
Versions: 1
Compression:
Stored size: 1.04 KB
Contents
require 'erb' module Fluent class ExecPlaceholderOutput < Output Fluent::Plugin.register_output('exec_placeholder', self) PLACEHOLDER_REGEXP = /\$\{([^}]+)\}/ ERB_REGEXP = "<%=record['" + '\1' + "'] %>" desc 'The command (program) to execute.' config_param :command, :string def initialize super end def configure(conf) super command = @command.gsub('${tag}', '<%=tag %>') command = command.gsub('${time}', '<%=time %>') command = command.gsub(PLACEHOLDER_REGEXP, ERB_REGEXP) log.info(%Q{command => #{command}}) @erb = ERB.new(command) end def format(tag, time, record) [tag, time, record].to_msgpack end def emit(tag, es, chain) es.each {|time, record| prog = get_prog(tag, time, record) system(prog) ecode = $?.to_i if ecode != 0 raise "command returns #{ecode}: #{prog}" end } chain.next end private def get_prog(tag, time, record) @erb.result(binding) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fluent-plugin-exec_placeholder-0.0.2 | lib/fluent/plugin/out_exec_placeholder.rb |