Skip to content

Commit

Permalink
Merge pull request #1616 from cosmo0920/resolve_hostname_in_syslog
Browse files Browse the repository at this point in the history
Add resolve_hostname config param in in_syslog
  • Loading branch information
repeatedly authored Jul 6, 2017
2 parents 2befef0 + 10d1f82 commit 7abad52
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/fluent/plugin/in_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class SyslogInput < Input

desc 'The field name of hostname of sender.'
config_param :source_hostname_key, :string, default: nil
config_param :resolve_hostname, :bool, default: nil
desc 'Connections will be disconnected right after receiving first message if this value is true.'
desc 'The field name of source address of sender.'
config_param :source_address_key, :string, default: nil
desc 'The field name of the priority.'
Expand Down Expand Up @@ -116,7 +118,13 @@ def configure(conf)
end
@source_address_key = @source_host_key
end
@resolve_name = !!@source_hostname_key
if @source_hostname_key
if @resolve_hostname.nil?
@resolve_hostname = true
elsif !@resolve_hostname # user specifies "false" in config
raise Fluent::ConfigError, "resolve_hostname must be true with source_hostname_key"
end
end

@_event_loop_run_timeout = @blocking_timeout
end
Expand All @@ -138,7 +146,7 @@ def start
end

def start_udp_server
server_create_udp(:in_syslog_udp_server, @port, bind: @bind, max_bytes: @message_length_limit, resolve_name: @resolve_name) do |data, sock|
server_create_udp(:in_syslog_udp_server, @port, bind: @bind, max_bytes: @message_length_limit, resolve_name: @resolve_hostname) do |data, sock|
message_handler(data.chomp, sock)
end
end
Expand All @@ -147,7 +155,7 @@ def start_tcp_server
# syslog family add "\n" to each message and this seems only way to split messages in tcp stream
delimiter = "\n"
delimiter_size = delimiter.size
server_create_connection(:in_syslog_tcp_server, @port, bind: @bind, resolve_name: @resolve_name) do |conn|
server_create_connection(:in_syslog_tcp_server, @port, bind: @bind, resolve_name: @resolve_hostname) do |conn|
buffer = ""
conn.data do |data|
buffer << data
Expand Down
18 changes: 18 additions & 0 deletions test/plugin/test_in_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ def test_configure(data)
assert_equal bind_addr, d.instance.bind
end

sub_test_case 'source_hostname_key and source_address_key features' do
test 'resolve_hostname must be true with source_hostname_key' do
assert_raise(Fluent::ConfigError) {
create_driver(CONFIG + <<EOS)
resolve_hostname false
source_hostname_key hostname
EOS
}
end

data('resolve_hostname' => 'resolve_hostname true',
'source_hostname_key' => 'source_hostname_key source_host')
def test_configure_reslove_hostname(param)
d = create_driver([CONFIG, param].join("\n"))
assert_true d.instance.resolve_hostname
end
end

data(
ipv4: ['127.0.0.1', CONFIG, ::Socket::AF_INET],
ipv6: ['::1', IPv6_CONFIG, ::Socket::AF_INET6],
Expand Down

0 comments on commit 7abad52

Please sign in to comment.