From 06c97acea7ca5843d08a51518ade22b3fcf076d2 Mon Sep 17 00:00:00 2001 From: Guy Boertje Date: Tue, 6 Jun 2017 17:38:16 +0100 Subject: [PATCH] use common --- .../lib/logstash/config/source/modules.rb | 37 +++---------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/logstash-core/lib/logstash/config/source/modules.rb b/logstash-core/lib/logstash/config/source/modules.rb index 32ba22613..985bf2114 100644 --- a/logstash-core/lib/logstash/config/source/modules.rb +++ b/logstash-core/lib/logstash/config/source/modules.rb @@ -1,5 +1,6 @@ # encoding: utf-8 require "logstash/config/source/base" +require "logstash/config/modules_common" require "logstash/config/pipeline_config" require "logstash/util/loggable" require "logstash/elasticsearch_client" @@ -10,38 +11,12 @@ module LogStash module Config module Source class Modules < Base include LogStash::Util::Loggable def pipeline_configs - pipelines = [] - plugin_modules = LogStash::PLUGIN_REGISTRY.plugins_with_type(:modules) - - modules_array = @settings.get("modules.cli").empty? ? @settings.get("modules") : @settings.get("modules.cli") - logger.debug("Configured modules", :modules_array => modules_array.to_s) - module_names = [] - module_names = modules_array.collect {|module_hash| module_hash["name"]} - if module_names.length > module_names.uniq.length - duplicate_modules = module_names.group_by(&:to_s).select { |_,v| v.size > 1 }.keys - raise LogStash::ConfigLoadingError, I18n.t("logstash.modules.configuration.modules-must-be-unique", :duplicate_modules => duplicate_modules) + pipelines = LogStash::Config::ModulesCommon.pipeline_configs(@settings) + pipelines.map do |hash| + PipelineConfig.new(self, hash["pipeline_id"].to_sym, + org.logstash.common.SourceWithMetadata.new("module", hash["alt_name"], hash["config_string"]), + hash["settings"]) end - ### Here is where we can force the modules_array to use only [0] for 5.5, and leave - ### a warning/error message to that effect. - modules_array.each do |module_hash| - begin - import_engine = LogStash::Modules::Importer.new(LogStash::ElasticsearchClient.build(module_hash)) - - current_module = plugin_modules.find { |allmodules| allmodules.module_name == module_hash["name"] } - alt_name = "module-#{module_hash["name"]}" - pipeline_id = alt_name - - current_module.with_settings(module_hash) - current_module.import(import_engine) - config_string = current_module.config_string - - config_part = org.logstash.common.SourceWithMetadata.new("module", alt_name, config_string) - pipelines << PipelineConfig.new(self, pipeline_id.to_sym, config_part, @settings) - rescue => e - raise LogStash::ConfigLoadingError, I18n.t("logstash.modules.configuration.parse-failed", :error => e.message) - end - end - pipelines end def match?