Sha256: 27fa12939da1c5d57f5841b89f6ad2a48355bb76a60a62a5502338ee4b26192c

Contents?: true

Size: 917 Bytes

Versions: 2

Compression:

Stored size: 917 Bytes

Contents

require 'pp'
class Fluent::AddOutput < Fluent::Output
  Fluent::Plugin.register_output('add', self)

  config_param :add_tag_prefix, :string, :default => 'greped'

  def initialize
    super
  end

  def configure(conf)
    super

    # @key = @key.to_s
    # @value = @value.to_s 
    @tag_prefix = "#{@add_tag_prefix}."
    @add_hash = Hash.new

    @tag_proc =
      if @tag_prefix
        Proc.new {|tag| "#{@tag_prefix}#{tag}" }
      else
        Proc.new {|tag| tag }
      end
    conf.elements.select {|element|
      element.name == 'pair' 
    }.each do |pair|
      pair.each do | k,v|
       @add_hash[k] = v
      end
    end 
  end

  def emit(tag, es, chain)
    emit_tag = @tag_proc.call(tag)

    es.each do |time,record|
      # record[@key] = @value
      @add_hash.each do |k,v|
        record[k] = v
      end
      Fluent::Engine.emit(emit_tag, time, record)
    end

    chain.next
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fluent-plugin-add-0.0.3 lib/fluent/plugin/out_add.rb
fluent-plugin-add-0.0.2 lib/fluent/plugin/out_add.rb