Skip to content

Manage template fails if settings section is missing #11893

@tmanninger

Description

@tmanninger
  • Version: 7.6.1
  • Operating System: Debian 10

If the logstash output plugin "elasticsearch" manage the lifecycle management, adding lifecycle settings to the template fails, if template have no "settings" section declared.

logstash output plugin:

output {
      elasticsearch {
          hosts =>  [ 'https://localhost:9200' ]
          ilm_enabled => true
          ilm_rollover_alias => "syslog"
          ilm_pattern => "{now/d}-000001"
          ilm_policy => "long"
          manage_template => true
          template => "/etc/logstash/template.d/syslog.json"
          template_name => "syslog"
          template_overwrite => true
          ....
      }
}

If the template file /etc/logstash/template.d/syslog.json have no "settings {}" section declared, logstash fails with the following error:

Failed to install template. {:message=>"undefined method `update' for nil:NilClass", :class=>"NoMethodError", :backtrace=>["/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-output-elasticsearch-10.3.1-java/lib/logstash/outputs/elasticsearch/template_manager.rb:39:in `add_ilm_settings_to_template'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-output-elasticsearch-10.3.1-java/lib/logstash/outputs/elasticsearch/template_manager.rb:14:in `install_template'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-output-elasticsearch-10.3.1-java/lib/logstash/outputs/elasticsearch/common.rb:197:in `install_template'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-output-elasticsearch-10.3.1-java/lib/logstash/outputs/elasticsearch/common.rb:53:in `block in setup_after_successful_connection'"]}

If i add an empty settings section to the template, then it works:

{
  "settings" : { },
   ....
}

See vendor/bundle/jruby/2.5.0/gems/logstash-output-elasticsearch-10.3.1-java/lib/logstash/outputs/elasticsearch/template_manager.rb on line 39:

      # Overwrite any index patterns, and use the rollover alias. Use 'index_patterns' rather than 'template' for pattern
      # definition - remove any existing definition of 'template'
      template.delete('template') if template.include?('template')
      template['index_patterns'] = "#{plugin.ilm_rollover_alias}-*"
      if template['settings'] && (template['settings']['index.lifecycle.name'] || template['settings']['index.lifecycle.rollover_alias'])
        plugin.logger.info("Overwriting index lifecycle name and rollover alias as ILM is enabled.")
      end
      template['settings'].update({ 'index.lifecycle.name' => plugin.ilm_policy, 'index.lifecycle.rollover_alias' => plugin.ilm_rollover_alias})
    end

Logstash assumes, that the "settings" part exists. Before add the lifecycle settings, it must be checked, if the settings part exists...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions