From 4967c71f1ec64a3e7f2fd9f61e8770ee0341c7ee Mon Sep 17 00:00:00 2001 From: Lucas Barros Date: Mon, 9 Nov 2026 23:43:55 -0300 Subject: [PATCH 1/3] Use port when host_with_port has no port host_with_port without ":" left the port nil, so the sender was created for "host:" and every flush failed. A bracketed IPv6 address without a port, such as "[::1]", was also split at its last colon and became host "[:" and port "1]". Read the address up to the closing bracket, and fall back to the port parameter when no port is given. Signed-off-by: Lucas Barros --- README.md | 2 +- lib/fluent/plugin/out_remote_syslog.rb | 15 ++++++++------- test/plugin/out_remote_syslog.rb | 8 ++++++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4c9872a..9c0b191 100644 --- a/README.md +++ b/README.md @@ -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 `:` style. For an IPv6 address, use `"[]:"` (quoted) with `protocol tcp`. UDP does not support IPv6 yet. | +| host_with_port | string | support | parameter for `:` style. For an IPv6 address, use `"[]:"` (quoted) with `protocol tcp`. UDP does not support IPv6 yet. Without `:`, `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 | diff --git a/lib/fluent/plugin/out_remote_syslog.rb b/lib/fluent/plugin/out_remote_syslog.rb index 17949b9..a58387c 100644 --- a/lib/fluent/plugin/out_remote_syslog.rb +++ b/lib/fluent/plugin/out_remote_syslog.rb @@ -119,14 +119,15 @@ 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, _, rest = host_with_port[1..].partition("]") + port = rest.delete_prefix(":").split(":").first + else + host, port = host_with_port.split(":") + end + port = @port if port.nil? || port.empty? [host, port] end diff --git a/test/plugin/out_remote_syslog.rb b/test/plugin/out_remote_syslog.rb index ba54110..24272e2 100644 --- a/test/plugin/out_remote_syslog.rb +++ b/test/plugin/out_remote_syslog.rb @@ -127,6 +127,11 @@ 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}) def test_split_host_with_port(data) d = create_driver_out_syslog %[ @type remote_syslog @@ -140,11 +145,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 From 78b3d834e76426b357b19018e79cfa472ef6b08a Mon Sep 17 00:00:00 2001 From: Lucas Barros Date: Tue, 17 Nov 2026 19:52:36 -0300 Subject: [PATCH 2/3] Fall back to port only for a nil port, without Ruby 2.5+ methods Signed-off-by: Lucas Barros --- lib/fluent/plugin/out_remote_syslog.rb | 6 +++--- test/plugin/out_remote_syslog.rb | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/fluent/plugin/out_remote_syslog.rb b/lib/fluent/plugin/out_remote_syslog.rb index a58387c..88c9be1 100644 --- a/lib/fluent/plugin/out_remote_syslog.rb +++ b/lib/fluent/plugin/out_remote_syslog.rb @@ -122,12 +122,12 @@ def write(chunk) # "host:port", or "[ipv6]:port" for an IPv6 address. Without a port, `port` is used. def split_host_with_port(host_with_port) if host_with_port.start_with?("[") - host, _, rest = host_with_port[1..].partition("]") - port = rest.delete_prefix(":").split(":").first + host, _, rest = host_with_port[1..-1].partition("]") + port = rest.sub(/\A:/, "").split(":").first else host, port = host_with_port.split(":") end - port = @port if port.nil? || port.empty? + port = @port if port.nil? [host, port] end diff --git a/test/plugin/out_remote_syslog.rb b/test/plugin/out_remote_syslog.rb index 24272e2..a7c24b6 100644 --- a/test/plugin/out_remote_syslog.rb +++ b/test/plugin/out_remote_syslog.rb @@ -132,6 +132,7 @@ def test_write_tcp(data) 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: ""}) def test_split_host_with_port(data) d = create_driver_out_syslog %[ @type remote_syslog From d79db12081a9c3355f734b6fe512e08ac2cd7194 Mon Sep 17 00:00:00 2001 From: Lucas Barros Date: Sat, 21 Nov 2026 12:08:59 -0300 Subject: [PATCH 3/3] Keep the whole value as host when the closing bracket is missing Signed-off-by: Lucas Barros --- lib/fluent/plugin/out_remote_syslog.rb | 3 ++- test/plugin/out_remote_syslog.rb | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/fluent/plugin/out_remote_syslog.rb b/lib/fluent/plugin/out_remote_syslog.rb index 88c9be1..7619e84 100644 --- a/lib/fluent/plugin/out_remote_syslog.rb +++ b/lib/fluent/plugin/out_remote_syslog.rb @@ -122,7 +122,8 @@ def write(chunk) # "host:port", or "[ipv6]:port" for an IPv6 address. Without a port, `port` is used. def split_host_with_port(host_with_port) if host_with_port.start_with?("[") - host, _, rest = host_with_port[1..-1].partition("]") + 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(":") diff --git a/test/plugin/out_remote_syslog.rb b/test/plugin/out_remote_syslog.rb index a7c24b6..685cb86 100644 --- a/test/plugin/out_remote_syslog.rb +++ b/test/plugin/out_remote_syslog.rb @@ -133,6 +133,7 @@ def test_write_tcp(data) 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