class Fluent::GELFOutput

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_gelf.rb, line 19
def initialize
  super
end

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_gelf.rb, line 23
def configure(conf)
  super(conf)

  # a destination hostname or IP address must be provided
  raise ConfigError, "'host' parameter (hostname or address of Graylog2 server) is required" unless conf.has_key?('host')

  # choose protocol to pass to gelf-rb Notifier constructor
  # (@protocol is used instead of conf['protocol'] to leverage config_param default)
  if @protocol == 'udp' then @proto = GELF::Protocol::UDP
  elsif @protocol == 'tcp' then @proto = GELF::Protocol::TCP
  else raise ConfigError, "'protocol' parameter should be either 'udp' (default) or 'tcp'"
  end
end
format(tag, time, record) click to toggle source
# File lib/fluent/plugin/out_gelf.rb, line 60
def format(tag, time, record)
  if defined? Fluent::EventTime and time.is_a? Fluent::EventTime then
    timestamp = time.sec + (time.nsec.to_f/1000000000).round(3)
  else
    timestamp = time
  end

  make_gelfentry(
    tag,time,record,
    {
      :use_record_host => @use_record_host,
      :add_msec_time => @add_msec_time
    }
  ).to_msgpack

end
formatted_to_msgpack_binary() click to toggle source
# File lib/fluent/plugin/out_gelf.rb, line 83
def formatted_to_msgpack_binary
  true
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_gelf.rb, line 56
def shutdown
  super
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_gelf.rb, line 37
def start
  super

  options = {:facility => 'fluentd', :protocol => @proto}

  # add tls key (tls_options) only when tls = True
  # see https://github.com/graylog-labs/gelf-rb/blob/72916932b789f7a6768c3cdd6ab69a3c942dbcef/lib/gelf/notifier.rb#L133-L140
  if @tls then
    options[:tls] = @tls_options
  end

  @conn = GELF::Notifier.new(@host, @port, 'WAN', options)

  # Errors are not coming from Ruby so we use direct mapping
  @conn.level_mapping = 'direct'
  # file and line from Ruby are in this class, not relevant
  @conn.collect_file_and_line = false
end
write(chunk) click to toggle source
# File lib/fluent/plugin/out_gelf.rb, line 77
def write(chunk)
  chunk.msgpack_each do |data|
    @conn.notify(data)
  end
end