Class: Fluent::SyslogTlsOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::SyslogTlsOutput
- Includes:
- HandleTagNameMixin, Mixin::ConfigPlaceholders
- Defined in:
- lib/fluent/plugin/out_syslog_tls.rb
Constant Summary collapse
- DEFAULT_FORMAT_TYPE =
'json'- SYSLOG_HEADERS =
Allow to map keys from record to syslog message headers
[ :severity, :facility, :hostname, :app_name, :procid, :msgid ]
Instance Method Summary collapse
-
#configure(conf) ⇒ Object
This method is called before starting.
- #emit(tag, es, chain) ⇒ Object
- #format(tag, time, record) ⇒ Object
-
#initialize ⇒ SyslogTlsOutput
constructor
A new instance of SyslogTlsOutput.
-
#logger(tag) ⇒ Object
Get logger for given tag.
- #new_logger(tag) ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize ⇒ SyslogTlsOutput
Returns a new instance of SyslogTlsOutput.
49 50 51 52 53 |
# File 'lib/fluent/plugin/out_syslog_tls.rb', line 49 def initialize super require 'syslog_tls/logger' @loggers = {} end |
Instance Method Details
#configure(conf) ⇒ Object
This method is called before starting.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/fluent/plugin/out_syslog_tls.rb', line 61 def configure(conf) super @host = conf['host'] @port = conf['port'] @token = conf['token'] @hostname = conf['hostname'] || Socket.gethostname.split('.').first # Determine mapping of record keys to syslog keys @mappings = {} SYSLOG_HEADERS.each do |key_name| conf_key = "#{key_name}_key" @mappings[key_name] = conf[conf_key] if conf.key?(conf_key) end @formatter = Plugin.new_formatter(@format) @formatter.configure(conf) end |
#emit(tag, es, chain) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/fluent/plugin/out_syslog_tls.rb', line 105 def emit(tag, es, chain) chain.next es.each do |time, record| record.each_pair do |_, v| v.force_encoding('utf-8') if v.is_a?(String) end # Check if severity has been provided in record otherwise use INFO # by default. severity = if @mappings.key?(:severity) record[@mappings[:severity]] || 'INFO' else 'INFO' end # Send message to Syslog begin logger(tag).log(severity, format(tag, time, record), time: Time.at(time)) do |header| # Map syslog headers from record @mappings.each do |name, record_key| header.send("#{name}=", record[record_key]) unless record[record_key].nil? end end rescue => e log.error e.to_s end end end |
#format(tag, time, record) ⇒ Object
101 102 103 |
# File 'lib/fluent/plugin/out_syslog_tls.rb', line 101 def format(tag, time, record) @formatter.format(tag, time, record) end |
#logger(tag) ⇒ Object
Get logger for given tag
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/fluent/plugin/out_syslog_tls.rb', line 80 def logger(tag) # Try to reuse existing logger @loggers[tag] ||= new_logger(tag) # Create new logger if old one is closed if @loggers[tag].closed? @loggers[tag] = new_logger(tag) end @loggers[tag] end |
#new_logger(tag) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/fluent/plugin/out_syslog_tls.rb', line 92 def new_logger(tag) transport = ::SyslogTls::SSLTransport.new(host, port, ca_cert: ca_cert, cert: cert, key: key, max_retries: 3) logger = ::SyslogTls::Logger.new(transport, token) logger.facility(facility) logger.hostname(hostname) logger.app_name(tag) logger end |
#shutdown ⇒ Object
55 56 57 58 |
# File 'lib/fluent/plugin/out_syslog_tls.rb', line 55 def shutdown super @loggers.values.each(&:close) end |