Sha256: b0fb6471caef39a2292fcb7e3e0c9935f4deace9a510385acbe6a14ff22533ce

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

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

module Fluent
  class RemoteSyslogOutput < Fluent::Output
    Fluent::Plugin.register_output("kubernetes_remote_syslog", 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 :protocol, :string,  :default => 'udp'

    config_param :facility,     :string,  :default => "user"
    config_param :severity,     :string,  :default => "notice"
    config_param :tag,          :string,  :default => "fluentd"
    config_param :packet_size,  :integer, :default => 1024

    def initialize
      super
      require "remote_syslog_sender"
      @loggers = {}
    end

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

    def emit(tag, es, chain)
      chain.next
      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)
        if @protocol.downcase == 'tcp'
          @loggers[tag] ||= RemoteSyslogLogger::TcpSender.new(@host,
            @port,
            facility: @facility,
            severity: @severity,
            packet_size: @packet_size,
            program: tag,
            local_hostname: record['kubernetes_host'])
        else
          @loggers[tag] ||= RemoteSyslogLogger::UdpSender.new(@host,
            @port,
            facility: @facility,
            severity: @severity,
            packet_size: @packet_size,
            program: tag,
            local_hostname: record['kubernetes_host'])
        end


        @loggers[tag].transmit format(tag, time, record)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-kubernetes_remote_syslog-0.3.5 lib/fluent/plugin/out_kubernetes_remote_syslog.rb