@@ -364,6 +364,168 @@ def test_parse_with_keep_time_key
364
364
assert_equal "Feb 28 00:00:12" , record [ 'time' ]
365
365
end
366
366
end
367
+
368
+ class TestRFC5424Regexp < self
369
+ def test_parse_with_rfc5424_message
370
+ @parser . configure (
371
+ 'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z' ,
372
+ 'message_format' => 'rfc5424' ,
373
+ )
374
+ text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
375
+ @parser . parse ( text ) do |time , record |
376
+ assert_equal ( event_time ( "2017-02-06T13:14:15.003Z" , format : '%Y-%m-%dT%H:%M:%S.%L%z' ) , time )
377
+ assert_equal "-" , record [ "pid" ]
378
+ assert_equal "-" , record [ "msgid" ]
379
+ assert_equal "-" , record [ "extradata" ]
380
+ assert_equal "Hi, from Fluentd!" , record [ "message" ]
381
+ end
382
+ end
383
+
384
+ def test_parse_with_rfc5424_structured_message
385
+ @parser . configure (
386
+ 'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z' ,
387
+ 'message_format' => 'rfc5424' ,
388
+ )
389
+ 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!'
390
+ @parser . parse ( text ) do |time , record |
391
+ assert_equal ( event_time ( "2017-02-06T13:14:15.003Z" , format : '%Y-%m-%dT%H:%M:%S.%L%z' ) , time )
392
+ assert_equal "11111" , record [ "pid" ]
393
+ assert_equal "ID24224" , record [ "msgid" ]
394
+ assert_equal "[exampleSDID@20224 iut=\" 3\" eventSource=\" Application\" eventID=\" 11211\" ]" ,
395
+ record [ "extradata" ]
396
+ assert_equal "Hi, from Fluentd!" , record [ "message" ]
397
+ end
398
+ end
399
+ end
400
+
401
+ class TestAutoRegexp < self
402
+ def test_auto_with_legacy_syslog_message
403
+ @parser . configure (
404
+ 'time_format' => '%b %d %M:%S:%H' ,
405
+ 'mseeage_format' => 'auto' ,
406
+ )
407
+ text = 'Feb 28 00:00:12 192.168.0.1 fluentd[11111]: [error] Syslog test'
408
+ @parser . parse ( text ) do |time , record |
409
+ assert_equal ( event_time ( "Feb 28 00:00:12" , format : '%b %d %M:%S:%H' ) , time )
410
+ assert_equal ( @expected , record )
411
+ end
412
+ end
413
+
414
+ def test_auto_with_legacy_syslog_priority_message
415
+ @parser . configure (
416
+ 'time_format' => '%b %d %M:%S:%H' ,
417
+ 'with_priority' => true ,
418
+ 'mseeage_format' => 'auto' ,
419
+ )
420
+ text = '<6>Feb 28 12:00:00 192.168.0.1 fluentd[11111]: [error] Syslog test'
421
+ @parser . parse ( text ) do |time , record |
422
+ assert_equal ( event_time ( "Feb 28 12:00:00" , format : '%b %d %M:%S:%H' ) , time )
423
+ assert_equal ( @expected . merge ( 'pri' => 6 ) , record )
424
+ end
425
+ end
426
+
427
+ def test_parse_with_rfc5424_message
428
+ @parser . configure (
429
+ 'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z' ,
430
+ 'message_format' => 'auto' ,
431
+ )
432
+ text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
433
+ @parser . parse ( text ) do |time , record |
434
+ assert_equal ( event_time ( "2017-02-06T13:14:15.003Z" , format : '%Y-%m-%dT%H:%M:%S.%L%z' ) , time )
435
+ assert_equal "-" , record [ "pid" ]
436
+ assert_equal "-" , record [ "msgid" ]
437
+ assert_equal "-" , record [ "extradata" ]
438
+ assert_equal "Hi, from Fluentd!" , record [ "message" ]
439
+ end
440
+ end
441
+
442
+ def test_parse_with_rfc5424_structured_message
443
+ @parser . configure (
444
+ 'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z' ,
445
+ 'message_format' => 'auto' ,
446
+ )
447
+ 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!'
448
+ @parser . parse ( text ) do |time , record |
449
+ assert_equal ( event_time ( "2017-02-06T13:14:15.003Z" , format : '%Y-%m-%dT%H:%M:%S.%L%z' ) , time )
450
+ assert_equal "11111" , record [ "pid" ]
451
+ assert_equal "ID24224" , record [ "msgid" ]
452
+ assert_equal "[exampleSDID@20224 iut=\" 3\" eventSource=\" Application\" eventID=\" 11211\" ]" ,
453
+ record [ "extradata" ]
454
+ assert_equal "Hi, from Fluentd!" , record [ "message" ]
455
+ end
456
+ end
457
+
458
+ def test_parse_with_both_message_type
459
+ @parser . configure (
460
+ 'time_format' => '%b %d %M:%S:%H' ,
461
+ 'rfc5424_time_format' => '%Y-%m-%dT%H:%M:%S.%L%z' ,
462
+ 'message_format' => 'auto' ,
463
+ )
464
+ text = 'Feb 28 12:00:00 192.168.0.1 fluentd[11111]: [error] Syslog test'
465
+ @parser . parse ( text ) do |time , record |
466
+ assert_equal ( event_time ( "Feb 28 12:00:00" , format : '%b %d %M:%S:%H' ) , time )
467
+ assert_equal ( @expected , record )
468
+ end
469
+ 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!'
470
+ @parser . parse ( text ) do |time , record |
471
+ assert_equal ( event_time ( "2017-02-06T13:14:15.003Z" , format : '%Y-%m-%dT%H:%M:%S.%L%z' ) , time )
472
+ assert_equal "11111" , record [ "pid" ]
473
+ assert_equal "ID24224" , record [ "msgid" ]
474
+ assert_equal "[exampleSDID@20224 iut=\" 3\" eventSource=\" Application\" eventID=\" 11211\" ]" ,
475
+ record [ "extradata" ]
476
+ assert_equal "Hi, from Fluentd!" , record [ "message" ]
477
+ end
478
+ text = 'Feb 28 12:00:02 192.168.0.1 fluentd[11111]: [error] Syslog test'
479
+ @parser . parse ( text ) do |time , record |
480
+ assert_equal ( event_time ( "Feb 28 12:00:02" , format : '%b %d %M:%S:%H' ) , time )
481
+ assert_equal ( @expected , record )
482
+ end
483
+ text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
484
+ @parser . parse ( text ) do |time , record |
485
+ assert_equal ( event_time ( "2017-02-06T13:14:15.003Z" , format : '%Y-%m-%dT%H:%M:%S.%L%z' ) , time )
486
+ assert_equal "-" , record [ "pid" ]
487
+ assert_equal "-" , record [ "msgid" ]
488
+ assert_equal "-" , record [ "extradata" ]
489
+ assert_equal "Hi, from Fluentd!" , record [ "message" ]
490
+ end
491
+ end
492
+
493
+ def test_parse_with_both_message_type_and_priority
494
+ @parser . configure (
495
+ 'time_format' => '%b %d %M:%S:%H' ,
496
+ 'rfc5424_time_format' => '%Y-%m-%dT%H:%M:%S.%L%z' ,
497
+ 'with_priority' => true ,
498
+ 'message_format' => 'auto' ,
499
+ )
500
+ text = '<6>Feb 28 12:00:00 192.168.0.1 fluentd[11111]: [error] Syslog test'
501
+ @parser . parse ( text ) do |time , record |
502
+ assert_equal ( event_time ( "Feb 28 12:00:00" , format : '%b %d %M:%S:%H' ) , time )
503
+ assert_equal ( @expected . merge ( 'pri' => 6 ) , record )
504
+ end
505
+ 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!'
506
+ @parser . parse ( text ) do |time , record |
507
+ assert_equal ( event_time ( "2017-02-06T13:14:15.003Z" , format : '%Y-%m-%dT%H:%M:%S.%L%z' ) , time )
508
+ assert_equal "11111" , record [ "pid" ]
509
+ assert_equal "ID24224" , record [ "msgid" ]
510
+ assert_equal "[exampleSDID@20224 iut=\" 3\" eventSource=\" Application\" eventID=\" 11211\" ]" ,
511
+ record [ "extradata" ]
512
+ assert_equal "Hi, from Fluentd!" , record [ "message" ]
513
+ end
514
+ text = '<16>Feb 28 12:00:02 192.168.0.1 fluentd[11111]: [error] Syslog test'
515
+ @parser . parse ( text ) do |time , record |
516
+ assert_equal ( event_time ( "Feb 28 12:00:02" , format : '%b %d %M:%S:%H' ) , time )
517
+ assert_equal ( @expected . merge ( 'pri' => 16 ) , record )
518
+ end
519
+ text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
520
+ @parser . parse ( text ) do |time , record |
521
+ assert_equal ( event_time ( "2017-02-06T13:14:15.003Z" , format : '%Y-%m-%dT%H:%M:%S.%L%z' ) , time )
522
+ assert_equal "-" , record [ "pid" ]
523
+ assert_equal "-" , record [ "msgid" ]
524
+ assert_equal "-" , record [ "extradata" ]
525
+ assert_equal "Hi, from Fluentd!" , record [ "message" ]
526
+ end
527
+ end
528
+ end
367
529
end
368
530
369
531
class JsonParserTest < ::Test ::Unit ::TestCase
0 commit comments