mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 22:27:21 -04:00
Fallback to a local configuration if the parsing for remote configuration fails
Fixes #2653
This commit is contained in:
parent
10938a5ee4
commit
a67d4c2b51
2 changed files with 53 additions and 9 deletions
|
@ -294,17 +294,24 @@ class LogStash::Agent < Clamp::Command
|
|||
end # def configure_plugin_path
|
||||
|
||||
def load_config(path)
|
||||
begin
|
||||
uri = URI.parse(path)
|
||||
|
||||
uri = URI.parse(path)
|
||||
case uri.scheme
|
||||
when nil then
|
||||
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
|
||||
rescue URI::InvalidURIError
|
||||
# fallback for windows.
|
||||
# if the parsing of the file failed we assume we can reach it locally.
|
||||
# some relative path on windows arent parsed correctly (.\logstash.conf)
|
||||
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
|
||||
|
||||
|
|
37
spec/logstash/agent_spec.rb
Normal file
37
spec/logstash/agent_spec.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe LogStash::Agent do
|
||||
subject { LogStash::Agent.new('') }
|
||||
let(:dummy_config) { 'input {}' }
|
||||
|
||||
context "when loading the configuration" do
|
||||
context "when local" do
|
||||
before { expect(subject).to receive(:local_config).with(path) }
|
||||
|
||||
context "unix" do
|
||||
let(:path) { './test.conf' }
|
||||
it 'works with relative path' do
|
||||
subject.load_config(path)
|
||||
end
|
||||
end
|
||||
|
||||
context "windows" do
|
||||
let(:path) { '.\test.conf' }
|
||||
it 'work with relative windows path' do
|
||||
subject.load_config(path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when remote" do
|
||||
context 'supported scheme' do
|
||||
let(:path) { "http://test.local/superconfig.conf" }
|
||||
|
||||
before { expect(Net::HTTP).to receive(:get) { dummy_config } }
|
||||
it 'works with http' do
|
||||
expect(subject.load_config(path)).to eq("#{dummy_config}\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue