Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ $ td-agent-gem install fluent-plugin-remote_syslog
| hostname | string | support | departure of log |
| host | string | support | syslog target host |
| port | integer (default: `514`) | | syslog target port |
| host_with_port | string | support | parameter for `<host>:<port>` style. For an IPv6 address, use `"[<host>]:<port>"` (quoted) with `protocol tcp`. UDP does not support IPv6 yet. |
| host_with_port | string | support | parameter for `<host>:<port>` style. For an IPv6 address, use `"[<host>]:<port>"` (quoted) with `protocol tcp`. UDP does not support IPv6 yet. Without `:<port>`, `port` is used. |
| facility | string (default: `"user"`) | support | syslog facility |
| severity | string (default: `"notice"` | support | syslog severity |
| program | string (default: `"fluentd"` | support | syslog program name |
Expand Down
16 changes: 9 additions & 7 deletions lib/fluent/plugin/out_remote_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,16 @@ def write(chunk)

private

# "host:port", or "[ipv6]:port" for an IPv6 address
# "host:port", or "[ipv6]:port" for an IPv6 address. Without a port, `port` is used.
def split_host_with_port(host_with_port)
return host_with_port.split(":") unless host_with_port.start_with?("[")

host, separator, port = host_with_port.rpartition(":")
return [host_with_port, nil] if separator.empty?

host = host[1..-2] if host.start_with?("[") && host.end_with?("]")
if host_with_port.start_with?("[")
host, bracket, rest = host_with_port[1..-1].partition("]")
host = host_with_port if bracket.empty?
port = rest.sub(/\A:/, "").split(":").first
else
host, port = host_with_port.split(":")
end
port = @port if port.nil?
[host, port]
end

Expand Down
10 changes: 10 additions & 0 deletions test/plugin/out_remote_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ def test_write_tcp(data)
data("ipv4 with trailing colon", {value: "127.0.0.1:514:", host: "127.0.0.1", port: "514"})
data("ipv4 with extra field", {value: "127.0.0.1:514:extra", host: "127.0.0.1", port: "514"})
data("ipv6", {value: "[2001:db8::1]:514", host: "2001:db8::1", port: "514"})
data("ipv6 with extra field", {value: "[2001:db8::1]:514:extra", host: "2001:db8::1", port: "514"})
data("host without port", {value: "example.com", host: "example.com", port: 514})
data("host with empty port", {value: "example.com:", host: "example.com", port: 514})
data("ipv6 without port", {value: "[::1]", host: "::1", port: 514})
data("ipv6 with empty port", {value: "[2001:db8::1]:", host: "2001:db8::1", port: 514})
data("empty port field", {value: "example.com::6514", host: "example.com", port: ""})
data("ipv6 without closing bracket", {value: "[2001:db8::1:6514", host: "[2001:db8::1:6514", port: 514})
def test_split_host_with_port(data)
d = create_driver_out_syslog %[
@type remote_syslog
Expand All @@ -140,11 +147,14 @@ def test_split_host_with_port(data)

data("ipv4", {host_with_port: "127.0.0.1:5567", bind: "127.0.0.1"})
data("ipv6", {host_with_port: "[::1]:5567", bind: "::1"})
data("ipv4 without port", {host_with_port: "127.0.0.1", port: 5567, bind: "127.0.0.1"})
data("ipv6 without port", {host_with_port: "[::1]", port: 5567, bind: "::1"})
def test_write_tcp_with_host_with_port(data)
out_driver = create_driver_out_syslog %[
@type remote_syslog
hostname foo.com
host_with_port "#{data[:host_with_port]}"
#{"port #{data[:port]}" if data[:port]}
program minitest

protocol tcp
Expand Down
Loading