fluentd 0.12.40 → 0.14.0
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.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +6 -0
- data/.gitignore +2 -0
- data/.travis.yml +33 -21
- data/CONTRIBUTING.md +1 -0
- data/ChangeLog +810 -237
- data/README.md +0 -25
- data/Rakefile +2 -1
- data/Vagrantfile +17 -0
- data/appveyor.yml +35 -0
- data/example/filter_stdout.conf +5 -5
- data/example/in_forward.conf +2 -2
- data/example/in_http.conf +2 -2
- data/example/in_out_forward.conf +17 -0
- data/example/in_syslog.conf +2 -2
- data/example/in_tail.conf +2 -2
- data/example/in_tcp.conf +2 -2
- data/example/in_udp.conf +2 -2
- data/example/out_copy.conf +4 -4
- data/example/out_file.conf +2 -2
- data/example/out_forward.conf +2 -2
- data/example/out_forward_buf_file.conf +23 -0
- data/example/v0_12_filter.conf +8 -8
- data/fluent.conf +29 -0
- data/fluentd.gemspec +18 -11
- data/lib/fluent/agent.rb +60 -58
- data/lib/fluent/command/cat.rb +1 -1
- data/lib/fluent/command/debug.rb +7 -5
- data/lib/fluent/command/fluentd.rb +97 -2
- data/lib/fluent/compat/call_super_mixin.rb +67 -0
- data/lib/fluent/compat/filter.rb +50 -0
- data/lib/fluent/compat/formatter.rb +109 -0
- data/lib/fluent/compat/input.rb +50 -0
- data/lib/fluent/compat/output.rb +617 -0
- data/lib/fluent/compat/output_chain.rb +60 -0
- data/lib/fluent/compat/parser.rb +163 -0
- data/lib/fluent/compat/propagate_default.rb +62 -0
- data/lib/fluent/config.rb +23 -20
- data/lib/fluent/config/configure_proxy.rb +119 -70
- data/lib/fluent/config/dsl.rb +5 -18
- data/lib/fluent/config/element.rb +72 -8
- data/lib/fluent/config/error.rb +0 -3
- data/lib/fluent/config/literal_parser.rb +0 -2
- data/lib/fluent/config/parser.rb +4 -4
- data/lib/fluent/config/section.rb +39 -28
- data/lib/fluent/config/types.rb +2 -13
- data/lib/fluent/config/v1_parser.rb +1 -3
- data/lib/fluent/configurable.rb +48 -16
- data/lib/fluent/daemon.rb +15 -0
- data/lib/fluent/engine.rb +26 -52
- data/lib/fluent/env.rb +6 -4
- data/lib/fluent/event.rb +58 -11
- data/lib/fluent/event_router.rb +5 -5
- data/lib/fluent/filter.rb +2 -50
- data/lib/fluent/formatter.rb +4 -293
- data/lib/fluent/input.rb +2 -32
- data/lib/fluent/label.rb +2 -2
- data/lib/fluent/load.rb +3 -2
- data/lib/fluent/log.rb +107 -38
- data/lib/fluent/match.rb +0 -36
- data/lib/fluent/mixin.rb +117 -7
- data/lib/fluent/msgpack_factory.rb +62 -0
- data/lib/fluent/output.rb +7 -612
- data/lib/fluent/output_chain.rb +23 -0
- data/lib/fluent/parser.rb +4 -800
- data/lib/fluent/plugin.rb +100 -121
- data/lib/fluent/plugin/bare_output.rb +63 -0
- data/lib/fluent/plugin/base.rb +121 -0
- data/lib/fluent/plugin/buf_file.rb +101 -182
- data/lib/fluent/plugin/buf_memory.rb +9 -92
- data/lib/fluent/plugin/buffer.rb +473 -0
- data/lib/fluent/plugin/buffer/chunk.rb +135 -0
- data/lib/fluent/plugin/buffer/file_chunk.rb +339 -0
- data/lib/fluent/plugin/buffer/memory_chunk.rb +100 -0
- data/lib/fluent/plugin/exec_util.rb +80 -75
- data/lib/fluent/plugin/file_util.rb +33 -28
- data/lib/fluent/plugin/file_wrapper.rb +120 -0
- data/lib/fluent/plugin/filter.rb +51 -0
- data/lib/fluent/plugin/filter_grep.rb +13 -40
- data/lib/fluent/plugin/filter_record_transformer.rb +22 -18
- data/lib/fluent/plugin/formatter.rb +93 -0
- data/lib/fluent/plugin/formatter_csv.rb +48 -0
- data/lib/fluent/plugin/formatter_hash.rb +32 -0
- data/lib/fluent/plugin/formatter_json.rb +47 -0
- data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
- data/lib/fluent/plugin/formatter_msgpack.rb +32 -0
- data/lib/fluent/plugin/formatter_out_file.rb +45 -0
- data/lib/fluent/plugin/formatter_single_value.rb +34 -0
- data/lib/fluent/plugin/formatter_stdout.rb +39 -0
- data/lib/fluent/plugin/in_debug_agent.rb +4 -0
- data/lib/fluent/plugin/in_dummy.rb +22 -18
- data/lib/fluent/plugin/in_exec.rb +18 -8
- data/lib/fluent/plugin/in_forward.rb +36 -79
- data/lib/fluent/plugin/in_gc_stat.rb +4 -0
- data/lib/fluent/plugin/in_http.rb +21 -18
- data/lib/fluent/plugin/in_monitor_agent.rb +15 -48
- data/lib/fluent/plugin/in_object_space.rb +6 -1
- data/lib/fluent/plugin/in_stream.rb +7 -3
- data/lib/fluent/plugin/in_syslog.rb +46 -95
- data/lib/fluent/plugin/in_tail.rb +51 -595
- data/lib/fluent/plugin/in_tcp.rb +8 -1
- data/lib/fluent/plugin/in_udp.rb +8 -14
- data/lib/fluent/plugin/input.rb +33 -0
- data/lib/fluent/plugin/multi_output.rb +95 -0
- data/lib/fluent/plugin/out_buffered_null.rb +59 -0
- data/lib/fluent/plugin/out_copy.rb +11 -7
- data/lib/fluent/plugin/out_exec.rb +15 -11
- data/lib/fluent/plugin/out_exec_filter.rb +18 -10
- data/lib/fluent/plugin/out_file.rb +34 -5
- data/lib/fluent/plugin/out_forward.rb +19 -9
- data/lib/fluent/plugin/out_null.rb +0 -14
- data/lib/fluent/plugin/out_roundrobin.rb +11 -7
- data/lib/fluent/plugin/out_stdout.rb +5 -7
- data/lib/fluent/plugin/out_stream.rb +3 -1
- data/lib/fluent/plugin/output.rb +979 -0
- data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
- data/lib/fluent/plugin/parser.rb +244 -0
- data/lib/fluent/plugin/parser_apache.rb +24 -0
- data/lib/fluent/plugin/parser_apache2.rb +84 -0
- data/lib/fluent/plugin/parser_apache_error.rb +21 -0
- data/lib/fluent/plugin/parser_csv.rb +31 -0
- data/lib/fluent/plugin/parser_json.rb +79 -0
- data/lib/fluent/plugin/parser_ltsv.rb +50 -0
- data/lib/fluent/plugin/parser_multiline.rb +102 -0
- data/lib/fluent/plugin/parser_nginx.rb +24 -0
- data/lib/fluent/plugin/parser_none.rb +36 -0
- data/lib/fluent/plugin/parser_syslog.rb +82 -0
- data/lib/fluent/plugin/parser_tsv.rb +37 -0
- data/lib/fluent/plugin/socket_util.rb +120 -114
- data/lib/fluent/plugin/storage.rb +84 -0
- data/lib/fluent/plugin/storage_local.rb +116 -0
- data/lib/fluent/plugin/string_util.rb +16 -13
- data/lib/fluent/plugin_helper.rb +39 -0
- data/lib/fluent/plugin_helper/child_process.rb +298 -0
- data/lib/fluent/plugin_helper/compat_parameters.rb +99 -0
- data/lib/fluent/plugin_helper/event_emitter.rb +80 -0
- data/lib/fluent/plugin_helper/event_loop.rb +118 -0
- data/lib/fluent/plugin_helper/retry_state.rb +177 -0
- data/lib/fluent/plugin_helper/storage.rb +308 -0
- data/lib/fluent/plugin_helper/thread.rb +147 -0
- data/lib/fluent/plugin_helper/timer.rb +85 -0
- data/lib/fluent/plugin_id.rb +63 -0
- data/lib/fluent/process.rb +21 -30
- data/lib/fluent/registry.rb +21 -9
- data/lib/fluent/root_agent.rb +115 -40
- data/lib/fluent/supervisor.rb +330 -320
- data/lib/fluent/system_config.rb +42 -18
- data/lib/fluent/test.rb +6 -1
- data/lib/fluent/test/base.rb +23 -3
- data/lib/fluent/test/driver/base.rb +247 -0
- data/lib/fluent/test/driver/event_feeder.rb +98 -0
- data/lib/fluent/test/driver/filter.rb +35 -0
- data/lib/fluent/test/driver/input.rb +31 -0
- data/lib/fluent/test/driver/output.rb +78 -0
- data/lib/fluent/test/driver/test_event_router.rb +45 -0
- data/lib/fluent/test/filter_test.rb +0 -1
- data/lib/fluent/test/formatter_test.rb +2 -1
- data/lib/fluent/test/input_test.rb +23 -17
- data/lib/fluent/test/output_test.rb +28 -39
- data/lib/fluent/test/parser_test.rb +1 -1
- data/lib/fluent/time.rb +104 -1
- data/lib/fluent/{status.rb → unique_id.rb} +15 -24
- data/lib/fluent/version.rb +1 -1
- data/lib/fluent/winsvc.rb +72 -0
- data/test/compat/test_calls_super.rb +164 -0
- data/test/config/test_config_parser.rb +83 -0
- data/test/config/test_configurable.rb +547 -274
- data/test/config/test_configure_proxy.rb +146 -29
- data/test/config/test_dsl.rb +3 -181
- data/test/config/test_element.rb +274 -0
- data/test/config/test_literal_parser.rb +1 -1
- data/test/config/test_section.rb +79 -7
- data/test/config/test_system_config.rb +21 -0
- data/test/config/test_types.rb +3 -26
- data/test/helper.rb +78 -8
- data/test/plugin/test_bare_output.rb +118 -0
- data/test/plugin/test_base.rb +75 -0
- data/test/plugin/test_buf_file.rb +420 -521
- data/test/plugin/test_buf_memory.rb +32 -194
- data/test/plugin/test_buffer.rb +981 -0
- data/test/plugin/test_buffer_chunk.rb +110 -0
- data/test/plugin/test_buffer_file_chunk.rb +770 -0
- data/test/plugin/test_buffer_memory_chunk.rb +265 -0
- data/test/plugin/test_filter.rb +255 -0
- data/test/plugin/test_filter_grep.rb +2 -73
- data/test/plugin/test_filter_record_transformer.rb +24 -68
- data/test/plugin/test_filter_stdout.rb +6 -6
- data/test/plugin/test_in_debug_agent.rb +2 -0
- data/test/plugin/test_in_dummy.rb +11 -17
- data/test/plugin/test_in_exec.rb +6 -25
- data/test/plugin/test_in_forward.rb +112 -151
- data/test/plugin/test_in_gc_stat.rb +2 -0
- data/test/plugin/test_in_http.rb +106 -157
- data/test/plugin/test_in_object_space.rb +21 -5
- data/test/plugin/test_in_stream.rb +14 -13
- data/test/plugin/test_in_syslog.rb +30 -275
- data/test/plugin/test_in_tail.rb +95 -234
- data/test/plugin/test_in_tcp.rb +14 -0
- data/test/plugin/test_in_udp.rb +21 -13
- data/test/plugin/test_input.rb +122 -0
- data/test/plugin/test_multi_output.rb +180 -0
- data/test/plugin/test_out_buffered_null.rb +79 -0
- data/test/plugin/test_out_copy.rb +15 -2
- data/test/plugin/test_out_exec.rb +75 -25
- data/test/plugin/test_out_exec_filter.rb +74 -8
- data/test/plugin/test_out_file.rb +61 -7
- data/test/plugin/test_out_forward.rb +92 -15
- data/test/plugin/test_out_roundrobin.rb +1 -0
- data/test/plugin/test_out_stdout.rb +22 -13
- data/test/plugin/test_out_stream.rb +18 -0
- data/test/plugin/test_output.rb +515 -0
- data/test/plugin/test_output_as_buffered.rb +1540 -0
- data/test/plugin/test_output_as_buffered_overflow.rb +247 -0
- data/test/plugin/test_output_as_buffered_retries.rb +808 -0
- data/test/plugin/test_output_as_buffered_secondary.rb +776 -0
- data/test/plugin/test_output_as_standard.rb +362 -0
- data/test/plugin/test_owned_by.rb +35 -0
- data/test/plugin/test_storage.rb +167 -0
- data/test/plugin/test_storage_local.rb +8 -0
- data/test/plugin_helper/test_child_process.rb +599 -0
- data/test/plugin_helper/test_compat_parameters.rb +175 -0
- data/test/plugin_helper/test_event_emitter.rb +51 -0
- data/test/plugin_helper/test_event_loop.rb +52 -0
- data/test/plugin_helper/test_retry_state.rb +399 -0
- data/test/plugin_helper/test_storage.rb +411 -0
- data/test/plugin_helper/test_thread.rb +164 -0
- data/test/plugin_helper/test_timer.rb +100 -0
- data/test/scripts/exec_script.rb +0 -6
- data/test/scripts/fluent/plugin/out_test.rb +3 -0
- data/test/test_config.rb +13 -4
- data/test/test_event.rb +24 -13
- data/test/test_event_router.rb +8 -7
- data/test/test_event_time.rb +187 -0
- data/test/test_formatter.rb +13 -51
- data/test/test_input.rb +1 -1
- data/test/test_log.rb +239 -16
- data/test/test_mixin.rb +1 -1
- data/test/test_output.rb +53 -66
- data/test/test_parser.rb +105 -323
- data/test/test_plugin_helper.rb +81 -0
- data/test/test_root_agent.rb +4 -52
- data/test/test_supervisor.rb +272 -0
- data/test/test_unique_id.rb +47 -0
- metadata +180 -54
- data/lib/fluent/buffer.rb +0 -365
- data/lib/fluent/plugin/filter_parser.rb +0 -107
- data/lib/fluent/plugin/in_status.rb +0 -76
- data/lib/fluent/test/helpers.rb +0 -86
- data/test/plugin/data/log/foo/bar2 +0 -0
- data/test/plugin/test_filter_parser.rb +0 -744
- data/test/plugin/test_in_status.rb +0 -38
- data/test/test_buffer.rb +0 -624
@@ -1,7 +1,21 @@
|
|
1
1
|
require_relative '../helper'
|
2
2
|
require 'fluent/test'
|
3
|
+
require 'fluent/plugin/in_object_space'
|
4
|
+
|
5
|
+
require 'timeout'
|
3
6
|
|
4
7
|
class ObjectSpaceInputTest < Test::Unit::TestCase
|
8
|
+
def waiting(seconds, instance)
|
9
|
+
begin
|
10
|
+
Timeout.timeout(seconds) do
|
11
|
+
yield
|
12
|
+
end
|
13
|
+
rescue Timeout::Error
|
14
|
+
STDERR.print(*instance.log.out.logs)
|
15
|
+
raise
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
5
19
|
class FailObject
|
6
20
|
def self.class
|
7
21
|
raise "error"
|
@@ -32,17 +46,19 @@ class ObjectSpaceInputTest < Test::Unit::TestCase
|
|
32
46
|
def test_emit
|
33
47
|
d = create_driver
|
34
48
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
49
|
+
d.run do
|
50
|
+
waiting(10, d.instance) do
|
51
|
+
sleep 0.5 until d.emit_streams.size > 3
|
52
|
+
end
|
53
|
+
end
|
39
54
|
|
40
55
|
emits = d.emits
|
41
|
-
|
56
|
+
assert{ emits.length > 0 }
|
42
57
|
|
43
58
|
emits.each { |tag, time, record|
|
44
59
|
assert_equal d.instance.tag, tag
|
45
60
|
assert_equal d.instance.top, record.keys.size
|
61
|
+
assert(time.is_a?(Fluent::EventTime))
|
46
62
|
}
|
47
63
|
end
|
48
64
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative '../helper'
|
2
2
|
require 'fluent/test'
|
3
|
+
require 'fluent/plugin/in_stream'
|
3
4
|
|
4
5
|
module StreamInputTest
|
5
6
|
def setup
|
@@ -9,14 +10,14 @@ module StreamInputTest
|
|
9
10
|
def test_time
|
10
11
|
d = create_driver
|
11
12
|
|
12
|
-
time =
|
13
|
+
time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
|
13
14
|
Fluent::Engine.now = time
|
14
15
|
|
15
16
|
d.expect_emit "tag1", time, {"a"=>1}
|
16
17
|
d.expect_emit "tag2", time, {"a"=>2}
|
17
18
|
|
18
19
|
d.run do
|
19
|
-
d.expected_emits.each {|tag,
|
20
|
+
d.expected_emits.each {|tag,_time,record|
|
20
21
|
send_data Fluent::Engine.msgpack_factory.packer.write([tag, 0, record]).to_s
|
21
22
|
}
|
22
23
|
end
|
@@ -25,14 +26,14 @@ module StreamInputTest
|
|
25
26
|
def test_message
|
26
27
|
d = create_driver
|
27
28
|
|
28
|
-
time =
|
29
|
+
time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
|
29
30
|
|
30
31
|
d.expect_emit "tag1", time, {"a"=>1}
|
31
32
|
d.expect_emit "tag2", time, {"a"=>2}
|
32
33
|
|
33
34
|
d.run do
|
34
|
-
d.expected_emits.each {|tag,
|
35
|
-
send_data Fluent::Engine.msgpack_factory.packer.write([tag,
|
35
|
+
d.expected_emits.each {|tag,_time,record|
|
36
|
+
send_data Fluent::Engine.msgpack_factory.packer.write([tag, _time, record]).to_s
|
36
37
|
}
|
37
38
|
end
|
38
39
|
end
|
@@ -40,15 +41,15 @@ module StreamInputTest
|
|
40
41
|
def test_forward
|
41
42
|
d = create_driver
|
42
43
|
|
43
|
-
time =
|
44
|
+
time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
|
44
45
|
|
45
46
|
d.expect_emit "tag1", time, {"a"=>1}
|
46
47
|
d.expect_emit "tag1", time, {"a"=>2}
|
47
48
|
|
48
49
|
d.run do
|
49
50
|
entries = []
|
50
|
-
d.expected_emits.each {|tag,
|
51
|
-
entries << [
|
51
|
+
d.expected_emits.each {|tag,_time,record|
|
52
|
+
entries << [_time, record]
|
52
53
|
}
|
53
54
|
send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s
|
54
55
|
end
|
@@ -57,15 +58,15 @@ module StreamInputTest
|
|
57
58
|
def test_packed_forward
|
58
59
|
d = create_driver
|
59
60
|
|
60
|
-
time =
|
61
|
+
time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
|
61
62
|
|
62
63
|
d.expect_emit "tag1", time, {"a"=>1}
|
63
64
|
d.expect_emit "tag1", time, {"a"=>2}
|
64
65
|
|
65
66
|
d.run do
|
66
67
|
entries = ''
|
67
|
-
d.expected_emits.each {|tag,
|
68
|
-
Fluent::Engine.msgpack_factory.packer(entries).write([
|
68
|
+
d.expected_emits.each {|tag,_time,record|
|
69
|
+
Fluent::Engine.msgpack_factory.packer(entries).write([_time, record]).flush
|
69
70
|
}
|
70
71
|
send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s
|
71
72
|
end
|
@@ -80,7 +81,7 @@ module StreamInputTest
|
|
80
81
|
d.expect_emit "tag2", time, {"a"=>2}
|
81
82
|
|
82
83
|
d.run do
|
83
|
-
d.expected_emits.each {|tag,
|
84
|
+
d.expected_emits.each {|tag,_time,record|
|
84
85
|
send_data [tag, time, record].to_json
|
85
86
|
}
|
86
87
|
end
|
@@ -122,4 +123,4 @@ class UnixInputTest < Test::Unit::TestCase
|
|
122
123
|
def connect
|
123
124
|
UNIXSocket.new("#{TMP_DIR}/unix")
|
124
125
|
end
|
125
|
-
end
|
126
|
+
end unless Fluent.windows?
|
@@ -1,7 +1,20 @@
|
|
1
1
|
require_relative '../helper'
|
2
2
|
require 'fluent/test'
|
3
|
+
require 'fluent/plugin/in_syslog'
|
3
4
|
|
4
5
|
class SyslogInputTest < Test::Unit::TestCase
|
6
|
+
class << self
|
7
|
+
def startup
|
8
|
+
socket_manager_path = ServerEngine::SocketManager::Server.generate_path
|
9
|
+
@server = ServerEngine::SocketManager::Server.open(socket_manager_path)
|
10
|
+
ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = socket_manager_path.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
def shutdown
|
14
|
+
@server.close
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
5
18
|
def setup
|
6
19
|
Fluent::Test.setup
|
7
20
|
require 'fluent/plugin/socket_util'
|
@@ -35,74 +48,6 @@ class SyslogInputTest < Test::Unit::TestCase
|
|
35
48
|
}
|
36
49
|
end
|
37
50
|
|
38
|
-
sub_test_case 'source_hostname_key and source_address_key features' do
|
39
|
-
test 'resolve_hostname must be true with source_hostname_key' do
|
40
|
-
assert_raise(Fluent::ConfigError) {
|
41
|
-
create_driver(CONFIG + <<EOS)
|
42
|
-
resolve_hostname false
|
43
|
-
source_hostname_key hostname
|
44
|
-
EOS
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
|
-
LOCALHOST_HOSTNAME_GETTER = ->(){sock = UDPSocket.new(::Socket::AF_INET); sock.do_not_reverse_lookup = false; sock.connect("127.0.0.1", 2048); sock.peeraddr[2] }
|
49
|
-
LOCALHOST_HOSTNAME = LOCALHOST_HOSTNAME_GETTER.call
|
50
|
-
DUMMY_SOCK = Struct.new(:remote_host, :remote_addr, :remote_port).new(LOCALHOST_HOSTNAME, "127.0.0.1", 0)
|
51
|
-
data(
|
52
|
-
both: [:hostname, :address],
|
53
|
-
hostname: [:hostname],
|
54
|
-
address: [:address],
|
55
|
-
)
|
56
|
-
test 'source_hostname_key and source_address_key parameter feature should add record(s)' do |keys|
|
57
|
-
conf = CONFIG.dup
|
58
|
-
if keys.include?(:hostname)
|
59
|
-
conf << <<EOL
|
60
|
-
source_hostname_key source_hostname
|
61
|
-
EOL
|
62
|
-
end
|
63
|
-
if keys.include?(:address)
|
64
|
-
conf << <<EOL
|
65
|
-
source_address_key source_address
|
66
|
-
EOL
|
67
|
-
end
|
68
|
-
tests = create_test_case
|
69
|
-
d = create_driver(conf)
|
70
|
-
|
71
|
-
d.run do
|
72
|
-
u = UDPSocket.new
|
73
|
-
u.connect('127.0.0.1', PORT)
|
74
|
-
tests.each {|test|
|
75
|
-
u.send(test['msg'], 0)
|
76
|
-
}
|
77
|
-
sleep 1
|
78
|
-
end
|
79
|
-
|
80
|
-
d.emits.each { |tag, _time, record|
|
81
|
-
if keys.include?(:hostname)
|
82
|
-
assert_true record.has_key?('source_hostname')
|
83
|
-
assert_equal DUMMY_SOCK.remote_host, record['source_hostname']
|
84
|
-
unless keys.include?(:address)
|
85
|
-
assert_false record.has_key?('source_address')
|
86
|
-
end
|
87
|
-
end
|
88
|
-
if keys.include?(:address)
|
89
|
-
assert_true record.has_key?('source_address')
|
90
|
-
assert_equal DUMMY_SOCK.remote_addr, record['source_address']
|
91
|
-
unless keys.include?(:hostname)
|
92
|
-
assert_false record.has_key?('source_hostname')
|
93
|
-
end
|
94
|
-
end
|
95
|
-
}
|
96
|
-
end
|
97
|
-
|
98
|
-
data('resolve_hostname' => 'resolve_hostname true',
|
99
|
-
'source_hostname_key' => 'source_hostname_key source_host')
|
100
|
-
def test_configure_reslove_hostname(param)
|
101
|
-
d = create_driver([CONFIG, param].join("\n"))
|
102
|
-
assert_true d.instance.resolve_hostname
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
51
|
def test_time_format
|
107
52
|
configs = {'127.0.0.1' => CONFIG}
|
108
53
|
configs.merge!('::1' => IPv6_CONFIG) if ipv6_enabled?
|
@@ -111,8 +56,8 @@ EOL
|
|
111
56
|
d = create_driver(v)
|
112
57
|
|
113
58
|
tests = [
|
114
|
-
{'msg' => '<6>
|
115
|
-
{'msg' => '<6>
|
59
|
+
{'msg' => '<6>Dec 11 00:00:00 localhost logger: foo', 'expected' => Fluent::EventTime.from_time(Time.strptime('Dec 11 00:00:00', '%b %d %H:%M:%S'))},
|
60
|
+
{'msg' => '<6>Dec 1 00:00:00 localhost logger: foo', 'expected' => Fluent::EventTime.from_time(Time.strptime('Dec 1 00:00:00', '%b %d %H:%M:%S'))},
|
116
61
|
]
|
117
62
|
|
118
63
|
d.run do
|
@@ -125,9 +70,8 @@ EOL
|
|
125
70
|
end
|
126
71
|
|
127
72
|
emits = d.emits
|
128
|
-
assert_equal 2, emits.size
|
129
73
|
emits.each_index {|i|
|
130
|
-
|
74
|
+
assert_equal_event_time(tests[i]['expected'], emits[i][1])
|
131
75
|
}
|
132
76
|
}
|
133
77
|
end
|
@@ -145,26 +89,6 @@ EOL
|
|
145
89
|
sleep 1
|
146
90
|
end
|
147
91
|
|
148
|
-
assert_equal 2, d.emits.size
|
149
|
-
compare_test_result(d.emits, tests)
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_msg_size_udp_for_large_msg
|
153
|
-
d = create_driver(CONFIG + %[
|
154
|
-
message_length_limit 5k
|
155
|
-
])
|
156
|
-
tests = create_test_case(true)
|
157
|
-
|
158
|
-
d.run do
|
159
|
-
u = UDPSocket.new
|
160
|
-
u.connect('127.0.0.1', PORT)
|
161
|
-
tests.each {|test|
|
162
|
-
u.send(test['msg'], 0)
|
163
|
-
}
|
164
|
-
sleep 1
|
165
|
-
end
|
166
|
-
|
167
|
-
assert_equal 3, d.emits.size
|
168
92
|
compare_test_result(d.emits, tests)
|
169
93
|
end
|
170
94
|
|
@@ -181,7 +105,6 @@ EOL
|
|
181
105
|
sleep 1
|
182
106
|
end
|
183
107
|
|
184
|
-
assert_equal 2, d.emits.size
|
185
108
|
compare_test_result(d.emits, tests)
|
186
109
|
end
|
187
110
|
|
@@ -198,7 +121,6 @@ EOL
|
|
198
121
|
sleep 1
|
199
122
|
end
|
200
123
|
|
201
|
-
assert_equal 2, d.emits.size
|
202
124
|
compare_test_result(d.emits, tests)
|
203
125
|
end
|
204
126
|
|
@@ -219,207 +141,40 @@ EOL
|
|
219
141
|
sleep 1
|
220
142
|
end
|
221
143
|
|
222
|
-
assert_equal 2, d.emits.size
|
223
144
|
compare_test_result(d.emits, tests)
|
224
145
|
end
|
225
146
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
data('old parameter' => 'include_source_host',
|
230
|
-
'new parameter' => 'source_hostname_key source_host')
|
231
|
-
def test_msg_size_with_include_source_host(param)
|
232
|
-
d = create_driver([CONFIG, param].join("\n"))
|
233
|
-
tests = create_test_case
|
234
|
-
|
235
|
-
d.run do
|
236
|
-
u = UDPSocket.new
|
237
|
-
u.connect('127.0.0.1', PORT)
|
238
|
-
tests.each {|test|
|
239
|
-
u.send(test['msg'], 0)
|
240
|
-
}
|
241
|
-
sleep 1
|
242
|
-
end
|
243
|
-
|
244
|
-
assert_equal 2, d.emits.size
|
245
|
-
compare_test_result(d.emits, tests, {host: LOCALHOST_HOSTNAME})
|
246
|
-
end
|
247
|
-
|
248
|
-
def test_msg_size_with_include_priority
|
249
|
-
d = create_driver([CONFIG, 'priority_key priority'].join("\n"))
|
147
|
+
def test_msg_size_with_include_source_host
|
148
|
+
d = create_driver([CONFIG, 'include_source_host'].join("\n"))
|
250
149
|
tests = create_test_case
|
251
150
|
|
252
|
-
|
151
|
+
host = nil
|
253
152
|
d.run do
|
254
153
|
u = UDPSocket.new
|
255
154
|
u.connect('127.0.0.1', PORT)
|
155
|
+
host = u.peeraddr[2]
|
256
156
|
tests.each {|test|
|
257
157
|
u.send(test['msg'], 0)
|
258
158
|
}
|
259
159
|
sleep 1
|
260
160
|
end
|
261
161
|
|
262
|
-
|
263
|
-
compare_test_result(d.emits, tests, {priority: priority})
|
162
|
+
compare_test_result(d.emits, tests, host)
|
264
163
|
end
|
265
164
|
|
266
|
-
def
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
facility = 'kern'
|
271
|
-
d.run do
|
272
|
-
u = UDPSocket.new
|
273
|
-
u.connect('127.0.0.1', PORT)
|
274
|
-
tests.each {|test|
|
275
|
-
u.send(test['msg'], 0)
|
276
|
-
}
|
277
|
-
sleep 1
|
278
|
-
end
|
279
|
-
|
280
|
-
assert_equal 2, d.emits.size
|
281
|
-
compare_test_result(d.emits, tests, {facility: facility})
|
282
|
-
end
|
283
|
-
|
284
|
-
def test_allow_without_priority_with_default_format
|
285
|
-
d = create_driver([CONFIG, 'allow_without_priority true'].join("\n"))
|
286
|
-
|
287
|
-
tests = [
|
288
|
-
{'msg' => '<6>Sep 10 00:00:00 localhost logger: ' + 'x' * 100 + "\n", 'expected' => 'x' * 100},
|
289
|
-
{'msg' => 'Sep 10 00:00:00 localhost logger: ' + 'x' * 1024 + "\n", 'expected' => 'x' * 1024, 'tag' => 'syslog.user.notice'},
|
290
|
-
]
|
291
|
-
|
292
|
-
d.run do
|
293
|
-
u = UDPSocket.new
|
294
|
-
u.connect('127.0.0.1', PORT)
|
295
|
-
tests.each {|test|
|
296
|
-
u.send(test['msg'], 0)
|
297
|
-
}
|
298
|
-
sleep 1
|
299
|
-
end
|
300
|
-
|
301
|
-
assert_equal 2, d.emits.size
|
302
|
-
compare_test_result(d.emits, tests)
|
303
|
-
end
|
304
|
-
|
305
|
-
def test_allow_without_priority_with_json_format
|
306
|
-
d = create_driver([CONFIG, %[
|
307
|
-
allow_without_priority true
|
308
|
-
format json
|
309
|
-
]].join("\n"))
|
310
|
-
|
311
|
-
message = 'foo'
|
312
|
-
tests = [
|
313
|
-
{'msg' => '<6>' + {'message' => message}.to_json + "\n", 'expected' => message},
|
314
|
-
{'msg' => {'message' => message}.to_json + "\n", 'expected' => message, 'tag' => 'syslog.user.notice'},
|
315
|
-
]
|
316
|
-
|
317
|
-
d.run do
|
318
|
-
u = UDPSocket.new
|
319
|
-
u.connect('127.0.0.1', PORT)
|
320
|
-
tests.each {|test|
|
321
|
-
u.send(test['msg'], 0)
|
322
|
-
}
|
323
|
-
sleep 1
|
324
|
-
end
|
325
|
-
|
326
|
-
assert_equal 2, d.emits.size
|
327
|
-
compare_test_result(d.emits, tests)
|
328
|
-
end
|
329
|
-
|
330
|
-
def test_default_priority
|
331
|
-
d = create_driver([CONFIG, %[
|
332
|
-
allow_without_priority true
|
333
|
-
default_priority 100
|
334
|
-
]].join("\n"))
|
335
|
-
|
336
|
-
tests = [
|
165
|
+
def create_test_case
|
166
|
+
# actual syslog message has "\n"
|
167
|
+
[
|
337
168
|
{'msg' => '<6>Sep 10 00:00:00 localhost logger: ' + 'x' * 100 + "\n", 'expected' => 'x' * 100},
|
338
|
-
{'msg' => 'Sep 10 00:00:00 localhost logger: ' + 'x' * 1024 + "\n", 'expected' => 'x' * 1024
|
169
|
+
{'msg' => '<6>Sep 10 00:00:00 localhost logger: ' + 'x' * 1024 + "\n", 'expected' => 'x' * 1024},
|
339
170
|
]
|
340
|
-
|
341
|
-
d.run do
|
342
|
-
u = UDPSocket.new
|
343
|
-
u.connect('127.0.0.1', PORT)
|
344
|
-
tests.each {|test|
|
345
|
-
u.send(test['msg'], 0)
|
346
|
-
}
|
347
|
-
sleep 1
|
348
|
-
end
|
349
|
-
|
350
|
-
assert_equal 2, d.emits.size
|
351
|
-
compare_test_result(d.emits, tests)
|
352
|
-
|
353
171
|
end
|
354
172
|
|
355
|
-
def
|
356
|
-
|
357
|
-
|
358
|
-
[
|
359
|
-
|
360
|
-
{'msg' => '<6>Sep 10 00:00:00 localhost logger: ' + 'x' * 1024 + "\n", 'expected' => 'x' * 1024},
|
361
|
-
{'msg' => '<6>Sep 10 00:00:00 localhost logger: ' + 'x' * 4096 + "\n", 'expected' => 'x' * 4096},
|
362
|
-
]
|
363
|
-
else
|
364
|
-
[
|
365
|
-
{'msg' => '<6>Sep 10 00:00:00 localhost logger: ' + 'x' * 100 + "\n", 'expected' => 'x' * 100},
|
366
|
-
{'msg' => '<6>Sep 10 00:00:00 localhost logger: ' + 'x' * 1024 + "\n", 'expected' => 'x' * 1024},
|
367
|
-
]
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
def compare_test_result(events, tests, options = {})
|
372
|
-
events.each_index { |i|
|
373
|
-
assert_equal((tests[i]['tag'] || 'syslog.kern.info'), events[i][0]) # <6> means kern.info
|
374
|
-
assert_equal(tests[i]['expected'], events[i][2]['message'])
|
375
|
-
assert_equal(options[:host], events[i][2]['source_host']) if options[:host]
|
376
|
-
assert_equal(options[:priority], events[i][2]['priority']) if options[:priority]
|
377
|
-
assert_equal(options[:facility], events[i][2]['facility']) if options[:facility]
|
173
|
+
def compare_test_result(emits, tests, host = nil)
|
174
|
+
emits.each_index { |i|
|
175
|
+
assert_equal('syslog.kern.info', emits[0][0]) # <6> means kern.info
|
176
|
+
assert_equal(tests[i]['expected'], emits[i][2]['message'])
|
177
|
+
assert_equal(host, emits[i][2]['source_host']) if host
|
378
178
|
}
|
379
179
|
end
|
380
|
-
|
381
|
-
class SyslogMessageFormatTest < self
|
382
|
-
def test_syslog_rfc5424_format
|
383
|
-
d = create_driver(CONFIG + 'message_format rfc5424')
|
384
|
-
tests = [
|
385
|
-
'<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!',
|
386
|
-
'<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!'
|
387
|
-
]
|
388
|
-
|
389
|
-
run_tests(d, tests)
|
390
|
-
compare_test_result(d)
|
391
|
-
end
|
392
|
-
|
393
|
-
def test_syslog_auto_format
|
394
|
-
d = create_driver(CONFIG + 'message_format auto')
|
395
|
-
tests = [
|
396
|
-
'<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!',
|
397
|
-
'<6>Sep 11 00:00:00 localhost fluentd: Hi, from Fluentd!'
|
398
|
-
]
|
399
|
-
|
400
|
-
run_tests(d, tests)
|
401
|
-
compare_test_result(d)
|
402
|
-
end
|
403
|
-
|
404
|
-
def run_tests(d, tests)
|
405
|
-
d.run do
|
406
|
-
u = Fluent::SocketUtil.create_udp_socket('127.0.0.1')
|
407
|
-
u.connect('127.0.0.1', PORT)
|
408
|
-
tests.each {|test|
|
409
|
-
u.send(test, 0)
|
410
|
-
}
|
411
|
-
sleep 1
|
412
|
-
end
|
413
|
-
end
|
414
|
-
|
415
|
-
def compare_test_result(d)
|
416
|
-
emits = d.emits
|
417
|
-
assert_equal 2, emits.size
|
418
|
-
emits.each_index {|i|
|
419
|
-
record = emits[i][2]
|
420
|
-
assert_equal('fluentd', record['ident'])
|
421
|
-
assert_equal('Hi, from Fluentd!', record['message'])
|
422
|
-
}
|
423
|
-
end
|
424
|
-
end
|
425
180
|
end
|