Sha256: 9b9ee000b098a3445f27e0f66538b3ba52ad0e0b719a76373529c382a2352374

Contents?: true

Size: 802 Bytes

Versions: 1

Compression:

Stored size: 802 Bytes

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
      @erb = ERB.new(@command.gsub(PLACEHOLDER_REGEXP, ERB_REGEXP))
    end

    def format(tag, time, record)
      [tag, time, record].to_msgpack
    end

    def emit(tag, es, chain)
      es.each {|time, record|
        prog = @erb.result(binding)
        system(prog)
        ecode = $?.to_i
        if ecode != 0
          raise "command returns #{ecode}: #{prog}"
        end
      }
      chain.next
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-exec_placeholder-0.0.1 lib/fluent/plugin/out_exec_placeholder.rb