Skip to content
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
9 changes: 9 additions & 0 deletions lib/fluent/plugin/in_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SyslogInput < Input

DEFAULT_PARSER = 'syslog'
SYSLOG_REGEXP = /\A\<([0-9]+)\>(.*)/
PRI_RANGE = 0..191

FACILITY_MAP = {
0 => 'kern',
Expand Down Expand Up @@ -322,6 +323,14 @@ def message_handler(data, sock)
end

pri ||= record.delete('pri')
# RFC 5424 limits PRI to 0..191. A larger value has no facility.
unless PRI_RANGE.cover?(pri)
if @emit_unmatched_lines
emit_unmatched(data, sock)
end
log.warn "invalid syslog priority", data: data
return
end
facility = FACILITY_MAP[pri >> 3]
severity = SEVERITY_MAP[pri & 0b111]

Expand Down
24 changes: 22 additions & 2 deletions test/plugin/test_in_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ def test_space_after_input_owned_priority_preserves_input_priority_syntax(parser
].join("\n"))

messages = [
'<1234>Apr 25 16:43:29 host app: message',
'<1234> Apr 25 16:43:29 host app: message',
'<0134>Apr 25 16:43:29 host app: message',
'<0134> Apr 25 16:43:29 host app: message',
'<ab> Apr 25 16:43:29 host app: message',
]
d.run(expect_emits: 3) do
Expand Down Expand Up @@ -218,6 +218,26 @@ def test_priority_on_a_later_line_is_unmatched_when_input_parses_priority
assert_equal(message, d.events[0][2]['unmatched_line'])
end

data('with_priority' => [],
'without_priority' => ['<parse>', ' @type syslog', ' with_priority false', '</parse>'])
def test_priority_out_of_range_is_unmatched(parse_conf)
d = create_driver(([ipv4_config, 'emit_unmatched_lines true'] + parse_conf).join("\n"))

messages = [
'<192>Apr 25 16:43:29 host app: msg',
'<1234>Apr 25 16:43:29 host app: msg',
'<191>Apr 25 16:43:29 host app: msg',
]
d.run(expect_emits: 3) do
u = UDPSocket.new
u.connect('127.0.0.1', @port)
messages.each { |message| u.send(message, 0) }
end

assert_equal(['syslog.unmatched', 'syslog.unmatched', 'syslog.local7.debug'], d.events.map { |tag, _time, _record| tag })
assert_equal(messages[0, 2], d.events[0, 2].map { |_tag, _time, record| record['unmatched_line'] })
end

def test_msg_size
d = create_driver
tests = create_test_case
Expand Down
Loading