Sha256: f4a44bf985ab86b3cce3c7a3fb31a49fd414bd281ace7996e53661ce70c424fc

Contents?: true

Size: 1.34 KB

Versions: 16

Compression:

Stored size: 1.34 KB

Contents

#
# DESCRIPTION:
#   Common helper methods
#
# DEPENDENCIES:
#   gem: elasticsearch
#   gem: sensu-plugin
#
# USAGE:
#
# NOTES:
#
# LICENSE:
#   Brendan Gibat <brendan.gibat@gmail.com>
#   Released under the same terms as Sensu (the MIT license); see LICENSE
#   for details.
#

require_relative 'elasticsearch-query.rb'

module ElasticsearchCommon
  include ElasticsearchQuery
  def initialize
    super()
  end

  def client
    transport_class = nil
    if config[:transport] == 'AWS'
      transport_class = Elasticsearch::Transport::Transport::HTTP::AWS
    end

    host = {
      host:               config[:host],
      port:               config[:port],
      request_timeout:    config[:timeout],
      scheme:             config[:scheme]
    }

    if !config[:user].nil? && !config[:password].nil?
      host[:user] = config[:user]
      host[:password] = config[:password]
      host[:scheme] = 'https' unless config[:scheme]
    end

    transport_options = {}

    if config[:headers]

      headers = {}

      config[:headers].split(',').each do |header|
        h, v = header.split(':', 2)
        headers[h.strip] = v.strip
      end

      transport_options[:headers] = headers

    end

    @client ||= Elasticsearch::Client.new(transport_class: transport_class, hosts: [host], region: config[:region], transport_options: transport_options)
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
sensu-plugins-elasticsearch-boutetnico-1.1.1 lib/sensu-plugins-elasticsearch/elasticsearch-common.rb
sensu-plugins-elasticsearch-boutetnico-1.0.5 lib/sensu-plugins-elasticsearch/elasticsearch-common.rb
sensu-plugins-elasticsearch-4.2.2 lib/sensu-plugins-elasticsearch/elasticsearch-common.rb
sensu-plugins-elasticsearch-4.2.1 lib/sensu-plugins-elasticsearch/elasticsearch-common.rb
sensu-plugins-elasticsearch-boutetnico-1.0.4 lib/sensu-plugins-elasticsearch/elasticsearch-common.rb
sensu-plugins-elasticsearch-4.2.0 lib/sensu-plugins-elasticsearch/elasticsearch-common.rb
sensu-plugins-elasticsearch-4.1.0 lib/sensu-plugins-elasticsearch/elasticsearch-common.rb
sensu-plugins-elasticsearch-4.0.1 lib/sensu-plugins-elasticsearch/elasticsearch-common.rb
sensu-plugins-elasticsearch-4.0.0 lib/sensu-plugins-elasticsearch/elasticsearch-common.rb
sensu-plugins-elasticsearch-3.0.0 lib/sensu-plugins-elasticsearch/elasticsearch-common.rb
sensu-plugins-elasticsearch-2.1.0 lib/sensu-plugins-elasticsearch/elasticsearch-common.rb
sensu-plugins-elasticsearch-2.0.1 lib/sensu-plugins-elasticsearch/elasticsearch-common.rb
sensu-plugins-elasticsearch-2.0.0 lib/sensu-plugins-elasticsearch/elasticsearch-common.rb
sensu-plugins-elasticsearch-1.12.0 lib/sensu-plugins-elasticsearch/elasticsearch-common.rb
sensu-plugins-elasticsearch-1.11.1 lib/sensu-plugins-elasticsearch/elasticsearch-common.rb
sensu-plugins-elasticsearch-1.11.0 lib/sensu-plugins-elasticsearch/elasticsearch-common.rb