19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/logstash/outputs/elastic_app_search.rb', line 19
def register
if @host.nil? && @url.nil?
raise ::LogStash::ConfigurationError.new("Please specify either \"url\" (for self-managed) or \"host\" (for SaaS).")
elsif @host && @url
raise ::LogStash::ConfigurationError.new("Both \"url\" or \"host\" can't be set simultaneously. Please specify either \"url\" (for self-managed) or \"host\" (for SaaS).")
elsif @host && path_is_set? raise ::LogStash::ConfigurationError.new("The setting \"path\" is not compatible with \"host\". Use \"path\" only with \"url\".")
elsif @host
@client = Elastic::AppSearch::Client.new(:host_identifier => @host, :api_key => @api_key.value)
elsif @url
@client = Elastic::AppSearch::Client.new(:api_endpoint => @url + @path, :api_key => @api_key.value)
end
check_connection! unless @engine =~ ENGINE_WITH_SPRINTF_REGEX
rescue => e
if e.message =~ /401/
raise ::LogStash::ConfigurationError.new("Failed to connect to App Search. Error: 401. Please check your credentials")
elsif e.message =~ /404/
raise ::LogStash::ConfigurationError.new("Failed to connect to App Search. Error: 404. Please check if host '#{@host}' is correct and you've created an engine with name '#{@engine}'")
else
raise ::LogStash::ConfigurationError.new("Failed to connect to App Search. #{e.message}")
end
end
|