require 'fluent/output' require_relative 'norikra/output' require 'norikra-client' module Fluent class NorikraOutput < Fluent::BufferedOutput include Fluent::NorikraPlugin::OutputMixin Fluent::Plugin.register_output('norikra', self) config_set_default :flush_interval, 1 # 1sec config_param :norikra, :string, :default => 'localhost:26571' config_param :connect_timeout, :integer, :default => nil config_param :send_timeout, :integer, :default => nil config_param :receive_timeout, :integer, :default => nil #for OutputMixin config_param :remove_tag_prefix, :string, :default => nil config_param :target_map_tag, :bool, :default => false config_param :target_map_key, :string, :default => nil config_param :target_string, :string, :default => nil config_param :drop_error_record, :bool, :default => true config_param :drop_server_error_record, :bool, :default => false config_param :drop_when_shutoff, :bool, :default => false # # # Define `log` method for v0.10.42 or earlier unless method_defined?(:log) define_method("log") { $log } end def configure(conf) super @host,@port = @norikra.split(':', 2) @port = @port.to_i if !@target_map_tag && @target_map_key.nil? && @target_string.nil? raise Fluent::ConfigError, 'target naming not specified (target_map_tag/target_map_key/target_string)' end setup_output(conf, false) # disabled in and end def client(opts={}) Norikra::Client.new(@host, @port, { :connect_timeout => opts[:connect_timeout] || @connect_timeout, :send_timeout => opts[:send_timeout] || @send_timeout, :receive_timeout => opts[:receive_timeout] || @receive_timeout, }) end def start super start_output end def shutdown stop_output shutdown_output end def fetchable? true end # For Fluentd 0.14 compatibility. # Fluent::Compat::BufferedOutput expects the plugin class itself # (but not its included module) to define `format_stream` when overriding. def format_stream(*) super end end end