Class: Fluent::Plugin::SyslogTlsOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::Plugin::SyslogTlsOutput
- 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 Attribute Summary collapse
-
#formatter ⇒ Object
Returns the value of attribute formatter.
Instance Method Summary collapse
-
#configure(conf) ⇒ Object
This method is called before starting.
- #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
- #process(tag, es) ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize ⇒ SyslogTlsOutput
Returns a new instance of SyslogTlsOutput.
119 120 121 122 |
# File 'lib/fluent/plugin/out_syslog_tls.rb', line 119 def initialize super @loggers = {} end |
Instance Attribute Details
#formatter ⇒ Object
Returns the value of attribute formatter.
116 117 118 |
# File 'lib/fluent/plugin/out_syslog_tls.rb', line 116 def formatter @formatter end |
Instance Method Details
#configure(conf) ⇒ Object
This method is called before starting.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/fluent/plugin/out_syslog_tls.rb', line 130 def configure(conf) if conf['output_type'] && !conf['format'] conf['format'] = conf['output_type'] end compat_parameters_convert(conf, :inject, :formatter) 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 add_host_backoff_spec(0, conf['host']+":"+conf['port']) @formatter = formatter_create(conf: conf.elements('format').first, default_type: DEFAULT_FORMAT_TYPE) end |
#format(tag, time, record) ⇒ Object
183 184 185 186 |
# File 'lib/fluent/plugin/out_syslog_tls.rb', line 183 def format(tag, time, record) record = inject_values_to_record(tag, time, record) @formatter.format(tag, time, record) end |
#logger(tag) ⇒ Object
Get logger for given tag
155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/fluent/plugin/out_syslog_tls.rb', line 155 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
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/fluent/plugin/out_syslog_tls.rb', line 167 def new_logger(tag) transport = ::SyslogTls::SSLTransport.new(host, port, idle_timeout: idle_timeout, ca_cert: ca_cert, client_cert: client_cert, client_key: client_key, verify_cert_name: verify_cert_name, max_retries: 3, ) logger = ::SyslogTls::Logger.new(transport, token) logger.facility(facility) logger.hostname(hostname) logger.app_name(tag) logger end |
#process(tag, es) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/fluent/plugin/out_syslog_tls.rb', line 188 def process(tag, es) 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 |
#shutdown ⇒ Object
124 125 126 127 |
# File 'lib/fluent/plugin/out_syslog_tls.rb', line 124 def shutdown @loggers.values.each(&:close) super end |