Class: Fluent::Plugin::RemoteSyslogOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::Plugin::RemoteSyslogOutput
- Defined in:
- lib/fluent/plugin/out_remote_syslog_ms.rb
Instance Method Summary collapse
- #close ⇒ Object
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
-
#initialize ⇒ RemoteSyslogOutput
constructor
A new instance of RemoteSyslogOutput.
- #multi_workers_ready? ⇒ Boolean
- #write(chunk) ⇒ Object
Constructor Details
#initialize ⇒ RemoteSyslogOutput
Returns a new instance of RemoteSyslogOutput.
44 45 46 |
# File 'lib/fluent/plugin/out_remote_syslog_ms.rb', line 44 def initialize super end |
Instance Method Details
#close ⇒ Object
68 69 70 71 72 |
# File 'lib/fluent/plugin/out_remote_syslog_ms.rb', line 68 def close super @senders.each { |s| s.close if s } @senders.clear end |
#configure(conf) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fluent/plugin/out_remote_syslog_ms.rb', line 48 def configure(conf) super if @host.nil? && @host_with_port.nil? raise ConfigError, "host or host_with_port is required" end @formatter = formatter_create unless @formatter.formatter_type == :text_per_line raise ConfigError, "formatter_type must be text_per_line formatter" end validate_target = "host=#{@host}/host_with_port=#{@host_with_port}/hostname=#{@hostname}/facility=#{@facility}/severity=#{@severity}/program=#{@program}" placeholder_validate!(:remote_syslog, validate_target) @senders = [] end |
#format(tag, time, record) ⇒ Object
74 75 76 77 |
# File 'lib/fluent/plugin/out_remote_syslog_ms.rb', line 74 def format(tag, time, record) r = inject_values_to_record(tag, time, record) @formatter.format(tag, time, r) end |
#multi_workers_ready? ⇒ Boolean
64 65 66 |
# File 'lib/fluent/plugin/out_remote_syslog_ms.rb', line 64 def multi_workers_ready? true end |
#write(chunk) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/fluent/plugin/out_remote_syslog_ms.rb', line 79 def write(chunk) return if chunk.empty? host = extract_placeholders(@host, chunk.) port = @port if @host_with_port host, port = extract_placeholders(@host_with_port, chunk.).split(":") end host_with_port = "#{host}:#{port}" Thread.current[host_with_port] ||= create_sender(host, port) sender = Thread.current[host_with_port] facility = extract_placeholders(@facility, chunk.) severity = extract_placeholders(@severity, chunk.) program = extract_placeholders(@program, chunk.) hostname = extract_placeholders(@hostname, chunk.) = {facility: facility, severity: severity, program: program} [:hostname] = hostname unless hostname.empty? begin chunk.open do |io| io.each_line do |msg| sender.transmit(msg.chomp!, **) end end rescue if Thread.current[host_with_port] Thread.current[host_with_port].close @senders.delete(Thread.current[host_with_port]) Thread.current[host_with_port] = nil end raise end end |