fluentd-hubspot 0.14.14.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.github/ISSUE_TEMPLATE.md +6 -0
- data/.gitignore +28 -0
- data/.travis.yml +51 -0
- data/AUTHORS +2 -0
- data/CONTRIBUTING.md +42 -0
- data/COPYING +14 -0
- data/ChangeLog +593 -0
- data/Gemfile +9 -0
- data/README.md +76 -0
- data/Rakefile +74 -0
- data/Vagrantfile +17 -0
- data/appveyor.yml +43 -0
- data/bin/fluent-binlog-reader +7 -0
- data/bin/fluent-debug +5 -0
- data/bin/fluent-plugin-config-format +5 -0
- data/bin/fluent-plugin-generate +5 -0
- data/code-of-conduct.md +3 -0
- data/example/copy_roundrobin.conf +39 -0
- data/example/filter_stdout.conf +22 -0
- data/example/in_dummy_blocks.conf +17 -0
- data/example/in_dummy_with_compression.conf +23 -0
- data/example/in_forward.conf +14 -0
- data/example/in_forward_client.conf +37 -0
- data/example/in_forward_shared_key.conf +15 -0
- data/example/in_forward_tls.conf +14 -0
- data/example/in_forward_users.conf +24 -0
- data/example/in_forward_workers.conf +21 -0
- data/example/in_http.conf +14 -0
- data/example/in_out_forward.conf +17 -0
- data/example/in_syslog.conf +15 -0
- data/example/in_tail.conf +14 -0
- data/example/in_tcp.conf +13 -0
- data/example/in_udp.conf +13 -0
- data/example/logevents.conf +25 -0
- data/example/multi_filters.conf +61 -0
- data/example/out_copy.conf +20 -0
- data/example/out_exec_filter.conf +42 -0
- data/example/out_file.conf +13 -0
- data/example/out_forward.conf +35 -0
- data/example/out_forward_buf_file.conf +23 -0
- data/example/out_forward_client.conf +109 -0
- data/example/out_forward_heartbeat_none.conf +16 -0
- data/example/out_forward_shared_key.conf +36 -0
- data/example/out_forward_tls.conf +18 -0
- data/example/out_forward_users.conf +65 -0
- data/example/out_null.conf +36 -0
- data/example/secondary_file.conf +41 -0
- data/example/suppress_config_dump.conf +7 -0
- data/example/v0_12_filter.conf +78 -0
- data/example/v1_literal_example.conf +36 -0
- data/fluent.conf +139 -0
- data/fluentd.gemspec +51 -0
- data/lib/fluent/agent.rb +163 -0
- data/lib/fluent/clock.rb +62 -0
- data/lib/fluent/command/binlog_reader.rb +234 -0
- data/lib/fluent/command/bundler_injection.rb +45 -0
- data/lib/fluent/command/cat.rb +330 -0
- data/lib/fluent/command/debug.rb +102 -0
- data/lib/fluent/command/fluentd.rb +301 -0
- data/lib/fluent/command/plugin_config_formatter.rb +258 -0
- data/lib/fluent/command/plugin_generator.rb +301 -0
- data/lib/fluent/compat/call_super_mixin.rb +67 -0
- data/lib/fluent/compat/detach_process_mixin.rb +25 -0
- data/lib/fluent/compat/exec_util.rb +129 -0
- data/lib/fluent/compat/file_util.rb +54 -0
- data/lib/fluent/compat/filter.rb +68 -0
- data/lib/fluent/compat/formatter.rb +111 -0
- data/lib/fluent/compat/formatter_utils.rb +85 -0
- data/lib/fluent/compat/handle_tag_and_time_mixin.rb +62 -0
- data/lib/fluent/compat/handle_tag_name_mixin.rb +53 -0
- data/lib/fluent/compat/input.rb +59 -0
- data/lib/fluent/compat/output.rb +728 -0
- data/lib/fluent/compat/output_chain.rb +60 -0
- data/lib/fluent/compat/parser.rb +310 -0
- data/lib/fluent/compat/parser_utils.rb +40 -0
- data/lib/fluent/compat/propagate_default.rb +62 -0
- data/lib/fluent/compat/record_filter_mixin.rb +34 -0
- data/lib/fluent/compat/set_tag_key_mixin.rb +50 -0
- data/lib/fluent/compat/set_time_key_mixin.rb +69 -0
- data/lib/fluent/compat/socket_util.rb +165 -0
- data/lib/fluent/compat/string_util.rb +34 -0
- data/lib/fluent/compat/structured_format_mixin.rb +26 -0
- data/lib/fluent/compat/type_converter.rb +90 -0
- data/lib/fluent/config.rb +56 -0
- data/lib/fluent/config/basic_parser.rb +123 -0
- data/lib/fluent/config/configure_proxy.rb +418 -0
- data/lib/fluent/config/dsl.rb +149 -0
- data/lib/fluent/config/element.rb +218 -0
- data/lib/fluent/config/error.rb +26 -0
- data/lib/fluent/config/literal_parser.rb +251 -0
- data/lib/fluent/config/parser.rb +107 -0
- data/lib/fluent/config/section.rb +223 -0
- data/lib/fluent/config/types.rb +136 -0
- data/lib/fluent/config/v1_parser.rb +190 -0
- data/lib/fluent/configurable.rb +200 -0
- data/lib/fluent/daemon.rb +15 -0
- data/lib/fluent/engine.rb +266 -0
- data/lib/fluent/env.rb +28 -0
- data/lib/fluent/error.rb +30 -0
- data/lib/fluent/event.rb +334 -0
- data/lib/fluent/event_router.rb +269 -0
- data/lib/fluent/filter.rb +21 -0
- data/lib/fluent/formatter.rb +23 -0
- data/lib/fluent/input.rb +21 -0
- data/lib/fluent/label.rb +46 -0
- data/lib/fluent/load.rb +35 -0
- data/lib/fluent/log.rb +546 -0
- data/lib/fluent/match.rb +178 -0
- data/lib/fluent/mixin.rb +31 -0
- data/lib/fluent/msgpack_factory.rb +62 -0
- data/lib/fluent/output.rb +29 -0
- data/lib/fluent/output_chain.rb +23 -0
- data/lib/fluent/parser.rb +23 -0
- data/lib/fluent/plugin.rb +183 -0
- data/lib/fluent/plugin/bare_output.rb +63 -0
- data/lib/fluent/plugin/base.rb +165 -0
- data/lib/fluent/plugin/buf_file.rb +184 -0
- data/lib/fluent/plugin/buf_memory.rb +34 -0
- data/lib/fluent/plugin/buffer.rb +617 -0
- data/lib/fluent/plugin/buffer/chunk.rb +221 -0
- data/lib/fluent/plugin/buffer/file_chunk.rb +364 -0
- data/lib/fluent/plugin/buffer/memory_chunk.rb +90 -0
- data/lib/fluent/plugin/compressable.rb +92 -0
- data/lib/fluent/plugin/exec_util.rb +22 -0
- data/lib/fluent/plugin/file_util.rb +22 -0
- data/lib/fluent/plugin/file_wrapper.rb +120 -0
- data/lib/fluent/plugin/filter.rb +93 -0
- data/lib/fluent/plugin/filter_grep.rb +75 -0
- data/lib/fluent/plugin/filter_parser.rb +119 -0
- data/lib/fluent/plugin/filter_record_transformer.rb +322 -0
- data/lib/fluent/plugin/filter_stdout.rb +53 -0
- data/lib/fluent/plugin/formatter.rb +50 -0
- data/lib/fluent/plugin/formatter_csv.rb +52 -0
- data/lib/fluent/plugin/formatter_hash.rb +33 -0
- data/lib/fluent/plugin/formatter_json.rb +55 -0
- data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
- data/lib/fluent/plugin/formatter_msgpack.rb +33 -0
- data/lib/fluent/plugin/formatter_out_file.rb +51 -0
- data/lib/fluent/plugin/formatter_single_value.rb +34 -0
- data/lib/fluent/plugin/formatter_stdout.rb +75 -0
- data/lib/fluent/plugin/formatter_tsv.rb +34 -0
- data/lib/fluent/plugin/in_debug_agent.rb +64 -0
- data/lib/fluent/plugin/in_dummy.rb +139 -0
- data/lib/fluent/plugin/in_exec.rb +108 -0
- data/lib/fluent/plugin/in_forward.rb +455 -0
- data/lib/fluent/plugin/in_gc_stat.rb +56 -0
- data/lib/fluent/plugin/in_http.rb +433 -0
- data/lib/fluent/plugin/in_monitor_agent.rb +448 -0
- data/lib/fluent/plugin/in_object_space.rb +93 -0
- data/lib/fluent/plugin/in_syslog.rb +209 -0
- data/lib/fluent/plugin/in_tail.rb +905 -0
- data/lib/fluent/plugin/in_tcp.rb +85 -0
- data/lib/fluent/plugin/in_udp.rb +81 -0
- data/lib/fluent/plugin/in_unix.rb +201 -0
- data/lib/fluent/plugin/input.rb +37 -0
- data/lib/fluent/plugin/multi_output.rb +157 -0
- data/lib/fluent/plugin/out_copy.rb +46 -0
- data/lib/fluent/plugin/out_exec.rb +105 -0
- data/lib/fluent/plugin/out_exec_filter.rb +317 -0
- data/lib/fluent/plugin/out_file.rb +302 -0
- data/lib/fluent/plugin/out_forward.rb +912 -0
- data/lib/fluent/plugin/out_null.rb +74 -0
- data/lib/fluent/plugin/out_relabel.rb +32 -0
- data/lib/fluent/plugin/out_roundrobin.rb +84 -0
- data/lib/fluent/plugin/out_secondary_file.rb +133 -0
- data/lib/fluent/plugin/out_stdout.rb +75 -0
- data/lib/fluent/plugin/out_stream.rb +130 -0
- data/lib/fluent/plugin/output.rb +1291 -0
- data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
- data/lib/fluent/plugin/parser.rb +191 -0
- data/lib/fluent/plugin/parser_apache.rb +28 -0
- data/lib/fluent/plugin/parser_apache2.rb +84 -0
- data/lib/fluent/plugin/parser_apache_error.rb +26 -0
- data/lib/fluent/plugin/parser_csv.rb +39 -0
- data/lib/fluent/plugin/parser_json.rb +81 -0
- data/lib/fluent/plugin/parser_ltsv.rb +42 -0
- data/lib/fluent/plugin/parser_msgpack.rb +50 -0
- data/lib/fluent/plugin/parser_multiline.rb +105 -0
- data/lib/fluent/plugin/parser_nginx.rb +28 -0
- data/lib/fluent/plugin/parser_none.rb +36 -0
- data/lib/fluent/plugin/parser_regexp.rb +63 -0
- data/lib/fluent/plugin/parser_syslog.rb +121 -0
- data/lib/fluent/plugin/parser_tsv.rb +42 -0
- data/lib/fluent/plugin/socket_util.rb +22 -0
- data/lib/fluent/plugin/storage.rb +84 -0
- data/lib/fluent/plugin/storage_local.rb +159 -0
- data/lib/fluent/plugin/string_util.rb +22 -0
- data/lib/fluent/plugin_helper.rb +70 -0
- data/lib/fluent/plugin_helper/cert_option.rb +159 -0
- data/lib/fluent/plugin_helper/child_process.rb +364 -0
- data/lib/fluent/plugin_helper/compat_parameters.rb +331 -0
- data/lib/fluent/plugin_helper/event_emitter.rb +93 -0
- data/lib/fluent/plugin_helper/event_loop.rb +161 -0
- data/lib/fluent/plugin_helper/extract.rb +104 -0
- data/lib/fluent/plugin_helper/formatter.rb +147 -0
- data/lib/fluent/plugin_helper/inject.rb +151 -0
- data/lib/fluent/plugin_helper/parser.rb +147 -0
- data/lib/fluent/plugin_helper/retry_state.rb +201 -0
- data/lib/fluent/plugin_helper/server.rb +738 -0
- data/lib/fluent/plugin_helper/socket.rb +241 -0
- data/lib/fluent/plugin_helper/socket_option.rb +69 -0
- data/lib/fluent/plugin_helper/storage.rb +349 -0
- data/lib/fluent/plugin_helper/thread.rb +179 -0
- data/lib/fluent/plugin_helper/timer.rb +91 -0
- data/lib/fluent/plugin_id.rb +80 -0
- data/lib/fluent/process.rb +22 -0
- data/lib/fluent/registry.rb +116 -0
- data/lib/fluent/root_agent.rb +323 -0
- data/lib/fluent/rpc.rb +94 -0
- data/lib/fluent/supervisor.rb +741 -0
- data/lib/fluent/system_config.rb +159 -0
- data/lib/fluent/test.rb +58 -0
- data/lib/fluent/test/base.rb +78 -0
- data/lib/fluent/test/driver/base.rb +224 -0
- data/lib/fluent/test/driver/base_owned.rb +70 -0
- data/lib/fluent/test/driver/base_owner.rb +135 -0
- data/lib/fluent/test/driver/event_feeder.rb +98 -0
- data/lib/fluent/test/driver/filter.rb +57 -0
- data/lib/fluent/test/driver/formatter.rb +30 -0
- data/lib/fluent/test/driver/input.rb +31 -0
- data/lib/fluent/test/driver/multi_output.rb +53 -0
- data/lib/fluent/test/driver/output.rb +102 -0
- data/lib/fluent/test/driver/parser.rb +30 -0
- data/lib/fluent/test/driver/test_event_router.rb +45 -0
- data/lib/fluent/test/filter_test.rb +77 -0
- data/lib/fluent/test/formatter_test.rb +65 -0
- data/lib/fluent/test/helpers.rb +134 -0
- data/lib/fluent/test/input_test.rb +174 -0
- data/lib/fluent/test/log.rb +79 -0
- data/lib/fluent/test/output_test.rb +156 -0
- data/lib/fluent/test/parser_test.rb +70 -0
- data/lib/fluent/test/startup_shutdown.rb +46 -0
- data/lib/fluent/time.rb +412 -0
- data/lib/fluent/timezone.rb +133 -0
- data/lib/fluent/unique_id.rb +39 -0
- data/lib/fluent/version.rb +21 -0
- data/lib/fluent/winsvc.rb +71 -0
- data/templates/new_gem/Gemfile +3 -0
- data/templates/new_gem/README.md.erb +43 -0
- data/templates/new_gem/Rakefile +13 -0
- data/templates/new_gem/fluent-plugin.gemspec.erb +27 -0
- data/templates/new_gem/lib/fluent/plugin/filter.rb.erb +14 -0
- data/templates/new_gem/lib/fluent/plugin/formatter.rb.erb +14 -0
- data/templates/new_gem/lib/fluent/plugin/input.rb.erb +11 -0
- data/templates/new_gem/lib/fluent/plugin/output.rb.erb +11 -0
- data/templates/new_gem/lib/fluent/plugin/parser.rb.erb +15 -0
- data/templates/new_gem/test/helper.rb.erb +8 -0
- data/templates/new_gem/test/plugin/test_filter.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_formatter.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_input.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_output.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_parser.rb.erb +18 -0
- data/templates/plugin_config_formatter/param.md-compact.erb +25 -0
- data/templates/plugin_config_formatter/param.md.erb +34 -0
- data/templates/plugin_config_formatter/section.md.erb +12 -0
- data/test/command/test_binlog_reader.rb +346 -0
- data/test/command/test_fluentd.rb +618 -0
- data/test/command/test_plugin_config_formatter.rb +275 -0
- data/test/command/test_plugin_generator.rb +66 -0
- data/test/compat/test_calls_super.rb +166 -0
- data/test/compat/test_parser.rb +92 -0
- data/test/config/assertions.rb +42 -0
- data/test/config/test_config_parser.rb +513 -0
- data/test/config/test_configurable.rb +1587 -0
- data/test/config/test_configure_proxy.rb +566 -0
- data/test/config/test_dsl.rb +415 -0
- data/test/config/test_element.rb +403 -0
- data/test/config/test_literal_parser.rb +297 -0
- data/test/config/test_section.rb +184 -0
- data/test/config/test_system_config.rb +168 -0
- data/test/config/test_types.rb +191 -0
- data/test/helper.rb +153 -0
- data/test/plugin/data/2010/01/20100102-030405.log +0 -0
- data/test/plugin/data/2010/01/20100102-030406.log +0 -0
- data/test/plugin/data/2010/01/20100102.log +0 -0
- data/test/plugin/data/log/bar +0 -0
- data/test/plugin/data/log/foo/bar.log +0 -0
- data/test/plugin/data/log/foo/bar2 +0 -0
- data/test/plugin/data/log/test.log +0 -0
- data/test/plugin/test_bare_output.rb +118 -0
- data/test/plugin/test_base.rb +115 -0
- data/test/plugin/test_buf_file.rb +843 -0
- data/test/plugin/test_buf_memory.rb +42 -0
- data/test/plugin/test_buffer.rb +1220 -0
- data/test/plugin/test_buffer_chunk.rb +198 -0
- data/test/plugin/test_buffer_file_chunk.rb +844 -0
- data/test/plugin/test_buffer_memory_chunk.rb +338 -0
- data/test/plugin/test_compressable.rb +84 -0
- data/test/plugin/test_file_util.rb +96 -0
- data/test/plugin/test_filter.rb +357 -0
- data/test/plugin/test_filter_grep.rb +119 -0
- data/test/plugin/test_filter_parser.rb +700 -0
- data/test/plugin/test_filter_record_transformer.rb +556 -0
- data/test/plugin/test_filter_stdout.rb +202 -0
- data/test/plugin/test_formatter_csv.rb +111 -0
- data/test/plugin/test_formatter_hash.rb +35 -0
- data/test/plugin/test_formatter_json.rb +51 -0
- data/test/plugin/test_formatter_ltsv.rb +59 -0
- data/test/plugin/test_formatter_msgpack.rb +28 -0
- data/test/plugin/test_formatter_out_file.rb +95 -0
- data/test/plugin/test_formatter_single_value.rb +38 -0
- data/test/plugin/test_in_debug_agent.rb +28 -0
- data/test/plugin/test_in_dummy.rb +192 -0
- data/test/plugin/test_in_exec.rb +245 -0
- data/test/plugin/test_in_forward.rb +1120 -0
- data/test/plugin/test_in_gc_stat.rb +39 -0
- data/test/plugin/test_in_http.rb +588 -0
- data/test/plugin/test_in_monitor_agent.rb +516 -0
- data/test/plugin/test_in_object_space.rb +64 -0
- data/test/plugin/test_in_syslog.rb +271 -0
- data/test/plugin/test_in_tail.rb +1216 -0
- data/test/plugin/test_in_tcp.rb +118 -0
- data/test/plugin/test_in_udp.rb +152 -0
- data/test/plugin/test_in_unix.rb +126 -0
- data/test/plugin/test_input.rb +126 -0
- data/test/plugin/test_multi_output.rb +180 -0
- data/test/plugin/test_out_copy.rb +160 -0
- data/test/plugin/test_out_exec.rb +310 -0
- data/test/plugin/test_out_exec_filter.rb +613 -0
- data/test/plugin/test_out_file.rb +873 -0
- data/test/plugin/test_out_forward.rb +685 -0
- data/test/plugin/test_out_null.rb +105 -0
- data/test/plugin/test_out_relabel.rb +28 -0
- data/test/plugin/test_out_roundrobin.rb +146 -0
- data/test/plugin/test_out_secondary_file.rb +442 -0
- data/test/plugin/test_out_stdout.rb +170 -0
- data/test/plugin/test_out_stream.rb +93 -0
- data/test/plugin/test_output.rb +870 -0
- data/test/plugin/test_output_as_buffered.rb +1932 -0
- data/test/plugin/test_output_as_buffered_compress.rb +165 -0
- data/test/plugin/test_output_as_buffered_overflow.rb +250 -0
- data/test/plugin/test_output_as_buffered_retries.rb +839 -0
- data/test/plugin/test_output_as_buffered_secondary.rb +877 -0
- data/test/plugin/test_output_as_standard.rb +374 -0
- data/test/plugin/test_owned_by.rb +35 -0
- data/test/plugin/test_parser.rb +359 -0
- data/test/plugin/test_parser_apache.rb +42 -0
- data/test/plugin/test_parser_apache2.rb +46 -0
- data/test/plugin/test_parser_apache_error.rb +45 -0
- data/test/plugin/test_parser_csv.rb +103 -0
- data/test/plugin/test_parser_json.rb +114 -0
- data/test/plugin/test_parser_labeled_tsv.rb +128 -0
- data/test/plugin/test_parser_multiline.rb +100 -0
- data/test/plugin/test_parser_nginx.rb +48 -0
- data/test/plugin/test_parser_none.rb +52 -0
- data/test/plugin/test_parser_regexp.rb +281 -0
- data/test/plugin/test_parser_syslog.rb +242 -0
- data/test/plugin/test_parser_tsv.rb +122 -0
- data/test/plugin/test_storage.rb +167 -0
- data/test/plugin/test_storage_local.rb +335 -0
- data/test/plugin/test_string_util.rb +26 -0
- data/test/plugin_helper/test_child_process.rb +794 -0
- data/test/plugin_helper/test_compat_parameters.rb +331 -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_extract.rb +194 -0
- data/test/plugin_helper/test_formatter.rb +255 -0
- data/test/plugin_helper/test_inject.rb +519 -0
- data/test/plugin_helper/test_parser.rb +264 -0
- data/test/plugin_helper/test_retry_state.rb +422 -0
- data/test/plugin_helper/test_server.rb +1677 -0
- data/test/plugin_helper/test_storage.rb +542 -0
- data/test/plugin_helper/test_thread.rb +164 -0
- data/test/plugin_helper/test_timer.rb +132 -0
- data/test/scripts/exec_script.rb +32 -0
- data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +7 -0
- data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +7 -0
- data/test/scripts/fluent/plugin/formatter_known.rb +8 -0
- data/test/scripts/fluent/plugin/out_test.rb +81 -0
- data/test/scripts/fluent/plugin/out_test2.rb +80 -0
- data/test/scripts/fluent/plugin/parser_known.rb +4 -0
- data/test/test_clock.rb +164 -0
- data/test/test_config.rb +179 -0
- data/test/test_configdsl.rb +148 -0
- data/test/test_event.rb +515 -0
- data/test/test_event_router.rb +331 -0
- data/test/test_event_time.rb +186 -0
- data/test/test_filter.rb +121 -0
- data/test/test_formatter.rb +312 -0
- data/test/test_input.rb +31 -0
- data/test/test_log.rb +828 -0
- data/test/test_match.rb +137 -0
- data/test/test_mixin.rb +351 -0
- data/test/test_output.rb +273 -0
- data/test/test_plugin.rb +251 -0
- data/test/test_plugin_classes.rb +253 -0
- data/test/test_plugin_helper.rb +81 -0
- data/test/test_plugin_id.rb +101 -0
- data/test/test_process.rb +14 -0
- data/test/test_root_agent.rb +611 -0
- data/test/test_supervisor.rb +373 -0
- data/test/test_test_drivers.rb +135 -0
- data/test/test_time_formatter.rb +282 -0
- data/test/test_time_parser.rb +211 -0
- data/test/test_unique_id.rb +47 -0
- metadata +898 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'fluent/plugin/input'
|
18
|
+
|
19
|
+
module Fluent::Plugin
|
20
|
+
class DebugAgentInput < Input
|
21
|
+
Fluent::Plugin.register_input('debug_agent', self)
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
require 'drb/drb'
|
25
|
+
require 'fluent/plugin/file_util'
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
config_param :bind, :string, default: '0.0.0.0'
|
30
|
+
config_param :port, :integer, default: 24230
|
31
|
+
config_param :unix_path, :string, default: nil
|
32
|
+
#config_param :unix_mode # TODO
|
33
|
+
config_param :object, :string, default: 'Fluent::Engine'
|
34
|
+
|
35
|
+
def configure(conf)
|
36
|
+
super
|
37
|
+
if @unix_path
|
38
|
+
unless ::Fluent::FileUtil.writable?(@unix_path)
|
39
|
+
raise Fluent::ConfigError, "in_debug_agent: `#{@unix_path}` is not writable"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def start
|
45
|
+
super
|
46
|
+
|
47
|
+
if @unix_path
|
48
|
+
require 'drb/unix'
|
49
|
+
uri = "drbunix:#{@unix_path}"
|
50
|
+
else
|
51
|
+
uri = "druby://#{@bind}:#{@port}"
|
52
|
+
end
|
53
|
+
log.info "listening dRuby", uri: uri, object: @object
|
54
|
+
obj = eval(@object)
|
55
|
+
@server = DRb::DRbServer.new(uri, obj)
|
56
|
+
end
|
57
|
+
|
58
|
+
def shutdown
|
59
|
+
@server.stop_service if @server
|
60
|
+
|
61
|
+
super
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'json'
|
18
|
+
|
19
|
+
require 'fluent/plugin/input'
|
20
|
+
require 'fluent/config/error'
|
21
|
+
|
22
|
+
module Fluent::Plugin
|
23
|
+
class DummyInput < Input
|
24
|
+
Fluent::Plugin.register_input('dummy', self)
|
25
|
+
|
26
|
+
helpers :thread, :storage
|
27
|
+
|
28
|
+
BIN_NUM = 10
|
29
|
+
DEFAULT_STORAGE_TYPE = 'local'
|
30
|
+
|
31
|
+
desc "The value is the tag assigned to the generated events."
|
32
|
+
config_param :tag, :string
|
33
|
+
desc "The number of events in event stream of each emits."
|
34
|
+
config_param :size, :integer, default: 1
|
35
|
+
desc "It configures how many events to generate per second."
|
36
|
+
config_param :rate, :integer, default: 1
|
37
|
+
desc "If specified, each generated event has an auto-incremented key field."
|
38
|
+
config_param :auto_increment_key, :string, default: nil
|
39
|
+
desc "The boolean to suspend-and-resume incremental value after restart"
|
40
|
+
config_param :suspend, :bool, default: false
|
41
|
+
desc "The dummy data to be generated. An array of JSON hashes or a single JSON hash."
|
42
|
+
config_param :dummy, default: [{"message"=>"dummy"}] do |val|
|
43
|
+
begin
|
44
|
+
parsed = JSON.parse(val)
|
45
|
+
rescue JSON::ParserError => ex
|
46
|
+
# Fluent::ConfigParseError, "got incomplete JSON" will be raised
|
47
|
+
# at literal_parser.rb with --use-v1-config, but I had to
|
48
|
+
# take care at here for the case of --use-v0-config.
|
49
|
+
raise Fluent::ConfigError, "#{ex.class}: #{ex.message}"
|
50
|
+
end
|
51
|
+
dummy = parsed.is_a?(Array) ? parsed : [parsed]
|
52
|
+
dummy.each_with_index do |e, i|
|
53
|
+
raise Fluent::ConfigError, "#{i}th element of dummy, #{e}, is not a hash" unless e.is_a?(Hash)
|
54
|
+
end
|
55
|
+
dummy
|
56
|
+
end
|
57
|
+
|
58
|
+
def initialize
|
59
|
+
super
|
60
|
+
@storage = nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def configure(conf)
|
64
|
+
super
|
65
|
+
@dummy_index = 0
|
66
|
+
config = conf.elements.select{|e| e.name == 'storage' }.first
|
67
|
+
@storage = storage_create(usage: 'suspend', conf: config, default_type: DEFAULT_STORAGE_TYPE)
|
68
|
+
end
|
69
|
+
|
70
|
+
def multi_workers_ready?
|
71
|
+
true
|
72
|
+
end
|
73
|
+
|
74
|
+
def start
|
75
|
+
super
|
76
|
+
|
77
|
+
@storage.put(:increment_value, 0) unless @storage.get(:increment_value)
|
78
|
+
@storage.put(:dummy_index, 0) unless @storage.get(:dummy_index)
|
79
|
+
|
80
|
+
if @auto_increment_key && !@storage.get(:auto_increment_value)
|
81
|
+
@storage.put(:auto_increment_value, -1)
|
82
|
+
end
|
83
|
+
|
84
|
+
thread_create(:dummy_input, &method(:run))
|
85
|
+
end
|
86
|
+
|
87
|
+
def run
|
88
|
+
batch_num = (@rate / BIN_NUM).to_i
|
89
|
+
residual_num = (@rate % BIN_NUM)
|
90
|
+
while thread_current_running?
|
91
|
+
current_time = Time.now.to_i
|
92
|
+
BIN_NUM.times do
|
93
|
+
break unless (thread_current_running? && Time.now.to_i <= current_time)
|
94
|
+
wait(0.1) { emit(batch_num) }
|
95
|
+
end
|
96
|
+
emit(residual_num) if thread_current_running?
|
97
|
+
# wait for next second
|
98
|
+
while thread_current_running? && Time.now.to_i <= current_time
|
99
|
+
sleep 0.01
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def emit(num)
|
105
|
+
begin
|
106
|
+
if @size > 1
|
107
|
+
num.times do
|
108
|
+
router.emit_array(@tag, Array.new(@size) { [Fluent::Engine.now, generate] })
|
109
|
+
end
|
110
|
+
else
|
111
|
+
num.times { router.emit(@tag, Fluent::Engine.now, generate) }
|
112
|
+
end
|
113
|
+
rescue => _
|
114
|
+
# ignore all errors not to stop emits by emit errors
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def generate
|
119
|
+
d = @dummy[@dummy_index]
|
120
|
+
unless d
|
121
|
+
@dummy_index = 0
|
122
|
+
d = @dummy[@dummy_index]
|
123
|
+
end
|
124
|
+
@dummy_index += 1
|
125
|
+
if @auto_increment_key
|
126
|
+
d = d.dup
|
127
|
+
d[@auto_increment_key] = @storage.update(:auto_increment_value){|v| v + 1 }
|
128
|
+
end
|
129
|
+
d
|
130
|
+
end
|
131
|
+
|
132
|
+
def wait(time)
|
133
|
+
start_time = Time.now
|
134
|
+
yield
|
135
|
+
sleep_time = time - (Time.now - start_time)
|
136
|
+
sleep sleep_time if sleep_time > 0
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'fluent/plugin/input'
|
18
|
+
require 'yajl'
|
19
|
+
|
20
|
+
module Fluent::Plugin
|
21
|
+
class ExecInput < Fluent::Plugin::Input
|
22
|
+
Fluent::Plugin.register_input('exec', self)
|
23
|
+
|
24
|
+
helpers :compat_parameters, :extract, :parser, :child_process
|
25
|
+
|
26
|
+
desc 'The command (program) to execute.'
|
27
|
+
config_param :command, :string
|
28
|
+
|
29
|
+
config_section :parse do
|
30
|
+
config_set_default :@type, 'tsv'
|
31
|
+
config_set_default :time_type, :float
|
32
|
+
config_set_default :time_key, nil
|
33
|
+
config_set_default :estimate_current_event, false
|
34
|
+
end
|
35
|
+
|
36
|
+
config_section :extract do
|
37
|
+
config_set_default :time_type, :float
|
38
|
+
end
|
39
|
+
|
40
|
+
desc 'Tag of the output events.'
|
41
|
+
config_param :tag, :string, default: nil
|
42
|
+
desc 'The interval time between periodic program runs.'
|
43
|
+
config_param :run_interval, :time, default: nil
|
44
|
+
desc 'The default block size to read if parser requires partial read.'
|
45
|
+
config_param :read_block_size, :size, default: 10240 # 10k
|
46
|
+
|
47
|
+
attr_reader :parser
|
48
|
+
|
49
|
+
def configure(conf)
|
50
|
+
compat_parameters_convert(conf, :extract, :parser)
|
51
|
+
['parse', 'extract'].each do |subsection_name|
|
52
|
+
if subsection = conf.elements(subsection_name).first
|
53
|
+
if subsection.has_key?('time_format')
|
54
|
+
subsection['time_type'] ||= 'string'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
super
|
60
|
+
|
61
|
+
if !@tag && (!@extract_config || !@extract_config.tag_key)
|
62
|
+
raise Fluent::ConfigError, "'tag' or 'tag_key' option is required on exec input"
|
63
|
+
end
|
64
|
+
@parser = parser_create
|
65
|
+
end
|
66
|
+
|
67
|
+
def multi_workers_ready?
|
68
|
+
true
|
69
|
+
end
|
70
|
+
|
71
|
+
def start
|
72
|
+
super
|
73
|
+
|
74
|
+
if @run_interval
|
75
|
+
child_process_execute(:exec_input, @command, interval: @run_interval, mode: [:read], &method(:run))
|
76
|
+
else
|
77
|
+
child_process_execute(:exec_input, @command, immediate: true, mode: [:read], &method(:run))
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def run(io)
|
82
|
+
case
|
83
|
+
when @parser.implement?(:parse_io)
|
84
|
+
@parser.parse_io(io, &method(:on_record))
|
85
|
+
when @parser.implement?(:parse_partial_data)
|
86
|
+
until io.eof?
|
87
|
+
@parser.parse_partial_data(io.readpartial(@read_block_size), &method(:on_record))
|
88
|
+
end
|
89
|
+
when @parser.parser_type == :text_per_line
|
90
|
+
io.each_line do |line|
|
91
|
+
@parser.parse(line.chomp, &method(:on_record))
|
92
|
+
end
|
93
|
+
else
|
94
|
+
@parser.parse(io.read, &method(:on_record))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def on_record(time, record)
|
99
|
+
tag = extract_tag_from_record(record)
|
100
|
+
tag ||= @tag
|
101
|
+
time ||= extract_time_from_record(record) || Fluent::EventTime.now
|
102
|
+
router.emit(tag, time, record)
|
103
|
+
rescue => e
|
104
|
+
log.error "exec failed to emit", tag: tag, record: Yajl.dump(record), error: e
|
105
|
+
router.emit_error_event(tag, time, record, e) if tag && time && record
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,455 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
|
18
|
+
require 'fluent/plugin/input'
|
19
|
+
require 'fluent/msgpack_factory'
|
20
|
+
require 'yajl'
|
21
|
+
require 'digest'
|
22
|
+
require 'securerandom'
|
23
|
+
|
24
|
+
module Fluent::Plugin
|
25
|
+
class ForwardInput < Input
|
26
|
+
Fluent::Plugin.register_input('forward', self)
|
27
|
+
|
28
|
+
# See the wiki page below for protocol specification
|
29
|
+
# https://github.com/fluent/fluentd/wiki/Forward-Protocol-Specification-v1
|
30
|
+
|
31
|
+
helpers :server
|
32
|
+
|
33
|
+
LISTEN_PORT = 24224
|
34
|
+
|
35
|
+
desc 'The port to listen to.'
|
36
|
+
config_param :port, :integer, default: LISTEN_PORT
|
37
|
+
desc 'The bind address to listen to.'
|
38
|
+
config_param :bind, :string, default: '0.0.0.0'
|
39
|
+
|
40
|
+
config_param :backlog, :integer, default: nil
|
41
|
+
# SO_LINGER 0 to send RST rather than FIN to avoid lots of connections sitting in TIME_WAIT at src
|
42
|
+
desc 'The timeout time used to set linger option.'
|
43
|
+
config_param :linger_timeout, :integer, default: 0
|
44
|
+
# This option is for Cool.io's loop wait timeout to avoid loop stuck at shutdown. Almost users don't need to change this value.
|
45
|
+
config_param :blocking_timeout, :time, default: 0.5
|
46
|
+
desc 'Try to resolve hostname from IP addresses or not.'
|
47
|
+
config_param :resolve_hostname, :bool, default: nil
|
48
|
+
desc 'Connections will be disconnected right after receiving first message if this value is true.'
|
49
|
+
config_param :deny_keepalive, :bool, default: false
|
50
|
+
|
51
|
+
desc 'Log warning if received chunk size is larger than this value.'
|
52
|
+
config_param :chunk_size_warn_limit, :size, default: nil
|
53
|
+
desc 'Received chunk is dropped if it is larger than this value.'
|
54
|
+
config_param :chunk_size_limit, :size, default: nil
|
55
|
+
desc 'Skip an event if incoming event is invalid.'
|
56
|
+
config_param :skip_invalid_event, :bool, default: false
|
57
|
+
|
58
|
+
desc "The field name of the client's source address."
|
59
|
+
config_param :source_address_key, :string, default: nil
|
60
|
+
desc "The field name of the client's hostname."
|
61
|
+
config_param :source_hostname_key, :string, default: nil
|
62
|
+
|
63
|
+
config_section :security, required: false, multi: false do
|
64
|
+
desc 'The hostname'
|
65
|
+
config_param :self_hostname, :string
|
66
|
+
desc 'Shared key for authentication'
|
67
|
+
config_param :shared_key, :string, secret: true
|
68
|
+
desc 'If true, use user based authentication'
|
69
|
+
config_param :user_auth, :bool, default: false
|
70
|
+
desc 'Allow anonymous source. <client> sections required if disabled.'
|
71
|
+
config_param :allow_anonymous_source, :bool, default: true
|
72
|
+
|
73
|
+
### User based authentication
|
74
|
+
config_section :user, param_name: :users, required: false, multi: true do
|
75
|
+
desc 'The username for authentication'
|
76
|
+
config_param :username, :string
|
77
|
+
desc 'The password for authentication'
|
78
|
+
config_param :password, :string, secret: true
|
79
|
+
end
|
80
|
+
|
81
|
+
### Client ip/network authentication & per_host shared key
|
82
|
+
config_section :client, param_name: :clients, required: false, multi: true do
|
83
|
+
desc 'The IP address or host name of the client'
|
84
|
+
config_param :host, :string, default: nil
|
85
|
+
desc 'Network address specification'
|
86
|
+
config_param :network, :string, default: nil
|
87
|
+
desc 'Shared key per client'
|
88
|
+
config_param :shared_key, :string, default: nil, secret: true
|
89
|
+
desc 'Array of username.'
|
90
|
+
config_param :users, :array, default: []
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def configure(conf)
|
95
|
+
super
|
96
|
+
|
97
|
+
if @source_hostname_key
|
98
|
+
# TODO: add test
|
99
|
+
if @resolve_hostname.nil?
|
100
|
+
@resolve_hostname = true
|
101
|
+
elsif !@resolve_hostname # user specifies "false" in config
|
102
|
+
raise Fluent::ConfigError, "resolve_hostname must be true with source_hostname_key"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
@enable_field_injection = @source_address_key || @source_hostname_key
|
106
|
+
|
107
|
+
if @security
|
108
|
+
if @security.user_auth && @security.users.empty?
|
109
|
+
raise Fluent::ConfigError, "<user> sections required if user_auth enabled"
|
110
|
+
end
|
111
|
+
if !@security.allow_anonymous_source && @security.clients.empty?
|
112
|
+
raise Fluent::ConfigError, "<client> sections required if allow_anonymous_source disabled"
|
113
|
+
end
|
114
|
+
|
115
|
+
@nodes = []
|
116
|
+
|
117
|
+
@security.clients.each do |client|
|
118
|
+
if client.host && client.network
|
119
|
+
raise Fluent::ConfigError, "both of 'host' and 'network' are specified for client"
|
120
|
+
end
|
121
|
+
if !client.host && !client.network
|
122
|
+
raise Fluent::ConfigError, "Either of 'host' and 'network' must be specified for client"
|
123
|
+
end
|
124
|
+
source = nil
|
125
|
+
if client.host
|
126
|
+
begin
|
127
|
+
source = IPSocket.getaddress(client.host)
|
128
|
+
rescue SocketError => e
|
129
|
+
raise Fluent::ConfigError, "host '#{client.host}' cannot be resolved"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
source_addr = begin
|
133
|
+
IPAddr.new(source || client.network)
|
134
|
+
rescue ArgumentError => e
|
135
|
+
raise Fluent::ConfigError, "network '#{client.network}' address format is invalid"
|
136
|
+
end
|
137
|
+
@nodes.push({
|
138
|
+
address: source_addr,
|
139
|
+
shared_key: (client.shared_key || @security.shared_key),
|
140
|
+
users: client.users
|
141
|
+
})
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def multi_workers_ready?
|
147
|
+
true
|
148
|
+
end
|
149
|
+
|
150
|
+
HEARTBEAT_UDP_PAYLOAD = "\0"
|
151
|
+
|
152
|
+
def start
|
153
|
+
super
|
154
|
+
|
155
|
+
shared_socket = system_config.workers > 1
|
156
|
+
|
157
|
+
log.info "listening port", port: @port, bind: @bind
|
158
|
+
server_create_connection(
|
159
|
+
:in_forward_server, @port,
|
160
|
+
bind: @bind,
|
161
|
+
shared: shared_socket,
|
162
|
+
resolve_name: @resolve_hostname,
|
163
|
+
linger_timeout: @linger_timeout,
|
164
|
+
backlog: @backlog,
|
165
|
+
&method(:handle_connection)
|
166
|
+
)
|
167
|
+
|
168
|
+
server_create(:in_forward_server_udp_heartbeat, @port, shared: shared_socket, proto: :udp, bind: @bind, resolve_name: @resolve_hostname, max_bytes: 128) do |data, sock|
|
169
|
+
log.trace "heartbeat udp data arrived", host: sock.remote_host, port: sock.remote_port, data: data
|
170
|
+
begin
|
171
|
+
sock.write HEARTBEAT_UDP_PAYLOAD
|
172
|
+
rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::EINTR
|
173
|
+
log.trace "error while heartbeat response", host: sock.remote_host, error: e
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def handle_connection(conn)
|
179
|
+
send_data = ->(serializer, data){ conn.write serializer.call(data) }
|
180
|
+
|
181
|
+
log.trace "connected fluent socket", addr: conn.remote_addr, port: conn.remote_port
|
182
|
+
state = :established
|
183
|
+
nonce = nil
|
184
|
+
user_auth_salt = nil
|
185
|
+
|
186
|
+
if @security
|
187
|
+
# security enabled session MUST use MessagePack as serialization format
|
188
|
+
state = :helo
|
189
|
+
nonce = generate_salt
|
190
|
+
user_auth_salt = generate_salt
|
191
|
+
send_data.call(:to_msgpack.to_proc, generate_helo(nonce, user_auth_salt))
|
192
|
+
state = :pingpong
|
193
|
+
end
|
194
|
+
|
195
|
+
log.trace "accepted fluent socket", addr: conn.remote_addr, port: conn.remote_port
|
196
|
+
|
197
|
+
read_messages(conn) do |msg, chunk_size, serializer|
|
198
|
+
case state
|
199
|
+
when :pingpong
|
200
|
+
success, reason_or_salt, shared_key = check_ping(msg, conn.remote_addr, user_auth_salt, nonce)
|
201
|
+
unless success
|
202
|
+
send_data.call(serializer, generate_pong(false, reason_or_salt, nonce, shared_key))
|
203
|
+
conn.close
|
204
|
+
next
|
205
|
+
end
|
206
|
+
send_data.call(serializer, generate_pong(true, reason_or_salt, nonce, shared_key))
|
207
|
+
|
208
|
+
log.debug "connection established", address: conn.remote_addr, port: conn.remote_port
|
209
|
+
state = :established
|
210
|
+
when :established
|
211
|
+
options = on_message(msg, chunk_size, conn)
|
212
|
+
if options && r = response(options)
|
213
|
+
log.trace "sent response to fluent socket", address: conn.remote_addr, response: r
|
214
|
+
conn.on_write_complete{ conn.close } if @deny_keepalive
|
215
|
+
send_data.call(serializer, r)
|
216
|
+
else
|
217
|
+
if @deny_keepalive
|
218
|
+
conn.close
|
219
|
+
end
|
220
|
+
end
|
221
|
+
else
|
222
|
+
raise "BUG: unknown session state: #{state}"
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
def read_messages(conn, &block)
|
228
|
+
feeder = nil
|
229
|
+
serializer = nil
|
230
|
+
bytes = 0
|
231
|
+
conn.data do |data|
|
232
|
+
# only for first call of callback
|
233
|
+
unless feeder
|
234
|
+
first = data[0]
|
235
|
+
if first == '{' || first == '[' # json
|
236
|
+
parser = Yajl::Parser.new
|
237
|
+
parser.on_parse_complete = ->(obj){
|
238
|
+
block.call(obj, bytes, serializer)
|
239
|
+
bytes = 0
|
240
|
+
}
|
241
|
+
serializer = :to_json.to_proc
|
242
|
+
feeder = ->(d){ parser << d }
|
243
|
+
else # msgpack
|
244
|
+
parser = Fluent::Engine.msgpack_factory.unpacker
|
245
|
+
serializer = :to_msgpack.to_proc
|
246
|
+
feeder = ->(d){
|
247
|
+
parser.feed_each(d){|obj|
|
248
|
+
block.call(obj, bytes, serializer)
|
249
|
+
bytes = 0
|
250
|
+
}
|
251
|
+
}
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
bytes += data.bytesize
|
256
|
+
feeder.call(data)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
def response(option)
|
261
|
+
if option && option['chunk']
|
262
|
+
return { 'ack' => option['chunk'] }
|
263
|
+
end
|
264
|
+
nil
|
265
|
+
end
|
266
|
+
|
267
|
+
def on_message(msg, chunk_size, conn)
|
268
|
+
if msg.nil?
|
269
|
+
# for future TCP heartbeat_request
|
270
|
+
return
|
271
|
+
end
|
272
|
+
|
273
|
+
# TODO: raise an exception if broken chunk is generated by recoverable situation
|
274
|
+
unless msg.is_a?(Array)
|
275
|
+
log.warn "incoming chunk is broken:", host: conn.remote_host, msg: msg
|
276
|
+
return
|
277
|
+
end
|
278
|
+
|
279
|
+
tag = msg[0]
|
280
|
+
entries = msg[1]
|
281
|
+
|
282
|
+
if @chunk_size_limit && (chunk_size > @chunk_size_limit)
|
283
|
+
log.warn "Input chunk size is larger than 'chunk_size_limit', dropped:", tag: tag, host: conn.remote_host, limit: @chunk_size_limit, size: chunk_size
|
284
|
+
return
|
285
|
+
elsif @chunk_size_warn_limit && (chunk_size > @chunk_size_warn_limit)
|
286
|
+
log.warn "Input chunk size is larger than 'chunk_size_warn_limit':", tag: tag, host: conn.remote_host, limit: @chunk_size_warn_limit, size: chunk_size
|
287
|
+
end
|
288
|
+
|
289
|
+
case entries
|
290
|
+
when String
|
291
|
+
# PackedForward
|
292
|
+
option = msg[2]
|
293
|
+
size = (option && option['size']) || 0
|
294
|
+
es_class = (option && option['compressed'] == 'gzip') ? Fluent::CompressedMessagePackEventStream : Fluent::MessagePackEventStream
|
295
|
+
es = es_class.new(entries, nil, size.to_i)
|
296
|
+
es = check_and_skip_invalid_event(tag, es, conn.remote_host) if @skip_invalid_event
|
297
|
+
if @enable_field_injection
|
298
|
+
es = add_source_info(es, conn)
|
299
|
+
end
|
300
|
+
router.emit_stream(tag, es)
|
301
|
+
|
302
|
+
when Array
|
303
|
+
# Forward
|
304
|
+
es = if @skip_invalid_event
|
305
|
+
check_and_skip_invalid_event(tag, entries, conn.remote_host)
|
306
|
+
else
|
307
|
+
es = Fluent::MultiEventStream.new
|
308
|
+
entries.each { |e|
|
309
|
+
record = e[1]
|
310
|
+
next if record.nil?
|
311
|
+
time = e[0]
|
312
|
+
time = Fluent::Engine.now if time.nil? || time.to_i == 0 # `to_i == 0` for empty EventTime
|
313
|
+
es.add(time, record)
|
314
|
+
}
|
315
|
+
es
|
316
|
+
end
|
317
|
+
if @enable_field_injection
|
318
|
+
es = add_source_info(es, conn)
|
319
|
+
end
|
320
|
+
router.emit_stream(tag, es)
|
321
|
+
option = msg[2]
|
322
|
+
|
323
|
+
else
|
324
|
+
# Message
|
325
|
+
time = msg[1]
|
326
|
+
record = msg[2]
|
327
|
+
if @skip_invalid_event && invalid_event?(tag, time, record)
|
328
|
+
log.warn "got invalid event and drop it:", host: conn.remote_host, tag: tag, time: time, record: record
|
329
|
+
return msg[3] # retry never succeeded so return ack and drop incoming event.
|
330
|
+
end
|
331
|
+
return if record.nil?
|
332
|
+
time = Fluent::Engine.now if time.to_i == 0
|
333
|
+
if @enable_field_injection
|
334
|
+
record[@source_address_key] = conn.remote_addr if @source_address_key
|
335
|
+
record[@source_hostname_key] = conn.remote_host if @source_hostname_key
|
336
|
+
end
|
337
|
+
router.emit(tag, time, record)
|
338
|
+
option = msg[3]
|
339
|
+
end
|
340
|
+
|
341
|
+
# return option for response
|
342
|
+
option
|
343
|
+
end
|
344
|
+
|
345
|
+
def invalid_event?(tag, time, record)
|
346
|
+
!((time.is_a?(Integer) || time.is_a?(::Fluent::EventTime)) && record.is_a?(Hash) && tag.is_a?(String))
|
347
|
+
end
|
348
|
+
|
349
|
+
def check_and_skip_invalid_event(tag, es, remote_host)
|
350
|
+
new_es = Fluent::MultiEventStream.new
|
351
|
+
es.each { |time, record|
|
352
|
+
if invalid_event?(tag, time, record)
|
353
|
+
log.warn "skip invalid event:", host: remote_host, tag: tag, time: time, record: record
|
354
|
+
next
|
355
|
+
end
|
356
|
+
new_es.add(time, record)
|
357
|
+
}
|
358
|
+
new_es
|
359
|
+
end
|
360
|
+
|
361
|
+
def add_source_info(es, conn)
|
362
|
+
new_es = Fluent::MultiEventStream.new
|
363
|
+
if @source_address_key && @source_hostname_key
|
364
|
+
address = conn.remote_addr
|
365
|
+
hostname = conn.remote_host
|
366
|
+
es.each { |time, record|
|
367
|
+
record[@source_address_key] = address
|
368
|
+
record[@source_hostname_key] = hostname
|
369
|
+
new_es.add(time, record)
|
370
|
+
}
|
371
|
+
elsif @source_address_key
|
372
|
+
address = conn.remote_addr
|
373
|
+
es.each { |time, record|
|
374
|
+
record[@source_address_key] = address
|
375
|
+
new_es.add(time, record)
|
376
|
+
}
|
377
|
+
elsif @source_hostname_key
|
378
|
+
hostname = conn.remote_host
|
379
|
+
es.each { |time, record|
|
380
|
+
record[@source_hostname_key] = hostname
|
381
|
+
new_es.add(time, record)
|
382
|
+
}
|
383
|
+
else
|
384
|
+
raise "BUG: don't call this method in this case"
|
385
|
+
end
|
386
|
+
new_es
|
387
|
+
end
|
388
|
+
|
389
|
+
def select_authenticate_users(node, username)
|
390
|
+
if node.nil? || node[:users].empty?
|
391
|
+
@security.users.select{|u| u.username == username}
|
392
|
+
else
|
393
|
+
@security.users.select{|u| node[:users].include?(u.username) && u.username == username}
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
def generate_salt
|
398
|
+
::SecureRandom.random_bytes(16)
|
399
|
+
end
|
400
|
+
|
401
|
+
def generate_helo(nonce, user_auth_salt)
|
402
|
+
log.debug "generating helo"
|
403
|
+
# ['HELO', options(hash)]
|
404
|
+
['HELO', {'nonce' => nonce, 'auth' => (@security ? user_auth_salt : ''), 'keepalive' => !@deny_keepalive}]
|
405
|
+
end
|
406
|
+
|
407
|
+
def check_ping(message, remote_addr, user_auth_salt, nonce)
|
408
|
+
log.debug "checking ping"
|
409
|
+
# ['PING', self_hostname, shared_key_salt, sha512_hex(shared_key_salt + self_hostname + nonce + shared_key), username || '', sha512_hex(auth_salt + username + password) || '']
|
410
|
+
unless message.size == 6 && message[0] == 'PING'
|
411
|
+
return false, 'invalid ping message'
|
412
|
+
end
|
413
|
+
_ping, hostname, shared_key_salt, shared_key_hexdigest, username, password_digest = message
|
414
|
+
|
415
|
+
node = @nodes.select{|n| n[:address].include?(remote_addr) rescue false }.first
|
416
|
+
if !node && !@security.allow_anonymous_source
|
417
|
+
log.warn "Anonymous client disallowed", address: remote_addr, hostname: hostname
|
418
|
+
return false, "anonymous source host '#{remote_addr}' denied", nil
|
419
|
+
end
|
420
|
+
|
421
|
+
shared_key = node ? node[:shared_key] : @security.shared_key
|
422
|
+
serverside = Digest::SHA512.new.update(shared_key_salt).update(hostname).update(nonce).update(shared_key).hexdigest
|
423
|
+
if shared_key_hexdigest != serverside
|
424
|
+
log.warn "Shared key mismatch", address: remote_addr, hostname: hostname
|
425
|
+
return false, 'shared_key mismatch', nil
|
426
|
+
end
|
427
|
+
|
428
|
+
if @security.user_auth
|
429
|
+
users = select_authenticate_users(node, username)
|
430
|
+
success = false
|
431
|
+
users.each do |user|
|
432
|
+
passhash = Digest::SHA512.new.update(user_auth_salt).update(username).update(user[:password]).hexdigest
|
433
|
+
success ||= (passhash == password_digest)
|
434
|
+
end
|
435
|
+
unless success
|
436
|
+
log.warn "Authentication failed", address: remote_addr, hostname: hostname, username: username
|
437
|
+
return false, 'username/password mismatch', nil
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
return true, shared_key_salt, shared_key
|
442
|
+
end
|
443
|
+
|
444
|
+
def generate_pong(auth_result, reason_or_salt, nonce, shared_key)
|
445
|
+
log.debug "generating pong"
|
446
|
+
# ['PONG', bool(authentication result), 'reason if authentication failed', self_hostname, sha512_hex(salt + self_hostname + nonce + sharedkey)]
|
447
|
+
unless auth_result
|
448
|
+
return ['PONG', false, reason_or_salt, '', '']
|
449
|
+
end
|
450
|
+
|
451
|
+
shared_key_digest_hex = Digest::SHA512.new.update(reason_or_salt).update(@security.self_hostname).update(nonce).update(shared_key).hexdigest
|
452
|
+
['PONG', true, '', @security.self_hostname, shared_key_digest_hex]
|
453
|
+
end
|
454
|
+
end
|
455
|
+
end
|