class Fluent::Plugin::RemoteSyslogOutput

Public Class Methods

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

Public Instance Methods

close() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_remote_syslog.rb, line 68
def close
  super
  @senders.each { |s| s.close if s }
  @senders.clear
end
configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_remote_syslog.rb, line 48
def configure(conf)
  super
  if @host.nil? && @host_with_port.nil?
    raise ConfigError, "host or host_with_port is required"
  end

  @formatter = formatter_create
  unless @formatter.formatter_type == :text_per_line
    raise ConfigError, "formatter_type must be text_per_line formatter"
  end

  validate_target = "host=#{@host}/host_with_port=#{@host_with_port}/hostname=#{@hostname}/facility=#{@facility}/severity=#{@severity}/program=#{@program}"
  placeholder_validate!(:remote_syslog, validate_target)
  @senders = []
end
format(tag, time, record) click to toggle source
# File lib/fluent/plugin/out_remote_syslog.rb, line 74
def format(tag, time, record)
  r = inject_values_to_record(tag, time, record)
  @formatter.format(tag, time, r)
end
multi_workers_ready?() click to toggle source
# File lib/fluent/plugin/out_remote_syslog.rb, line 64
def multi_workers_ready?
  true
end
write(chunk) click to toggle source
# File lib/fluent/plugin/out_remote_syslog.rb, line 79
def write(chunk)
  return if chunk.empty?

  host = extract_placeholders(@host, chunk.metadata)
  port = @port

  if @host_with_port
    host, port = extract_placeholders(@host_with_port, chunk.metadata).split(":")
  end

  host_with_port = "#{host}:#{port}"

  Thread.current[host_with_port] ||= create_sender(host, port)
  sender = Thread.current[host_with_port]

  facility = extract_placeholders(@facility, chunk.metadata)
  severity = extract_placeholders(@severity, chunk.metadata)
  program = extract_placeholders(@program, chunk.metadata)
  hostname = extract_placeholders(@hostname, chunk.metadata)

  packet_options = {facility: facility, severity: severity, program: program}
  packet_options[:hostname] = hostname unless hostname.empty?

  begin
    chunk.open do |io|
      msg = io.read
      sender.transmit(msg.chomp!, packet_options)
    end
  rescue
    if Thread.current[host_with_port]
      Thread.current[host_with_port].close
      @senders.delete(Thread.current[host_with_port])
      Thread.current[host_with_port] = nil
    end
    raise
  end
end

Private Instance Methods

create_sender(host, port) click to toggle source
# File lib/fluent/plugin/out_remote_syslog.rb, line 119
def create_sender(host, port)
  if @protocol == :tcp
    options = {
      tls: @tls,
      whinyerrors: true,
      packet_size: @packet_size,
      timeout: @timeout,
      timeout_exception: @timeout_exception,
      keep_alive: @keep_alive,
      keep_alive_idle: @keep_alive_idle,
      keep_alive_cnt: @keep_alive_cnt,
      keep_alive_intvl: @keep_alive_intvl,
      program: @program,
    }
    options[:ca_file] = @ca_file if @ca_file
    options[:verify_mode] = @verify_mode if @verify_mode
    sender = RemoteSyslogSender::TcpSender.new(
      host,
      port,
      options
    )
  else
    sender = RemoteSyslogSender::UdpSender.new(
      host,
      port,
      whinyerrors: true,
      program: @program,
    )
  end
  @senders << sender
  sender
end