Module: LogStash::Outputs::ElasticSearch::HttpClientBuilder
- Defined in:
- lib/logstash/outputs/elasticsearch/http_client_builder.rb
Class Method Summary collapse
- .build(logger, hosts, params) ⇒ Object
- .setup_basic_auth(logger, params) ⇒ Object
- .setup_proxy(logger, params) ⇒ Object
- .setup_ssl(logger, params) ⇒ Object
Class Method Details
.build(logger, hosts, params) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/logstash/outputs/elasticsearch/http_client_builder.rb', line 3 def self.build(logger, hosts, params) client_settings = { :pool_max => params["pool_max"], :pool_max_per_route => params["pool_max_per_route"], :check_connection_timeout => params["validate_after_inactivity"] } = { :client_settings => client_settings, :resurrect_delay => params["resurrect_delay"], :healthcheck_path => params["healthcheck_path"] } if params["sniffing"] [:sniffing] = true [:sniffer_delay] = params["sniffing_delay"] end [:timeout] = params["timeout"] if params["timeout"] if params["path"] client_settings[:path] = "/#{params["path"]}/".gsub(/\/+/, "/") # Normalize slashes end if params["parameters"] client_settings[:parameters] = params["parameters"] end logger.debug? && logger.debug("Normalizing http path", :path => params["path"], :normalized => client_settings[:path]) client_settings.merge! setup_ssl(logger, params) client_settings.merge! setup_proxy(logger, params) .merge! setup_basic_auth(logger, params) # Update API setup raise( LogStash::ConfigurationError, "doc_as_upsert and scripted_upsert are mutually exclusive." ) if params["doc_as_upsert"] and params["scripted_upsert"] raise( LogStash::ConfigurationError, "Specifying action => 'update' needs a document_id." ) if params['action'] == 'update' and params.fetch('document_id', '') == '' # Update API setup = { :doc_as_upsert => params["doc_as_upsert"], :script_var_name => params["script_var_name"], :script_type => params["script_type"], :script_lang => params["script_lang"], :scripted_upsert => params["scripted_upsert"] } .merge! if params["action"] == 'update' LogStash::Outputs::ElasticSearch::HttpClient.new( .merge(:hosts => hosts, :logger => logger) ) end |
.setup_basic_auth(logger, params) ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/logstash/outputs/elasticsearch/http_client_builder.rb', line 116 def self.setup_basic_auth(logger, params) user, password = params["user"], params["password"] return {} unless user && password { :user => user, :password => password.value } end |
.setup_proxy(logger, params) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/logstash/outputs/elasticsearch/http_client_builder.rb', line 62 def self.setup_proxy(logger, params) proxy = params["proxy"] return {} unless proxy # Symbolize keys proxy = if proxy.is_a?(Hash) Hash[proxy.map {|k,v| [k.to_sym, v]}] elsif proxy.is_a?(String) proxy else raise LogStash::ConfigurationError, "Expected 'proxy' to be a string or hash, not '#{proxy}''!" end return {:proxy => proxy} end |
.setup_ssl(logger, params) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/logstash/outputs/elasticsearch/http_client_builder.rb', line 78 def self.setup_ssl(logger, params) # If we have HTTPS hosts we act like SSL is enabled params["ssl"] = true if params["hosts"].any? {|h| h.start_with?("https://")} return {} if params["ssl"].nil? return {:ssl => {:enabled => false}} if params["ssl"] == false cacert, truststore, truststore_password, keystore, keystore_password = params.values_at('cacert', 'truststore', 'truststore_password', 'keystore', 'keystore_password') if cacert && truststore raise(LogStash::ConfigurationError, "Use either \"cacert\" or \"truststore\" when configuring the CA certificate") if truststore end = {:enabled => true} if cacert [:ca_file] = cacert elsif truststore [:truststore_password] = truststore_password.value if truststore_password end [:truststore] = truststore if truststore if keystore [:keystore] = keystore [:keystore_password] = keystore_password.value if keystore_password end if !params["ssl_certificate_verification"] logger.warn [ "** WARNING ** Detected UNSAFE options in elasticsearch output configuration!", "** WARNING ** You have enabled encryption but DISABLED certificate verification.", "** WARNING ** To make sure your data is secure change :ssl_certificate_verification to true" ].join("\n") [:verify] = false end { ssl: } end |