lib/fluent/plugin/in_syslog.rb in fluentd-0.12.33 vs lib/fluent/plugin/in_syslog.rb in fluentd-0.12.34
- old
+ new
@@ -86,19 +86,22 @@
else
raise ConfigError, "syslog input protocol type should be 'tcp' or 'udp'"
end
end
desc 'If true, add source host to event record.'
- config_param :include_source_host, :bool, default: false
+ config_param :include_source_host, :bool, default: false, deprecated: "use source_hostname_key instead"
desc 'Specify key of source host when include_source_host is true.'
- config_param :source_host_key, :string, default: 'source_host'.freeze
+ config_param :source_host_key, :string, default: 'source_host'.freeze, deprecated: "use source_hostname_key instead"
+ desc "The field name of the client's hostname."
+ config_param :source_hostname_key, :string, default: nil
desc 'The field name of the priority.'
config_param :priority_key, :string, default: nil
desc 'The field name of the facility.'
config_param :facility_key, :string, default: nil
- config_param :blocking_timeout, :time, default: 0.5
+ desc "The max bytes of message"
config_param :message_length_limit, :size, default: 2048
+ config_param :blocking_timeout, :time, default: 0.5
def configure(conf)
super
if conf.has_key?('format')
@@ -108,10 +111,14 @@
conf['with_priority'] = true
@parser = TextParser::SyslogParser.new
@parser.configure(conf)
@use_default = true
end
+
+ if @source_hostname_key.nil? && @include_source_host
+ @source_hostname_key = @source_host_key
+ end
end
def start
callback = if @use_default
method(:receive_data)
@@ -160,11 +167,11 @@
facility = FACILITY_MAP[pri >> 3]
priority = PRIORITY_MAP[pri & 0b111]
record[@priority_key] = priority if @priority_key
record[@facility_key] = facility if @facility_key
- record[@source_host_key] = addr[2] if @include_source_host
+ record[@source_hostname_key] = addr[2] if @source_hostname_key
tag = "#{@tag}.#{facility}.#{priority}"
emit(tag, time, record)
}
rescue => e
@@ -183,11 +190,11 @@
facility = FACILITY_MAP[pri >> 3]
priority = PRIORITY_MAP[pri & 0b111]
record[@priority_key] = priority if @priority_key
record[@facility_key] = facility if @facility_key
- record[@source_host_key] = addr[2] if @include_source_host
+ record[@source_hostname_key] = addr[2] if @source_hostname_key
tag = "#{@tag}.#{facility}.#{priority}"
emit(tag, time, record)
}
rescue => e
@@ -200,13 +207,13 @@
def listen(callback)
log.info "listening syslog socket on #{@bind}:#{@port} with #{@protocol_type}"
if @protocol_type == :udp
@usock = SocketUtil.create_udp_socket(@bind)
@usock.bind(@bind, @port)
- SocketUtil::UdpHandler.new(@usock, log, @message_length_limit, callback)
+ SocketUtil::UdpHandler.new(@usock, log, @message_length_limit, callback, !!@source_hostname_key)
else
# syslog family add "\n" to each message and this seems only way to split messages in tcp stream
- Coolio::TCPServer.new(@bind, @port, SocketUtil::TcpHandler, log, "\n", callback)
+ Coolio::TCPServer.new(@bind, @port, SocketUtil::TcpHandler, log, "\n", callback, !!@source_hostname_key)
end
end
def emit(tag, time, record)
router.emit(tag, time, record)