Sha256: ed911ae0f56e2009b640c9d2d632cf9b378b2a61e7c97e711a04c9a41d853d3a

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

Contents

# encoding: utf-8
require "elasticsearch"
require "base64"


module LogStash
  module Filters
    class ElasticsearchClient

      attr_reader :client

      def initialize(user, password, options={})
        ssl     = options.fetch(:ssl, false)
        hosts   = options[:hosts]
        @logger = options[:logger]

        transport_options = {}
        if user && password
          token = ::Base64.strict_encode64("#{user}:#{password.value}")
          transport_options[:headers] = { Authorization: "Basic #{token}" }
        end

        hosts.map! {|h| { host: h, scheme: 'https' } } if ssl
        # set ca_file even if ssl isn't on, since the host can be an https url
        transport_options[:ssl] = { ca_file: options[:ca_file] } if options[:ca_file]

        @logger.info("New ElasticSearch filter client", :hosts => hosts)
        @client = ::Elasticsearch::Client.new(hosts: hosts, transport_options: transport_options)
      end

      def search(params)
        @client.search(params)
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
logstash-filter-elasticsearch-3.4.0 lib/logstash/filters/elasticsearch/client.rb
logstash-filter-elasticsearch-3.3.1 lib/logstash/filters/elasticsearch/client.rb
logstash-filter-elasticsearch-3.3.0 lib/logstash/filters/elasticsearch/client.rb
logstash-filter-elasticsearch-3.2.1 lib/logstash/filters/elasticsearch/client.rb
logstash-filter-elasticsearch-3.2.0 lib/logstash/filters/elasticsearch/client.rb