Skip to content

Commit

Permalink
Fix regression in the case with_priority and rfc5424
Browse files Browse the repository at this point in the history
priority which is passed to in_syslog should be integer

Signed-off-by: Yuta Iwama <[email protected]>
  • Loading branch information
ganmacs committed Apr 1, 2020
1 parent 297696b commit f18f3a1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fluent/plugin/parser_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions test/plugin/test_in_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<parse>\n message_format rfc5424\nwith_priority true\n</parse>"].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, "<transport tcp> \n</transport>"].join("\n"))
tests = create_test_case
Expand Down
10 changes: 10 additions & 0 deletions test/plugin/test_parser_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f18f3a1

Please sign in to comment.