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..00c3d60f98 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)
@@ -454,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'])