Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression in the case with_priority and rfc5424 #2923

Merged
merged 2 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 11 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 Expand Up @@ -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'])
Expand Down