Class: LogStash::Modules::LogStashConfig
- Inherits:
-
Object
- Object
- LogStash::Modules::LogStashConfig
- Defined in:
- lib/logstash/modules/logstash_config.rb
Instance Method Summary collapse
- #config_string ⇒ Object
- #elasticsearch_output_config(type_string = nil) ⇒ Object
-
#initialize(modul, settings) ⇒ LogStashConfig
constructor
We name it ‘modul` here because `module` has meaning in Ruby.
- #setting(value, default) ⇒ Object
- #template ⇒ Object
Constructor Details
#initialize(modul, settings) ⇒ LogStashConfig
We name it ‘modul` here because `module` has meaning in Ruby.
8 9 10 11 12 |
# File 'lib/logstash/modules/logstash_config.rb', line 8 def initialize(modul, settings) @directory = ::File.join(modul.directory, "logstash") @name = modul.module_name @settings = settings end |
Instance Method Details
#config_string ⇒ Object
42 43 44 45 46 47 |
# File 'lib/logstash/modules/logstash_config.rb', line 42 def config_string # process the template and settings # send back as a string renderer = ERB.new(FileReader.read(template)) renderer.result(binding) end |
#elasticsearch_output_config(type_string = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/logstash/modules/logstash_config.rb', line 22 def elasticsearch_output_config(type_string = nil) hosts = setting("var.output.elasticsearch.hosts", "localhost:9200").split(',').map do |s| '"' + s.strip + '"' end.join(',') index = "#{@name}-#{setting("var.output.elasticsearch.index_suffix", "%{+YYYY.MM.dd}")}" password = "#{setting("var.output.elasticsearch.password", "changeme")}" user = "#{setting("var.output.elasticsearch.user", "elastic")}" document_type_line = type_string ? "document_type => #{type_string}" : "" <<-CONF elasticsearch { hosts => [#{hosts}] index => "#{index}" password => "#{password}" user => "#{user}" manage_template => false #{document_type_line} } CONF end |
#setting(value, default) ⇒ Object
18 19 20 |
# File 'lib/logstash/modules/logstash_config.rb', line 18 def setting(value, default) @settings.fetch(value, default) end |
#template ⇒ Object
14 15 16 |
# File 'lib/logstash/modules/logstash_config.rb', line 14 def template ::File.join(@directory, "#{@name}.conf.erb") end |