Sha256: 3dff8e9a86421f96d5da694db5bdab1af19ff821ec08519201340abb339c35b2

Contents?: true

Size: 1.74 KB

Versions: 28

Compression:

Stored size: 1.74 KB

Contents

module LogStash; module Outputs; class ElasticSearch
  class TemplateManager
    # To be mixed into the elasticsearch plugin base
    def self.install_template(plugin)
      return unless plugin.manage_template
      plugin.logger.info("Using mapping template from", :path => plugin.template)
      template = get_template(plugin.template, get_es_major_version(plugin.client))
      plugin.logger.info("Attempting to install template", :manage_template => template)
      install(plugin.client, plugin.template_name, template, plugin.template_overwrite)
    rescue => e
      plugin.logger.error("Failed to install template.", :message => e.message, :class => e.class.name, :backtrace => e.backtrace)
    end

    private
    def self.get_es_version(client)
      client.get_version
    end

    def self.get_es_major_version(client)
      get_es_version(client)["number"][0]
    end

    def self.get_template(path, es_major_version)
      template_path = path || default_template_path(es_major_version)
      read_template_file(template_path)
    end

    def self.install(client, template_name, template, template_overwrite)
      client.template_install(template_name, template, template_overwrite)
    end

    def self.default_template_path(es_major_version)
      template_version = es_major_version == "1" ? "2" : es_major_version
      default_template_name = "elasticsearch-template-es#{template_version}x.json"
      ::File.expand_path(default_template_name, ::File.dirname(__FILE__))
    end

    def self.read_template_file(template_path)
      raise ArgumentError, "Template file '#{@template_path}' could not be found!" unless ::File.exists?(template_path)
      template_data = ::IO.read(template_path)
      LogStash::Json.load(template_data)
    end
  end
end end end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
logstash-output-elasticsearch-7.4.0-java lib/logstash/outputs/elasticsearch/template_manager.rb
logstash-output-elasticsearch-8.1.1-java lib/logstash/outputs/elasticsearch/template_manager.rb
logstash-output-elasticsearch-8.0.1-java lib/logstash/outputs/elasticsearch/template_manager.rb
logstash-output-elasticsearch-8.0.0-java lib/logstash/outputs/elasticsearch/template_manager.rb
logstash-output-elasticsearch-7.3.8-java lib/logstash/outputs/elasticsearch/template_manager.rb
logstash-output-elasticsearch-7.3.7-java lib/logstash/outputs/elasticsearch/template_manager.rb
logstash-output-elasticsearch-7.3.6-java lib/logstash/outputs/elasticsearch/template_manager.rb
logstash-output-elasticsearch-7.3.5-java lib/logstash/outputs/elasticsearch/template_manager.rb
logstash-output-elasticsearch-7.3.4-java lib/logstash/outputs/elasticsearch/template_manager.rb
logstash-output-elasticsearch-7.3.3-java lib/logstash/outputs/elasticsearch/template_manager.rb
logstash-output-elasticsearch-7.3.2-java lib/logstash/outputs/elasticsearch/template_manager.rb
logstash-output-elasticsearch-7.3.1-java lib/logstash/outputs/elasticsearch/template_manager.rb
logstash-output-elasticsearch-7.3.0-java lib/logstash/outputs/elasticsearch/template_manager.rb
logstash-output-elasticsearch-6.3.0-java lib/logstash/outputs/elasticsearch/template_manager.rb
logstash-output-elasticsearch-7.2.2-java lib/logstash/outputs/elasticsearch/template_manager.rb
logstash-output-elasticsearch-7.2.1-java lib/logstash/outputs/elasticsearch/template_manager.rb
logstash-output-elasticsearch-7.2.0-java lib/logstash/outputs/elasticsearch/template_manager.rb
logstash-output-elasticsearch-7.1.0-java lib/logstash/outputs/elasticsearch/template_manager.rb
logstash-output-elasticsearch-7.0.0-java lib/logstash/outputs/elasticsearch/template_manager.rb
logstash-output-elasticsearch-6.2.6-java lib/logstash/outputs/elasticsearch/template_manager.rb