Sha256: 25eebc9ff944e569e33d8a32cbd20efcddccda28a297a61a64091aae31d89b77

Contents?: true

Size: 1.45 KB

Versions: 1

Compression:

Stored size: 1.45 KB

Contents

module Fluent
  class KubernetesTaggedRemoteSyslogOutput < Fluent::Output
    Fluent::Plugin.register_output('kubernetes_tagged_remote_syslog', self)

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

    config_param :facility, :string, default: 'user'
    config_param :severity, :string, default: 'notice'
    config_param :program, :string, default: 'pod_name'
    config_param :hostname, :string, default: 'namespace_name'
    config_param :skip_namespaces, :string, default: 'deis kube-system'

    def initialize
      super
      require "remote_syslog_logger"
      @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

        next if skip_namespaces.include?(record.dig('kubernetes', 'namespace_name'))

        @loggers[tag] ||= RemoteSyslogLogger::UdpSender.new(
          @host,
          @port,
          facility: record['facility'] || @facility,
          severity: record['severity'] || @severity,
          program: (record.dig('kubernetes', @program) || @program)[0...31],
          local_hostname: (record.dig('kubernetes', @hostname) || @hostname)[0...31])

        @loggers[tag].transmit((if record.key?('log') then record['log'] else record end).to_s)
      end
      chain.next
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-kubernetes_tagged_remote_syslog-0.3.6 lib/fluent/plugin/out_kubernetes_tagged_remote_syslog.rb