Skip to content

Commit

Permalink
Follow w/o priority behavior change for rfc5424
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmo0920 committed Jun 21, 2017
1 parent 8b5e91f commit 3464eba
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions test/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ def test_parse_with_rfc5424_message
@parser.configure(
'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
'message_format' => 'rfc5424',
'with_priority' => true,
)
text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
@parser.parse(text) do |time, record|
Expand All @@ -388,6 +389,9 @@ def test_parse_with_rfc5424_message
assert_equal "-", record["extradata"]
assert_equal "Hi, from Fluentd!", record["message"]
end
assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI,
@parser.instance.patterns['format'])

end

def test_parse_with_rfc5424_message_and_without_priority
Expand All @@ -410,6 +414,7 @@ def test_parse_with_rfc5424_message_and_without_priority
def test_parse_with_rfc5424_message_without_time_format
@parser.configure(
'message_format' => 'rfc5424',
'with_priority' => true,
)
text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
@parser.instance.parse(text) do |time, record|
Expand All @@ -425,6 +430,7 @@ def test_parse_with_rfc5424_structured_message
@parser.configure(
'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
'message_format' => 'rfc5424',
'with_priority' => true,
)
text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"] Hi, from Fluentd!'
@parser.parse(text) do |time, record|
Expand Down Expand Up @@ -462,12 +468,15 @@ def test_auto_with_legacy_syslog_priority_message
assert_equal(event_time("Feb 28 12:00:00", format: '%b %d %M:%S:%H'), time)
assert_equal(@expected.merge('pri' => 6), record)
end
assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI,
@parser.instance.patterns['format'])
end

def test_parse_with_rfc5424_message
@parser.configure(
'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
'message_format' => 'auto',
'with_priority' => true,
)
text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
@parser.parse(text) do |time, record|
Expand All @@ -477,12 +486,15 @@ def test_parse_with_rfc5424_message
assert_equal "-", record["extradata"]
assert_equal "Hi, from Fluentd!", record["message"]
end
assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI,
@parser.instance.patterns['format'])
end

def test_parse_with_rfc5424_structured_message
@parser.configure(
'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
'message_format' => 'auto',
'with_priority' => true,
)
text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"] Hi, from Fluentd!'
@parser.parse(text) do |time, record|
Expand All @@ -493,19 +505,25 @@ def test_parse_with_rfc5424_structured_message
record["extradata"]
assert_equal "Hi, from Fluentd!", record["message"]
end
assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI,
@parser.instance.patterns['format'])
end

def test_parse_with_both_message_type
@parser.configure(
'time_format' => '%b %d %M:%S:%H',
'rfc5424_time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
'message_format' => 'auto',
'with_priority' => true,
)
text = 'Feb 28 12:00:00 192.168.0.1 fluentd[11111]: [error] Syslog test'
text = '<1>Feb 28 12:00:00 192.168.0.1 fluentd[11111]: [error] Syslog test'
@parser.parse(text) do |time, record|
assert_equal(event_time("Feb 28 12:00:00", format: '%b %d %M:%S:%H'), time)
assert_equal(@expected, record)
assert_equal(@expected.merge('pri' => 1), record)
end
assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI,
@parser.instance.patterns['format'])

text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"] Hi, from Fluentd!'
@parser.parse(text) do |time, record|
assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time)
Expand All @@ -515,11 +533,17 @@ def test_parse_with_both_message_type
record["extradata"]
assert_equal "Hi, from Fluentd!", record["message"]
end
text = 'Feb 28 12:00:02 192.168.0.1 fluentd[11111]: [error] Syslog test'
assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI,
@parser.instance.patterns['format'])

text = '<1>Feb 28 12:00:02 192.168.0.1 fluentd[11111]: [error] Syslog test'
@parser.parse(text) do |time, record|
assert_equal(event_time("Feb 28 12:00:02", format: '%b %d %M:%S:%H'), time)
assert_equal(@expected, record)
assert_equal(@expected.merge('pri' => 1), record)
end
assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI,
@parser.instance.patterns['format'])

text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
@parser.parse(text) do |time, record|
assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time)
Expand All @@ -528,6 +552,9 @@ def test_parse_with_both_message_type
assert_equal "-", record["extradata"]
assert_equal "Hi, from Fluentd!", record["message"]
end
assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI,
@parser.instance.patterns['format'])

end

def test_parse_with_both_message_type_and_priority
Expand All @@ -542,6 +569,9 @@ def test_parse_with_both_message_type_and_priority
assert_equal(event_time("Feb 28 12:00:00", format: '%b %d %M:%S:%H'), time)
assert_equal(@expected.merge('pri' => 6), record)
end
assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI,
@parser.instance.patterns['format'])

text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"] Hi, from Fluentd!'
@parser.parse(text) do |time, record|
assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time)
Expand All @@ -551,11 +581,17 @@ def test_parse_with_both_message_type_and_priority
record["extradata"]
assert_equal "Hi, from Fluentd!", record["message"]
end
assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI,
@parser.instance.patterns['format'])

text = '<16>Feb 28 12:00:02 192.168.0.1 fluentd[11111]: [error] Syslog test'
@parser.parse(text) do |time, record|
assert_equal(event_time("Feb 28 12:00:02", format: '%b %d %M:%S:%H'), time)
assert_equal(@expected.merge('pri' => 16), record)
end
assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI,
@parser.instance.patterns['format'])

text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
@parser.parse(text) do |time, record|
assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time)
Expand All @@ -564,6 +600,9 @@ def test_parse_with_both_message_type_and_priority
assert_equal "-", record["extradata"]
assert_equal "Hi, from Fluentd!", record["message"]
end
assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI,
@parser.instance.patterns['format'])

end
end
end
Expand Down

0 comments on commit 3464eba

Please sign in to comment.