Sha256: 78456d0243925c032a094d58cec34a41762298ccbd945cf8261d173543f1f69f

Contents?: true

Size: 1.24 KB

Versions: 38

Compression:

Stored size: 1.24 KB

Contents

module Fluent::ElasticsearchIndexTemplate

  def get_template(template_file)
    if !File.exists?(template_file)
      raise "If you specify a template_name you must specify a valid template file (checked '#{template_file}')!"
    end
    file_contents = IO.read(template_file).gsub(/\n/,'')
    JSON.parse(file_contents)
  end

  def template_exists?(name)
    client.indices.get_template(:name => name)
    return true
  rescue Elasticsearch::Transport::Transport::Errors::NotFound
    return false
  end

  def template_put(name, template)
    client.indices.put_template(:name => name, :body => template)
  end

  def template_install(name, template_file, overwrite)
    if overwrite
      template_put(name, get_template(template_file))
      log.info("Template '#{name}' overwritten with #{template_file}.")
      return
    end
    if !template_exists?(name)
      template_put(name, get_template(template_file))
      log.info("Template configured, but no template installed. Installed '#{name}' from #{template_file}.")
    else
      log.info("Template configured and already installed.")
    end
  end

  def templates_hash_install(templates, overwrite)
    templates.each do |key, value|
      template_install(key, value, overwrite)
    end
  end

end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
fluent-plugin-elasticsearch-1.18.2 lib/fluent/plugin/elasticsearch_index_template.rb
fluent-plugin-elasticsearch-1.18.1 lib/fluent/plugin/elasticsearch_index_template.rb
fluent-plugin-elasticsearch-1.18.0 lib/fluent/plugin/elasticsearch_index_template.rb
fluent-plugin-elasticsearch-1.17.2 lib/fluent/plugin/elasticsearch_index_template.rb
fluent-plugin-elasticsearch-1.17.1 lib/fluent/plugin/elasticsearch_index_template.rb
fluent-plugin-elasticsearch-1.17.0 lib/fluent/plugin/elasticsearch_index_template.rb
fluent-plugin-elasticsearch-1.16.2 lib/fluent/plugin/elasticsearch_index_template.rb
fluent-plugin-elasticsearch-2.10.2 lib/fluent/plugin/elasticsearch_index_template.rb
fluent-plugin-elasticsearch-2.10.1 lib/fluent/plugin/elasticsearch_index_template.rb
fluent-plugin-elasticsearch-1.16.1 lib/fluent/plugin/elasticsearch_index_template.rb
fluent-plugin-elasticsearch-2.10.0 lib/fluent/plugin/elasticsearch_index_template.rb
fluent-plugin-elasticsearch-1.16.0 lib/fluent/plugin/elasticsearch_index_template.rb
fluent-plugin-elasticsearch-2.9.2 lib/fluent/plugin/elasticsearch_index_template.rb
fluent-plugin-elasticsearch-1.15.2 lib/fluent/plugin/elasticsearch_index_template.rb
fluent-plugin-elasticsearch-2.9.1 lib/fluent/plugin/elasticsearch_index_template.rb
fluent-plugin-elasticsearch-1.15.1 lib/fluent/plugin/elasticsearch_index_template.rb
fluent-plugin-elasticsearch-2.9.0 lib/fluent/plugin/elasticsearch_index_template.rb
fluent-plugin-elasticsearch-1.15.0 lib/fluent/plugin/elasticsearch_index_template.rb
fluent-plugin-elasticsearch-1.14.0 lib/fluent/plugin/elasticsearch_index_template.rb
fluent-plugin-elasticsearch-1.13.4 lib/fluent/plugin/elasticsearch_index_template.rb