diff --git a/lib/logstash/agent.rb b/lib/logstash/agent.rb index 0a6ce1da6..82fc2aa46 100644 --- a/lib/logstash/agent.rb +++ b/lib/logstash/agent.rb @@ -2,7 +2,8 @@ require "clamp" # gem 'clamp' require "logstash/environment" require "logstash/errors" -require "logstash/environment" +require "uri" +require "net/http" LogStash::Environment.load_locale! class LogStash::Agent < Clamp::Command @@ -286,6 +287,21 @@ class LogStash::Agent < Clamp::Command end # def configure_plugin_path def load_config(path) + + uri = URI.parse(path) + case uri.scheme + when nil then + local_config(path) + when /http/ then + fetch_config(uri) + when "file" then + local_config(uri.path) + else + fail(I18n.t("logstash.agent.configuration.scheme-not-supported", :path => path)) + end + end + + def local_config(path) path = File.join(path, "*") if File.directory?(path) if Dir.glob(path).length == 0 @@ -305,4 +321,12 @@ class LogStash::Agent < Clamp::Command return config end # def load_config + def fetch_config(uri) + begin + Net::HTTP.get(uri) + "\n" + rescue Exception => e + fail(I18n.t("logstash.agent.configuration.fetch-failed", :path => uri.to_s, :message => e.message)) + end + end + end # class LogStash::Agent diff --git a/locales/en.yml b/locales/en.yml index defe6e78d..f9a112ce6 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -69,6 +69,12 @@ en: file-not-found: |- No config files found: %{path} Can you make sure this path is a logstash config file? + scheme-not-supported: |- + URI scheme not supported: %{path} + Either pass a local file path or "file|http://" URI + fetch-failed: |- + Unable to fetch config from: %{path} + Reason: %{message} setting_missing: |- Missing a required setting for the %{plugin} %{type} plugin: