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

in_syslog: Replace priority_key with proper severity_key #2636

Merged
merged 1 commit into from
Sep 30, 2019
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
16 changes: 10 additions & 6 deletions lib/fluent/plugin/in_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SyslogInput < Input
23 => 'local7'
}

PRIORITY_MAP = {
SEVERITY_MAP = {
0 => 'emerg',
1 => 'alert',
2 => 'crit',
Expand Down Expand Up @@ -91,8 +91,8 @@ class SyslogInput < Input
config_param :resolve_hostname, :bool, default: nil
desc 'The field name of source address of sender.'
config_param :source_address_key, :string, default: nil
desc 'The field name of the priority.'
config_param :priority_key, :string, default: nil
desc 'The field name of the severity.'
config_param :severity_key, :string, default: nil, alias: :priority_key
desc 'The field name of the facility.'
config_param :facility_key, :string, default: nil

Expand All @@ -119,6 +119,10 @@ def configure(conf)

super

if conf.has_key?('priority_key')
log.warn "priority_key is deprecated. Use severity_key instead"
end

@use_default = false

@parser = parser_create
Expand Down Expand Up @@ -233,14 +237,14 @@ def message_handler(data, sock)

pri ||= record.delete('pri')
facility = FACILITY_MAP[pri >> 3]
priority = PRIORITY_MAP[pri & 0b111]
severity = SEVERITY_MAP[pri & 0b111]

record[@priority_key] = priority if @priority_key
record[@severity_key] = severity if @severity_key
record[@facility_key] = facility if @facility_key
record[@source_address_key] = sock.remote_addr if @source_address_key
record[@source_hostname_key] = sock.remote_host if @source_hostname_key

tag = "#{@tag}.#{facility}.#{priority}"
tag = "#{@tag}.#{facility}.#{severity}"
emit(tag, time, record)
end
rescue => e
Expand Down
14 changes: 9 additions & 5 deletions test/plugin/test_in_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,15 @@ def test_msg_size_with_include_source_host
compare_test_result(d.events, tests, {host: host})
end

def test_msg_size_with_priority_key
d = create_driver([CONFIG, 'priority_key priority'].join("\n"))
data(
severity_key: 'severity_key',
priority_key: 'priority_key',
)
def test_msg_size_with_severity_key(param_name)
d = create_driver([CONFIG, "#{param_name} severity"].join("\n"))
tests = create_test_case

priority = 'info'
severity = 'info'
d.run(expect_emits: 2) do
u = UDPSocket.new
u.connect('127.0.0.1', PORT)
Expand All @@ -231,7 +235,7 @@ def test_msg_size_with_priority_key
end

assert(d.events.size > 0)
compare_test_result(d.events, tests, {priority: priority})
compare_test_result(d.events, tests, {severity: severity})
end

def test_msg_size_with_facility_key
Expand Down Expand Up @@ -311,7 +315,7 @@ def compare_test_result(events, tests, options = {})
assert_equal(options[:host], events[i][2]['source_host']) if options[:host]
assert_equal(options[:address], events[i][2]['source_address']) if options[:address]
assert_equal(options[:hostname], events[i][2]['source_hostname']) if options[:hostname]
assert_equal(options[:priority], events[i][2]['priority']) if options[:priority]
assert_equal(options[:severity], events[i][2]['severity']) if options[:severity]
assert_equal(options[:facility], events[i][2]['facility']) if options[:facility]
}
end
Expand Down