Class: LogStash::ElasticsearchClient::RubyClient
- Inherits:
-
Object
- Object
- LogStash::ElasticsearchClient::RubyClient
- Defined in:
- lib/logstash/elasticsearch_client.rb
Instance Method Summary collapse
- #can_connect? ⇒ Boolean
- #delete(path) ⇒ Object
- #head(path) ⇒ Object
- #host_settings ⇒ Object
-
#initialize(settings, logger) ⇒ RubyClient
constructor
A new instance of RubyClient.
- #put(path, content) ⇒ Object
Constructor Details
#initialize(settings, logger) ⇒ RubyClient
Returns a new instance of RubyClient.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/logstash/elasticsearch_client.rb', line 25 def initialize(settings, logger) @settings = settings @logger = logger @client_args = client_args = {} if @settings["var.elasticsearch.ssl.enabled"] == "true" [:verify] = @settings.fetch("var.elasticsearch.ssl.verification_mode", true) [:ca_file] = @settings.fetch("var.elasticsearch.ssl.certificate_authority", nil) [:client_cert] = @settings.fetch("var.elasticsearch.ssl.certificate", nil) [:client_key] = @settings.fetch("var.elasticsearch.ssl.key", nil) end @client_args[:ssl] = username = @settings["var.elasticsearch.username"] password = @settings["var.elasticsearch.password"] if username @client_args[:transport_options] = { :headers => { "Authorization" => 'Basic ' + Base64.encode64( "#{username}:#{password}" ).chomp } } end @client = Elasticsearch::Client.new(@client_args) end |
Instance Method Details
#can_connect? ⇒ Boolean
50 51 52 53 54 55 56 57 58 |
# File 'lib/logstash/elasticsearch_client.rb', line 50 def can_connect? begin head(SecureRandom.hex(32).prepend('_')) rescue Elasticsearch::Transport::Transport::Errors::BadRequest true rescue Manticore::SocketException false end end |
#delete(path) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/logstash/elasticsearch_client.rb', line 64 def delete(path) begin normalize_response(@client.perform_request('DELETE', path, {}, nil)) rescue Exception => e if is_404_error?(e) Response.new(404, "", {}) else raise e end end end |
#head(path) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/logstash/elasticsearch_client.rb', line 80 def head(path) begin normalize_response(@client.perform_request('HEAD', path, {}, nil)) rescue Exception => e if is_404_error?(e) Response.new(404, "", {}) else raise e end end end |
#host_settings ⇒ Object
60 61 62 |
# File 'lib/logstash/elasticsearch_client.rb', line 60 def host_settings @client_args[:hosts] end |
#put(path, content) ⇒ Object
76 77 78 |
# File 'lib/logstash/elasticsearch_client.rb', line 76 def put(path, content) normalize_response(@client.perform_request('PUT', path, {}, content)) end |