Class: LogStash::Config::AST::PluginSection

Inherits:
Node
  • Object
show all
Defined in:
lib/logstash/config/config_ast.rb

Constant Summary

Constants included from LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers

LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers::AND_METHOD, LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers::BOOLEAN_DSL_METHOD_SIGNATURE, LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers::NAND_METHOD, LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers::OR_METHOD, LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers::XOR_METHOD

Instance Method Summary collapse

Methods inherited from Node

#text_value_for_comments

Methods included from LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers

#base_id, #base_protocol, #base_source_with_metadata, #base_source_with_metadata=, #compose, #compose_for, #jdsl, jdsl, #line_and_column, #source_meta

Constructor Details

#initialize(*args) ⇒ PluginSection

Global plugin numbering for the janky instance variable naming we use like @filter_<name>_1



105
106
107
# File 'lib/logstash/config/config_ast.rb', line 105

def initialize(*args)
  super(*args)
end

Instance Method Details

#compile_initializerObject

Generate ruby code to initialize all the plugins.



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/logstash/config/config_ast.rb', line 110

def compile_initializer
  generate_variables
  code = []
  @variables.each do |plugin, name|


    code << <<-CODE
      @generated_objects[:#{name}] = #{plugin.compile_initializer}
      @#{plugin.plugin_type}s << @generated_objects[:#{name}]
    CODE

    # The flush method for this filter.
    if plugin.plugin_type == "filter"

      code << <<-CODE
        @generated_objects[:#{name}_flush] = lambda do |options, &block|
          @logger.debug? && @logger.debug(\"Flushing\", :plugin => @generated_objects[:#{name}])

          events = @generated_objects[:#{name}].flush(options)

          return if events.nil? || events.empty?

          @logger.debug? && @logger.debug(\"Flushing\", :plugin => @generated_objects[:#{name}], :events => events.map { |x| x.to_hash  })

          #{plugin.compile_starting_here.gsub(/^/, "  ")}

          events.each{|e| block.call(e)}
        end

        if !@generated_objects[:#{name}].nil? && @generated_objects[:#{name}].has_flush
          @periodic_flushers << @generated_objects[:#{name}_flush] if @generated_objects[:#{name}].periodic_flush
          @shutdown_flushers << @generated_objects[:#{name}_flush]
        end
      CODE

    end
  end
  return code.join("\n")
end

#generate_variablesObject



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/logstash/config/config_ast.rb', line 155

def generate_variables
  return if !@variables.nil?
  @variables = {}
  plugins = recursive_select(Plugin)

  plugins.each do |plugin|
    # Unique number for every plugin.
    LogStash::Config::AST.plugin_instance_index += 1
    # store things as ivars, like @filter_grok_3
    var = :"#{plugin.plugin_type}_#{plugin.plugin_name}_#{LogStash::Config::AST.plugin_instance_index}"
    # puts("var=#{var.inspect}")
    @variables[plugin] = var
  end
  return @variables
end

#variable(object) ⇒ Object



150
151
152
153
# File 'lib/logstash/config/config_ast.rb', line 150

def variable(object)
  generate_variables
  return @variables[object]
end