From 4e4b3e5af23fecc4f7fc1ed1dd74346d93e9a863 Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 26 Sep 2018 10:36:18 +0900 Subject: [PATCH 1/4] Add test cases according to #2068 Signed-off-by: Kenji Okimoto --- test/plugin/test_parser_syslog.rb | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/plugin/test_parser_syslog.rb b/test/plugin/test_parser_syslog.rb index 7373000138..f5d0b7736e 100644 --- a/test/plugin/test_parser_syslog.rb +++ b/test/plugin/test_parser_syslog.rb @@ -149,6 +149,40 @@ def test_parse_with_rfc5424_structured_message assert_equal "Hi, from Fluentd!", record["message"] end end + + def test_parse_with_rfc5424_multiple_structured_message + @parser.configure( + 'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z', + 'message_format' => 'rfc5424', + 'with_priority' => true, + ) + text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"][exampleSDID@20224 class="high"] Hi, from Fluentd!' + @parser.instance.parse(text) do |time, record| + assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time) +assert_equal "11111", record["pid"] + assert_equal "ID24224", record["msgid"] + assert_equal "[exampleSDID@20224 iut=\"3\" eventSource=\"Application\" eventID=\"11211\"][exampleSDID@20224 class=\"high\"]", + record["extradata"] + assert_equal "Hi, from Fluentd!", record["message"] + end + end + + def test_parse_with_rfc5424_message_includes_right_bracket + @parser.configure( + 'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z', + 'message_format' => 'rfc5424', + 'with_priority' => true, + ) + text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"] Hi, from Fluentd]!' + @parser.instance.parse(text) do |time, record| + assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time) +assert_equal "11111", record["pid"] + assert_equal "ID24224", record["msgid"] + assert_equal "[exampleSDID@20224 iut=\"3\" eventSource=\"Application\" eventID=\"11211\"]", + record["extradata"] + assert_equal "Hi, from Fluentd]!", record["message"] + end + end end class TestAutoRegexp < self From abcb73b8c004232bb8a2a6544a349bc75c471252 Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 26 Sep 2018 10:45:24 +0900 Subject: [PATCH 2/4] Support empty message Signed-off-by: Kenji Okimoto --- lib/fluent/plugin/parser_syslog.rb | 4 ++-- test/plugin/test_parser_syslog.rb | 34 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/fluent/plugin/parser_syslog.rb b/lib/fluent/plugin/parser_syslog.rb index 954df0fa2f..998828430c 100644 --- a/lib/fluent/plugin/parser_syslog.rb +++ b/lib/fluent/plugin/parser_syslog.rb @@ -27,8 +27,8 @@ class SyslogParser < Parser REGEXP = /^(?