Sha256: 961861db29e5a1cd054b94d4ad98901f7163e5d039a78cb03701a9a75395c527

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

require "fluent/mixin/config_placeholders"
require "fluent/mixin/plaintextformatter"
require 'fluent/mixin/rewrite_tag_name'

module Fluent
  class RemoteSyslogTcpOutput < Fluent::Output
    Fluent::Plugin.register_output("remote_syslog_tcp", self)

    config_param :hostname, :string, :default => ""

    include Fluent::Mixin::PlainTextFormatter
    include Fluent::Mixin::ConfigPlaceholders
    include Fluent::HandleTagNameMixin
    include Fluent::Mixin::RewriteTagName

    config_param :host, :string
    config_param :port, :integer, :default => 514

    config_param :facility, :string, :default => "syslog"
    config_param :severity, :string, :default => "debug"
    config_param :tag, :string, :default => "fluentd"

    def initialize
      super
      require "remote_syslog_logger_custom"
      require "socket"
      @loggers = {}
    end

    def shutdown
      @loggers.values.each(&:close)
      super
    end

    def emit(tag, es, chain)
      es.each do |time, record|
        record.each_pair do |k, v|
          if v.is_a?(String)
            v.force_encoding("utf-8")
          end
        end

        tag = rewrite_tag!(tag.dup)
        @loggers[tag] ||= RemoteSyslogLoggerCustom::TcpSender.new(@host,
          @port,
          facility: record["facility"] || @facility,
          severity: record["severity"] || @severity,
          program: tag,
          local_hostname: Socket.gethostname)
        time = Time.at(time, record['time_key'].to_i * 1000) if record['time_key']
        @loggers[tag].transmit format(time, time, record)
      end
      chain.next
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-remote_syslog_tcp-0.3.9.4 lib/fluent/plugin/out_remote_syslog_tcp.rb