Class: Fluent::Plugin::RemoteSyslogOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::Plugin::RemoteSyslogOutput
- Defined in:
- lib/fluent/plugin/out_remote_syslog.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.
47 48 49 |
# File 'lib/fluent/plugin/out_remote_syslog.rb', line 47 def initialize super end |
Instance Method Details
#close ⇒ Object
71 72 73 74 75 |
# File 'lib/fluent/plugin/out_remote_syslog.rb', line 71 def close super @senders.each { |s| s.close if s } @senders.clear end |
#configure(conf) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fluent/plugin/out_remote_syslog.rb', line 51 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
77 78 79 80 |
# File 'lib/fluent/plugin/out_remote_syslog.rb', line 77 def format(tag, time, record) r = inject_values_to_record(tag, time, record) @formatter.format(tag, time, r) end |
#multi_workers_ready? ⇒ Boolean
67 68 69 |
# File 'lib/fluent/plugin/out_remote_syslog.rb', line 67 def multi_workers_ready? true end |
#write(chunk) ⇒ Object
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 117 118 119 |
# File 'lib/fluent/plugin/out_remote_syslog.rb', line 82 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 |