fluentd 1.10.3-x64-mingw32 → 1.11.3-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd might be problematic. Click here for more details.

Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +102 -0
  3. data/CONTRIBUTING.md +1 -1
  4. data/example/copy_roundrobin.conf +3 -3
  5. data/example/counter.conf +1 -1
  6. data/example/filter_stdout.conf +2 -2
  7. data/example/{in_dummy_blocks.conf → in_sample_blocks.conf} +4 -4
  8. data/example/{in_dummy_with_compression.conf → in_sample_with_compression.conf} +3 -3
  9. data/example/logevents.conf +5 -5
  10. data/example/multi_filters.conf +1 -1
  11. data/example/out_exec_filter.conf +2 -2
  12. data/example/out_forward.conf +1 -1
  13. data/example/out_forward_buf_file.conf +1 -1
  14. data/example/out_forward_client.conf +5 -5
  15. data/example/out_forward_heartbeat_none.conf +1 -1
  16. data/example/out_forward_sd.conf +1 -1
  17. data/example/out_forward_shared_key.conf +2 -2
  18. data/example/out_forward_tls.conf +1 -1
  19. data/example/out_forward_users.conf +3 -3
  20. data/example/out_null.conf +4 -4
  21. data/example/secondary_file.conf +1 -1
  22. data/fluentd.gemspec +5 -5
  23. data/lib/fluent/command/fluentd.rb +11 -0
  24. data/lib/fluent/log.rb +33 -3
  25. data/lib/fluent/match.rb +9 -0
  26. data/lib/fluent/plugin/buffer.rb +49 -40
  27. data/lib/fluent/plugin/buffer/chunk.rb +2 -1
  28. data/lib/fluent/plugin/in_dummy.rb +2 -123
  29. data/lib/fluent/plugin/in_exec.rb +4 -2
  30. data/lib/fluent/plugin/in_forward.rb +2 -2
  31. data/lib/fluent/plugin/in_gc_stat.rb +16 -0
  32. data/lib/fluent/plugin/in_http.rb +148 -77
  33. data/lib/fluent/plugin/in_monitor_agent.rb +1 -1
  34. data/lib/fluent/plugin/in_sample.rb +141 -0
  35. data/lib/fluent/plugin/in_tail.rb +2 -2
  36. data/lib/fluent/plugin/in_unix.rb +77 -77
  37. data/lib/fluent/plugin/out_file.rb +1 -1
  38. data/lib/fluent/plugin/out_forward.rb +1 -1
  39. data/lib/fluent/plugin/out_forward/load_balancer.rb +1 -1
  40. data/lib/fluent/plugin/out_http.rb +15 -2
  41. data/lib/fluent/plugin/output.rb +1 -0
  42. data/lib/fluent/plugin/parser_json.rb +5 -2
  43. data/lib/fluent/plugin/parser_syslog.rb +215 -54
  44. data/lib/fluent/plugin_helper/cert_option.rb +5 -8
  45. data/lib/fluent/plugin_helper/child_process.rb +3 -2
  46. data/lib/fluent/plugin_helper/socket.rb +1 -1
  47. data/lib/fluent/supervisor.rb +15 -6
  48. data/lib/fluent/system_config.rb +2 -1
  49. data/lib/fluent/test/filter_test.rb +2 -2
  50. data/lib/fluent/test/output_test.rb +3 -3
  51. data/lib/fluent/version.rb +1 -1
  52. data/test/plugin/out_forward/test_load_balancer.rb +46 -0
  53. data/test/plugin/test_buffer.rb +4 -0
  54. data/test/plugin/test_in_exec.rb +18 -0
  55. data/test/plugin/test_in_gc_stat.rb +24 -1
  56. data/test/plugin/test_in_http.rb +57 -0
  57. data/test/plugin/{test_in_dummy.rb → test_in_sample.rb} +25 -25
  58. data/test/plugin/test_in_tail.rb +3 -0
  59. data/test/plugin/test_in_unix.rb +128 -73
  60. data/test/plugin/test_out_http.rb +38 -0
  61. data/test/plugin/test_parser_syslog.rb +66 -29
  62. data/test/plugin_helper/data/cert/empty.pem +0 -0
  63. data/test/plugin_helper/test_cert_option.rb +7 -0
  64. data/test/plugin_helper/test_child_process.rb +15 -0
  65. data/test/plugin_helper/test_http_server_helper.rb +5 -0
  66. data/test/plugin_helper/test_server.rb +34 -0
  67. data/test/plugin_helper/test_socket.rb +8 -0
  68. data/test/test_log.rb +44 -0
  69. data/test/test_match.rb +11 -0
  70. data/test/test_static_config_analysis.rb +2 -2
  71. metadata +19 -16
@@ -1403,6 +1403,9 @@ class TailInputTest < Test::Unit::TestCase
1403
1403
  end
1404
1404
 
1405
1405
  def test_tail_path_with_multiline_with_multiple_paths
1406
+ if ENV["APPVEYOR"] && Fluent.windows?
1407
+ omit "This testcase is unstable on AppVeyor."
1408
+ end
1406
1409
  files = ["#{TMP_DIR}/tail1.txt", "#{TMP_DIR}/tail2.txt"]
1407
1410
  files.each { |file| File.open(file, "wb") { |f| } }
1408
1411
 
@@ -1,126 +1,181 @@
1
1
  require_relative '../helper'
2
- require 'fluent/test'
2
+ require 'fluent/test/driver/input'
3
3
  require 'fluent/plugin/in_unix'
4
4
 
5
- module StreamInputTest
5
+ class UnixInputTest < Test::Unit::TestCase
6
6
  def setup
7
7
  Fluent::Test.setup
8
+ @d = nil
8
9
  end
9
10
 
10
- def test_time
11
- d = create_driver
11
+ def teardown
12
+ @d.instance_shutdown if @d
13
+ end
12
14
 
13
- time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
14
- Fluent::Engine.now = time
15
+ TMP_DIR = File.dirname(__FILE__) + "/../tmp/in_unix#{ENV['TEST_ENV_NUMBER']}"
16
+ CONFIG = %[
17
+ path #{TMP_DIR}/unix
18
+ backlog 1000
19
+ ]
20
+
21
+ def create_driver(conf = CONFIG)
22
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::UnixInput).configure(conf)
23
+ end
15
24
 
16
- d.expect_emit "tag1", time, {"a"=>1}
17
- d.expect_emit "tag2", time, {"a"=>2}
25
+ def packer(*args)
26
+ Fluent::MessagePackFactory.msgpack_packer(*args)
27
+ end
18
28
 
19
- d.run do
20
- d.expected_emits.each {|tag,_time,record|
21
- send_data Fluent::MessagePackFactory.msgpack_packer.write([tag, 0, record]).to_s
29
+ def unpacker
30
+ Fluent::MessagePackFactory.msgpack_unpacker
31
+ end
32
+
33
+ def send_data(data)
34
+ io = UNIXSocket.new("#{TMP_DIR}/unix")
35
+ begin
36
+ io.write data
37
+ ensure
38
+ io.close
39
+ end
40
+ end
41
+
42
+ def test_configure
43
+ @d = create_driver
44
+ assert_equal "#{TMP_DIR}/unix", @d.instance.path
45
+ assert_equal 1000, @d.instance.backlog
46
+ end
47
+
48
+ def test_time
49
+ @d = create_driver
50
+
51
+ time = Fluent::EventTime.now
52
+ records = [
53
+ ["tag1", 0, {"a" => 1}],
54
+ ["tag2", nil, {"a" => 2}],
55
+ ]
56
+
57
+ @d.run(expect_records: records.length, timeout: 5) do
58
+ records.each {|tag, _time, record|
59
+ send_data packer.write([tag, _time, record]).to_s
22
60
  }
23
61
  end
62
+
63
+ @d.events.each_with_index { |e, i|
64
+ orig = records[i]
65
+ assert_equal(orig[0], e[0])
66
+ assert_true(time <= e[1])
67
+ assert_equal(orig[2], e[2])
68
+ }
24
69
  end
25
70
 
26
71
  def test_message
27
- d = create_driver
72
+ @d = create_driver
28
73
 
29
- time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
30
-
31
- d.expect_emit "tag1", time, {"a"=>1}
32
- d.expect_emit "tag2", time, {"a"=>2}
74
+ time = Fluent::EventTime.now
75
+ records = [
76
+ ["tag1", time, {"a" => 1}],
77
+ ["tag2", time, {"a" => 2}],
78
+ ]
33
79
 
34
- d.run do
35
- d.expected_emits.each {|tag,_time,record|
36
- send_data Fluent::MessagePackFactory.msgpack_packer.write([tag, _time, record]).to_s
80
+ @d.run(expect_records: records.length, timeout: 5) do
81
+ records.each {|tag, _time, record|
82
+ send_data packer.write([tag, _time, record]).to_s
37
83
  }
38
84
  end
85
+
86
+ assert_equal(records, @d.events)
39
87
  end
40
88
 
41
89
  def test_forward
42
- d = create_driver
90
+ @d = create_driver
43
91
 
44
92
  time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
93
+ records = [
94
+ ["tag1", time, {"a" => 1}],
95
+ ["tag1", time, {"a" => 2}]
96
+ ]
45
97
 
46
- d.expect_emit "tag1", time, {"a"=>1}
47
- d.expect_emit "tag1", time, {"a"=>2}
48
-
49
- d.run do
98
+ @d.run(expect_records: records.length, timeout: 20) do
50
99
  entries = []
51
- d.expected_emits.each {|tag,_time,record|
100
+ records.each {|tag, _time, record|
52
101
  entries << [_time, record]
53
102
  }
54
- send_data Fluent::MessagePackFactory.msgpack_packer.write(["tag1", entries]).to_s
103
+ send_data packer.write(["tag1", entries]).to_s
55
104
  end
105
+ assert_equal(records, @d.events)
56
106
  end
57
107
 
58
108
  def test_packed_forward
59
- d = create_driver
109
+ @d = create_driver
60
110
 
61
- time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
62
-
63
- d.expect_emit "tag1", time, {"a"=>1}
64
- d.expect_emit "tag1", time, {"a"=>2}
111
+ time = Fluent::EventTime.now
112
+ records = [
113
+ ["tag1", time, {"a" => 1}],
114
+ ["tag1", time, {"a" => 2}],
115
+ ]
65
116
 
66
- d.run do
117
+ @d.run(expect_records: records.length, timeout: 20) do
67
118
  entries = ''
68
- d.expected_emits.each {|tag,_time,record|
69
- Fluent::MessagePackFactory.msgpack_packer(entries).write([_time, record]).flush
119
+ records.each {|_tag, _time, record|
120
+ packer(entries).write([_time, record]).flush
70
121
  }
71
- send_data Fluent::MessagePackFactory.msgpack_packer.write(["tag1", entries]).to_s
122
+ send_data packer.write(["tag1", entries]).to_s
72
123
  end
124
+ assert_equal(records, @d.events)
73
125
  end
74
126
 
75
127
  def test_message_json
76
- d = create_driver
128
+ @d = create_driver
129
+
130
+ time = Fluent::EventTime.now
131
+ records = [
132
+ ["tag1", time, {"a" => 1}],
133
+ ["tag2", time, {"a" => 2}],
134
+ ]
135
+
136
+ @d.run(expect_records: records.length, timeout: 5) do
137
+ tag, _time, record = records[0]
138
+ send_data [tag, _time.to_i, record].to_json
139
+ tag, _time, record = records[1]
140
+ send_data [tag, _time.to_f, record].to_json
141
+ end
77
142
 
78
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
143
+ assert_equal(records, @d.events)
144
+ end
145
+
146
+ def test_message_with_tag
147
+ @d = create_driver(CONFIG + "tag new_tag")
79
148
 
80
- d.expect_emit "tag1", time, {"a"=>1}
81
- d.expect_emit "tag2", time, {"a"=>2}
149
+ time = Fluent::EventTime.now
150
+ records = [
151
+ ["tag1", time, {"a" => 1}],
152
+ ["tag2", time, {"a" => 2}],
153
+ ]
82
154
 
83
- d.run do
84
- d.expected_emits.each {|tag,_time,record|
85
- send_data [tag, time, record].to_json
155
+ @d.run(expect_records: records.length, timeout: 5) do
156
+ records.each {|tag, _time, record|
157
+ send_data packer.write([tag, _time, record]).to_s
86
158
  }
87
159
  end
88
- end
89
160
 
90
- def create_driver(klass, conf)
91
- Fluent::Test::InputTestDriver.new(klass).configure(conf)
161
+ @d.events.each { |event|
162
+ assert_equal("new_tag", event[0])
163
+ }
92
164
  end
93
165
 
94
- def send_data(data)
95
- io = connect
96
- begin
97
- io.write data
98
- ensure
99
- io.close
166
+ data('string chunk' => 'broken string',
167
+ 'integer chunk' => 10)
168
+ def test_broken_message(data)
169
+ @d = create_driver
170
+ @d.run(shutdown: false, timeout: 5) do
171
+ @d.instance.__send__(:on_message, data)
100
172
  end
101
- end
102
- end
103
-
104
- class UnixInputTest < Test::Unit::TestCase
105
- include StreamInputTest
106
-
107
- TMP_DIR = File.dirname(__FILE__) + "/../tmp/in_unix#{ENV['TEST_ENV_NUMBER']}"
108
- CONFIG = %[
109
- path #{TMP_DIR}/unix
110
- backlog 1000
111
- ]
112
173
 
113
- def create_driver(conf=CONFIG)
114
- super(Fluent::UnixInput, conf)
115
- end
116
-
117
- def test_configure
118
- d = create_driver
119
- assert_equal "#{TMP_DIR}/unix", d.instance.path
120
- assert_equal 1000, d.instance.backlog
121
- end
174
+ assert_equal 0, @d.events.size
122
175
 
123
- def connect
124
- UNIXSocket.new("#{TMP_DIR}/unix")
176
+ logs = @d.instance.log.logs
177
+ assert_equal 1, logs.select { |line|
178
+ line =~ / \[warn\]: incoming data is broken: msg=#{data.inspect}/
179
+ }.size, "should not accept broken chunk"
125
180
  end
126
181
  end unless Fluent.windows?
@@ -80,6 +80,8 @@ class HTTPOutputTest < Test::Unit::TestCase
80
80
  req.body.each_line { |l|
81
81
  data << JSON.parse(l)
82
82
  }
83
+ when 'application/json'
84
+ data = JSON.parse(req.body)
83
85
  when 'text/plain'
84
86
  # Use single_value in this test
85
87
  req.body.each_line { |line|
@@ -181,6 +183,19 @@ class HTTPOutputTest < Test::Unit::TestCase
181
183
  assert_not_match(/Status code 503 is going to be removed/, d.instance.log.out.logs.join)
182
184
  end
183
185
 
186
+ # Check if an exception is raised on not JSON format use
187
+ data('not_json' => 'msgpack')
188
+ def test_configure_with_json_array_err(format_type)
189
+ assert_raise(Fluent::ConfigError) do
190
+ create_driver(config + %[
191
+ json_array true
192
+ <format>
193
+ @type #{format_type}
194
+ </format>
195
+ ])
196
+ end
197
+ end
198
+
184
199
  data('json' => ['json', 'application/x-ndjson'],
185
200
  'ltsv' => ['ltsv', 'text/tab-separated-values'],
186
201
  'msgpack' => ['msgpack', 'application/x-msgpack'],
@@ -195,6 +210,14 @@ class HTTPOutputTest < Test::Unit::TestCase
195
210
  assert_equal content_type, d.instance.content_type
196
211
  end
197
212
 
213
+ # Check that json_array setting sets content_type = application/json
214
+ data('json' => 'application/json')
215
+ def test_configure_content_type_json_array(content_type)
216
+ d = create_driver(config + "json_array true")
217
+
218
+ assert_equal content_type, d.instance.content_type
219
+ end
220
+
198
221
  data('PUT' => 'put', 'POST' => 'post')
199
222
  def test_write_with_method(method)
200
223
  d = create_driver(config + "http_method #{method}")
@@ -211,6 +234,21 @@ class HTTPOutputTest < Test::Unit::TestCase
211
234
  assert_not_empty result.headers
212
235
  end
213
236
 
237
+ # Check that JSON at HTTP request body is valid
238
+ def test_write_with_json_array_setting
239
+ d = create_driver(config + "json_array true")
240
+ d.run(default_tag: 'test.http') do
241
+ test_events.each { |event|
242
+ d.feed(event)
243
+ }
244
+ end
245
+
246
+ result = @@result
247
+ assert_equal 'application/json', result.content_type
248
+ assert_equal test_events, result.data
249
+ assert_not_empty result.headers
250
+ end
251
+
214
252
  def test_write_with_single_value_format
215
253
  d = create_driver(config + %[
216
254
  <format>
@@ -35,8 +35,9 @@ class SyslogParserTest < ::Test::Unit::TestCase
35
35
  assert_equal('%b %d %M:%S:%H', @parser.instance.patterns['time_format'])
36
36
  end
37
37
 
38
- def test_parse_with_time_format2
39
- @parser.configure('time_format' => '%Y-%m-%dT%H:%M:%SZ')
38
+ data('regexp' => 'regexp', 'string' => 'string')
39
+ def test_parse_with_time_format2(param)
40
+ @parser.configure('time_format' => '%Y-%m-%dT%H:%M:%SZ', 'parser_type' => param)
40
41
  @parser.instance.parse('2020-03-03T10:14:29Z 192.168.0.1 fluentd[11111]: [error] Syslog test') { |time, record|
41
42
  assert_equal(event_time('Mar 03 10:14:29', format: '%b %d %H:%M:%S'), time)
42
43
  assert_equal(@expected, record)
@@ -198,11 +199,13 @@ class SyslogParserTest < ::Test::Unit::TestCase
198
199
  end
199
200
 
200
201
  class TestRFC5424Regexp < self
201
- def test_parse_with_rfc5424_message
202
+ data('regexp' => 'regexp', 'string' => 'string')
203
+ def test_parse_with_rfc5424_message(param)
202
204
  @parser.configure(
203
205
  'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
204
206
  'message_format' => 'rfc5424',
205
207
  'with_priority' => true,
208
+ 'parser_type' => param
206
209
  )
207
210
  text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
208
211
  @parser.instance.parse(text) do |time, record|
@@ -215,11 +218,13 @@ class SyslogParserTest < ::Test::Unit::TestCase
215
218
  assert_equal(Fluent::Plugin::SyslogParser::RFC5424_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
216
219
  end
217
220
 
218
- def test_parse_with_rfc5424_message_trailing_eol
221
+ data('regexp' => 'regexp', 'string' => 'string')
222
+ def test_parse_with_rfc5424_message_trailing_eol(param)
219
223
  @parser.configure(
220
224
  'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
221
225
  'message_format' => 'rfc5424',
222
226
  'with_priority' => true,
227
+ 'parser_type' => param
223
228
  )
224
229
  text = "<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!\n"
225
230
  @parser.instance.parse(text) do |time, record|
@@ -232,11 +237,13 @@ class SyslogParserTest < ::Test::Unit::TestCase
232
237
  assert_equal(Fluent::Plugin::SyslogParser::RFC5424_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
233
238
  end
234
239
 
235
- def test_parse_with_rfc5424_multiline_message
240
+ data('regexp' => 'regexp', 'string' => 'string')
241
+ def test_parse_with_rfc5424_multiline_message(param)
236
242
  @parser.configure(
237
243
  'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
238
244
  'message_format' => 'rfc5424',
239
245
  'with_priority' => true,
246
+ 'parser_type' => param
240
247
  )
241
248
  text = "<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi,\nfrom\nFluentd!"
242
249
  @parser.instance.parse(text) do |time, record|
@@ -249,10 +256,12 @@ class SyslogParserTest < ::Test::Unit::TestCase
249
256
  assert_equal(Fluent::Plugin::SyslogParser::RFC5424_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
250
257
  end
251
258
 
252
- def test_parse_with_rfc5424_message_and_without_priority
259
+ data('regexp' => 'regexp', 'string' => 'string')
260
+ def test_parse_with_rfc5424_message_and_without_priority(param)
253
261
  @parser.configure(
254
262
  'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
255
263
  'message_format' => 'rfc5424',
264
+ 'parser_type' => param
256
265
  )
257
266
  text = '2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
258
267
  @parser.instance.parse(text) do |time, record|
@@ -265,10 +274,12 @@ class SyslogParserTest < ::Test::Unit::TestCase
265
274
  assert_equal(Fluent::Plugin::SyslogParser::RFC5424_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
266
275
  end
267
276
 
268
- def test_parse_with_rfc5424_empty_message_and_without_priority
277
+ data('regexp' => 'regexp', 'string' => 'string')
278
+ def test_parse_with_rfc5424_empty_message_and_without_priority(param)
269
279
  @parser.configure(
270
280
  'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
271
281
  'message_format' => 'rfc5424',
282
+ 'parser_type' => param
272
283
  )
273
284
  text = '2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - -'
274
285
  @parser.instance.parse(text) do |time, record|
@@ -281,10 +292,12 @@ class SyslogParserTest < ::Test::Unit::TestCase
281
292
  assert_equal(Fluent::Plugin::SyslogParser::RFC5424_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
282
293
  end
283
294
 
284
- def test_parse_with_rfc5424_message_without_time_format
295
+ data('regexp' => 'regexp', 'string' => 'string')
296
+ def test_parse_with_rfc5424_message_without_time_format(param)
285
297
  @parser.configure(
286
298
  'message_format' => 'rfc5424',
287
299
  'with_priority' => true,
300
+ 'parser_type' => param
288
301
  )
289
302
  text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
290
303
  @parser.instance.parse(text) do |time, record|
@@ -296,10 +309,12 @@ class SyslogParserTest < ::Test::Unit::TestCase
296
309
  end
297
310
  end
298
311
 
299
- def test_parse_with_rfc5424_message_with_priority_and_pid
312
+ data('regexp' => 'regexp', 'string' => 'string')
313
+ def test_parse_with_rfc5424_message_with_priority_and_pid(param)
300
314
  @parser.configure(
301
315
  'message_format' => 'rfc5424',
302
316
  'with_priority' => true,
317
+ 'parser_type' => param
303
318
  )
304
319
  text = '<28>1 2018-09-26T15:54:26.620412+09:00 machine minissdpd 1298 - - peer 192.168.0.5:50123 is not from a LAN'
305
320
  @parser.instance.parse(text) do |time, record|
@@ -311,11 +326,13 @@ class SyslogParserTest < ::Test::Unit::TestCase
311
326
  end
312
327
  end
313
328
 
314
- def test_parse_with_rfc5424_structured_message
329
+ data('regexp' => 'regexp', 'string' => 'string')
330
+ def test_parse_with_rfc5424_structured_message(param)
315
331
  @parser.configure(
316
332
  'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
317
333
  'message_format' => 'rfc5424',
318
334
  'with_priority' => true,
335
+ 'parser_type' => param
319
336
  )
320
337
  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!'
321
338
  @parser.instance.parse(text) do |time, record|
@@ -328,11 +345,13 @@ class SyslogParserTest < ::Test::Unit::TestCase
328
345
  end
329
346
  end
330
347
 
331
- def test_parse_with_rfc5424_multiple_structured_message
348
+ data('regexp' => 'regexp', 'string' => 'string')
349
+ def test_parse_with_rfc5424_multiple_structured_message(param)
332
350
  @parser.configure(
333
351
  'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
334
352
  'message_format' => 'rfc5424',
335
353
  'with_priority' => true,
354
+ 'parser_type' => param
336
355
  )
337
356
  text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"][exampleSDID@20224 class="high"] Hi, from Fluentd!'
338
357
  @parser.instance.parse(text) do |time, record|
@@ -345,11 +364,13 @@ class SyslogParserTest < ::Test::Unit::TestCase
345
364
  end
346
365
  end
347
366
 
348
- def test_parse_with_rfc5424_message_includes_right_bracket
367
+ data('regexp' => 'regexp', 'string' => 'string')
368
+ def test_parse_with_rfc5424_message_includes_right_bracket(param)
349
369
  @parser.configure(
350
370
  'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
351
371
  'message_format' => 'rfc5424',
352
372
  'with_priority' => true,
373
+ 'parser_type' => param
353
374
  )
354
375
  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]!'
355
376
  @parser.instance.parse(text) do |time, record|
@@ -362,11 +383,13 @@ class SyslogParserTest < ::Test::Unit::TestCase
362
383
  end
363
384
  end
364
385
 
365
- def test_parse_with_rfc5424_empty_message
386
+ data('regexp' => 'regexp', 'string' => 'string')
387
+ def test_parse_with_rfc5424_empty_message(param)
366
388
  @parser.configure(
367
389
  'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
368
390
  'message_format' => 'rfc5424',
369
391
  'with_priority' => true,
392
+ 'parser_type' => param
370
393
  )
371
394
  text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"]'
372
395
  @parser.instance.parse(text) do |time, record|
@@ -379,10 +402,35 @@ class SyslogParserTest < ::Test::Unit::TestCase
379
402
  end
380
403
  end
381
404
 
382
- def test_parse_with_rfc5424_message_without_subseconds
405
+ data('regexp' => 'regexp', 'string' => 'string')
406
+ def test_parse_with_rfc5424_space_empty_message(param)
407
+ @parser.configure(
408
+ 'message_format' => 'rfc5424',
409
+ 'with_priority' => true,
410
+ 'parser_type' => param
411
+ )
412
+ text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"] '
413
+ @parser.instance.parse(text) do |time, record|
414
+ if param == 'string'
415
+ assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time)
416
+ assert_equal "11111", record["pid"]
417
+ assert_equal "ID24224", record["msgid"]
418
+ assert_equal "[exampleSDID@20224 iut=\"3\" eventSource=\"Application\" eventID=\"11211\"]",
419
+ record["extradata"]
420
+ assert_equal '', record["message"]
421
+ else
422
+ assert_nil time
423
+ assert_nil record
424
+ end
425
+ end
426
+ end
427
+
428
+ data('regexp' => 'regexp', 'string' => 'string')
429
+ def test_parse_with_rfc5424_message_without_subseconds(param)
383
430
  @parser.configure(
384
431
  'message_format' => 'rfc5424',
385
432
  'with_priority' => true,
433
+ 'parser_type' => param
386
434
  )
387
435
  text = '<16>1 2017-02-06T13:14:15Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
388
436
  @parser.instance.parse(text) do |time, record|
@@ -394,10 +442,12 @@ class SyslogParserTest < ::Test::Unit::TestCase
394
442
  end
395
443
  end
396
444
 
397
- def test_parse_with_rfc5424_message_both_timestamp
445
+ data('regexp' => 'regexp', 'string' => 'string')
446
+ def test_parse_with_rfc5424_message_both_timestamp(param)
398
447
  @parser.configure(
399
448
  'message_format' => 'rfc5424',
400
449
  'with_priority' => true,
450
+ 'parser_type' => param
401
451
  )
402
452
  text = '<16>1 2017-02-06T13:14:15Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
403
453
  @parser.instance.parse(text) do |time, record|
@@ -431,7 +481,6 @@ class SyslogParserTest < ::Test::Unit::TestCase
431
481
  assert_equal(event_time("Feb 28 00:00:12", format: '%b %d %M:%S:%H'), time)
432
482
  assert_equal(@expected, record)
433
483
  end
434
- assert_equal(Fluent::Plugin::SyslogParser::RFC3164_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
435
484
  end
436
485
 
437
486
  data('regexp' => 'regexp', 'string' => 'string')
@@ -447,7 +496,6 @@ class SyslogParserTest < ::Test::Unit::TestCase
447
496
  assert_equal(event_time("Feb 28 12:00:00", format: '%b %d %M:%S:%H'), time)
448
497
  assert_equal(@expected.merge('pri' => 6), record)
449
498
  end
450
- assert_equal(Fluent::Plugin::SyslogParser::RFC3164_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
451
499
  end
452
500
 
453
501
  data('regexp' => 'regexp', 'string' => 'string')
@@ -467,7 +515,6 @@ class SyslogParserTest < ::Test::Unit::TestCase
467
515
  assert_equal 16, record["pri"]
468
516
  assert_equal "Hi, from Fluentd!", record["message"]
469
517
  end
470
- assert_equal(Fluent::Plugin::SyslogParser::RFC5424_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
471
518
  end
472
519
 
473
520
  data('regexp' => 'regexp', 'string' => 'string')
@@ -487,7 +534,7 @@ class SyslogParserTest < ::Test::Unit::TestCase
487
534
  record["extradata"]
488
535
  assert_equal "Hi, from Fluentd!", record["message"]
489
536
  end
490
- assert_equal(Fluent::Plugin::SyslogParser::RFC5424_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])end
537
+ end
491
538
 
492
539
  data('regexp' => 'regexp', 'string' => 'string')
493
540
  def test_parse_with_both_message_type(param)
@@ -503,7 +550,6 @@ class SyslogParserTest < ::Test::Unit::TestCase
503
550
  assert_equal(event_time("Feb 28 12:00:00", format: '%b %d %M:%S:%H'), time)
504
551
  assert_equal(@expected.merge('pri' => 1), record)
505
552
  end
506
- assert_equal(Fluent::Plugin::SyslogParser::RFC3164_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
507
553
 
508
554
  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!'
509
555
  @parser.instance.parse(text) do |time, record|
@@ -514,21 +560,18 @@ class SyslogParserTest < ::Test::Unit::TestCase
514
560
  record["extradata"]
515
561
  assert_equal "Hi, from Fluentd!", record["message"]
516
562
  end
517
- assert_equal(Fluent::Plugin::SyslogParser::RFC5424_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
518
563
 
519
564
  text = '<1>Feb 28 12:00:02 192.168.0.1 fluentd[11111]: [error] Syslog test 2>1'
520
565
  @parser.instance.parse(text) do |time, record|
521
566
  assert_equal(event_time("Feb 28 12:00:02", format: '%b %d %M:%S:%H'), time)
522
567
  assert_equal(@expected.merge('pri' => 1, 'message'=> '[error] Syslog test 2>1'), record)
523
568
  end
524
- assert_equal(Fluent::Plugin::SyslogParser::RFC3164_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
525
569
 
526
570
  text = '<1>Feb 28 12:00:02 192.168.0.1 fluentd[11111]: [error] Syslog test'
527
571
  @parser.instance.parse(text) do |time, record|
528
572
  assert_equal(event_time("Feb 28 12:00:02", format: '%b %d %M:%S:%H'), time)
529
573
  assert_equal(@expected.merge('pri' => 1), record)
530
574
  end
531
- assert_equal(Fluent::Plugin::SyslogParser::RFC3164_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
532
575
 
533
576
  text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
534
577
  @parser.instance.parse(text) do |time, record|
@@ -538,7 +581,6 @@ class SyslogParserTest < ::Test::Unit::TestCase
538
581
  assert_equal "-", record["extradata"]
539
582
  assert_equal "Hi, from Fluentd!", record["message"]
540
583
  end
541
- assert_equal(Fluent::Plugin::SyslogParser::RFC5424_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
542
584
  end
543
585
 
544
586
  data('regexp' => 'regexp', 'string' => 'string')
@@ -555,7 +597,6 @@ class SyslogParserTest < ::Test::Unit::TestCase
555
597
  assert_equal(event_time("Feb 28 12:00:00", format: '%b %d %M:%S:%H'), time)
556
598
  assert_equal(@expected.merge('pri' => 6), record)
557
599
  end
558
- assert_equal(Fluent::Plugin::SyslogParser::RFC3164_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
559
600
 
560
601
  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!'
561
602
  @parser.instance.parse(text) do |time, record|
@@ -566,14 +607,12 @@ class SyslogParserTest < ::Test::Unit::TestCase
566
607
  record["extradata"]
567
608
  assert_equal "Hi, from Fluentd!", record["message"]
568
609
  end
569
- assert_equal(Fluent::Plugin::SyslogParser::RFC5424_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
570
610
 
571
611
  text = '<16>Feb 28 12:00:02 192.168.0.1 fluentd[11111]: [error] Syslog test'
572
612
  @parser.instance.parse(text) do |time, record|
573
613
  assert_equal(event_time("Feb 28 12:00:02", format: '%b %d %M:%S:%H'), time)
574
614
  assert_equal(@expected.merge('pri' => 16), record)
575
615
  end
576
- assert_equal(Fluent::Plugin::SyslogParser::RFC3164_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
577
616
 
578
617
  text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
579
618
  @parser.instance.parse(text) do |time, record|
@@ -583,7 +622,6 @@ class SyslogParserTest < ::Test::Unit::TestCase
583
622
  assert_equal "-", record["extradata"]
584
623
  assert_equal "Hi, from Fluentd!", record["message"]
585
624
  end
586
- assert_equal(Fluent::Plugin::SyslogParser::RFC5424_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
587
625
 
588
626
  text = '<16>1 2017-02-06T13:14:15Z 192.168.0.1 fluentd - - - Hi, from Fluentd without subseconds!'
589
627
  @parser.instance.parse(text) do |time, record|
@@ -593,7 +631,6 @@ class SyslogParserTest < ::Test::Unit::TestCase
593
631
  assert_equal "-", record["extradata"]
594
632
  assert_equal "Hi, from Fluentd without subseconds!", record["message"]
595
633
  end
596
- assert_equal(Fluent::Plugin::SyslogParser::RFC5424_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
597
634
  end
598
635
  end
599
636
  end