From f18f3a1d3fc6d7c32dd042ff1c4a0437c2db0f4c Mon Sep 17 00:00:00 2001 From: Yuta Iwama Date: Wed, 1 Apr 2020 11:38:31 +0900 Subject: [PATCH 1/2] Fix regression in the case with_priority and rfc5424 priority which is passed to in_syslog should be integer Signed-off-by: Yuta Iwama --- lib/fluent/plugin/parser_syslog.rb | 2 +- test/plugin/test_in_syslog.rb | 15 +++++++++++++++ test/plugin/test_parser_syslog.rb | 10 ++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/fluent/plugin/parser_syslog.rb b/lib/fluent/plugin/parser_syslog.rb index bd51492342..d5abe9ad76 100644 --- a/lib/fluent/plugin/parser_syslog.rb +++ b/lib/fluent/plugin/parser_syslog.rb @@ -175,7 +175,7 @@ def parse_rfc5424_regex(text, &block) if @with_priority if (m = RFC5424_PRI_REGEXP.match(text)) - record['pri'] = m['pri'] + record['pri'] = m['pri'].to_i idx = m.end(0) else yield(nil, nil) diff --git a/test/plugin/test_in_syslog.rb b/test/plugin/test_in_syslog.rb index fd4c49f0e4..13dbcbe86d 100755 --- a/test/plugin/test_in_syslog.rb +++ b/test/plugin/test_in_syslog.rb @@ -163,6 +163,21 @@ def test_msg_size_with_tcp compare_test_result(d.events, tests) end + def test_emit_rfc5452 + d = create_driver([CONFIG, "facility_key pri\n\n message_format rfc5424\nwith_priority true\n"].join("\n")) + msg = '<1>1 2017-02-06T13:14:15.003Z myhostname 02abaf0687f5 10339 02abaf0687f5 - method=POST db=0.00' + + d.run(expect_emits: 1, timeout: 2) do + u = UDPSocket.new + u.connect('127.0.0.1', PORT) + u.send(msg, 0) + end + + tag, _, event = d.events[0] + assert_equal('syslog.kern.alert', tag) + assert_equal('kern', event['pri']) + end + def test_msg_size_with_same_tcp_connection d = create_driver([CONFIG, " \n"].join("\n")) tests = create_test_case diff --git a/test/plugin/test_parser_syslog.rb b/test/plugin/test_parser_syslog.rb index c8b9cd0770..b72a6b4be7 100644 --- a/test/plugin/test_parser_syslog.rb +++ b/test/plugin/test_parser_syslog.rb @@ -73,6 +73,16 @@ def test_parse_with_priority(param) assert_equal("%b %d %H:%M:%S", @parser.instance.patterns['time_format']) end + data('regexp' => 'regexp', 'string' => 'string') + def test_parse_rfc5452_with_priority(param) + @parser.configure('with_priority' => true, 'parser_type' => param, 'message_format' => 'rfc5424') + @parser.instance.parse('<30>1 2020-03-31T20:32:54Z myhostname 02abaf0687f5 10339 02abaf0687f5 - method=POST db=0.00') do |time, record| + assert_equal(event_time('2020-03-31T20:32:54Z', format: '%Y-%m-%dT%H:%M:%S%z'), time) + expected = { 'extradata' => '-', 'host' => 'myhostname', 'ident' => '02abaf0687f5', 'message' => 'method=POST db=0.00', 'msgid' => '02abaf0687f5', 'pid' => '10339', 'pri' => 30 } + assert_equal(expected, record) + end + end + data('regexp' => 'regexp', 'string' => 'string') def test_parse_with_empty_priority(param) @parser.configure('with_priority' => true, 'parser_type' => param) From 167eb7c4ef82ef8336b8401b0c65d8663744b002 Mon Sep 17 00:00:00 2001 From: Yuta Iwama Date: Wed, 1 Apr 2020 15:45:15 +0900 Subject: [PATCH 2/2] Add an assertion to existing test case Signed-off-by: Yuta Iwama --- test/plugin/test_parser_syslog.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/plugin/test_parser_syslog.rb b/test/plugin/test_parser_syslog.rb index b72a6b4be7..00c3d60f98 100644 --- a/test/plugin/test_parser_syslog.rb +++ b/test/plugin/test_parser_syslog.rb @@ -464,6 +464,7 @@ def test_parse_with_rfc5424_message(param) assert_equal "-", record["pid"] assert_equal "-", record["msgid"] assert_equal "-", record["extradata"] + assert_equal 16, record["pri"] assert_equal "Hi, from Fluentd!", record["message"] end assert_equal(Fluent::Plugin::SyslogParser::RFC5424_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])