Sha256: 1966ed0b193f08a4fbc1936217cd47e6ebeb609d8c79555b00cd18abfe2337bc

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

module Fluent
  class NewrelicOutput < Output
    # First, register the plugin. NAME is the name of this plugin
    # and identifies the plugin in the configuration file.
    Fluent::Plugin.register_output('newrelic', self)
    
    config_param :tag, :string, default:'alert.newrelic.out' 

    # This method is called before starting.
    def configure(conf)
      super
    end

    # This method is called when starting.
    def start
      super
    end

    # This method is called when shutting down.
    def shutdown
      super
    end

    # This method is called when an event reaches Fluentd.
    # 'es' is a Fluent::EventStream object that includes multiple events.
    # You can use 'es.each {|time,record| ... }' to retrieve events.
    # 'chain' is an object that manages transactions. Call 'chain.next' at
    # appropriate points and rollback if it raises an exception.
    #
    # NOTE! This method is called by Fluentd's main thread so you should not write slow routine here. It causes Fluentd's performance degression.
    def emit(tag, es, chain)
      chain.next
      es.each {|time,record|
        $stderr.puts "OK!"
	if (record.has_key?("server_events")) 
		newhash = Hash.new
		# If the record value is not a array, then assign the name to value
		record.each_pair do |singlekey, singlevalue|
			if (singlevalue.class == String)
				newhash[singlekey]=singlevalue
			end
		end
		
		# Walk thro the array and assign each value
		record["server_events"].each_with_index do |attr, idx|
			temphash=Hash.new
			# Each value within the array is a hash
			# Iterate thro the hash and assign the values
			attr.each_pair do |key, value|
				temphash[key]=value
				newhash[key]=value
			end	
			newhash["raw"]=temphash.clone
			Fluent::Engine.emit @tag, time.to_i, newhash
		end
	else
		# Emit as is
		Fluent::Engine.emit @tag, time, record
	end
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-newrelictransform-0.0.3 lib/fluent/plugin/out_newrelic.rb