class LogStash::Filters::JdbcStreaming
Attributes
prepared_statement_constant_warned[R]
Public Instance Methods
close()
click to toggle source
# File lib/logstash/filters/jdbc_streaming.rb, line 138 def close @database.disconnect rescue => e logger.warn("Exception caught when attempting to close filter.", :exception => e.message, :backtrace => e.backtrace) end
filter(event)
click to toggle source
# File lib/logstash/filters/jdbc_streaming.rb, line 123 def filter(event) result = @statement_handler.cache_lookup(@database, event) # should return a CachePayload instance if result.failed? tag_failure(event) end if result.empty? tag_default(event) process_event(event, @default_array) else process_event(event, result.payload) end end
register()
click to toggle source
# File lib/logstash/filters/jdbc_streaming.rb, line 103 def register convert_config_options if @use_prepared_statements validation_errors = validate_prepared_statement_mode unless validation_errors.empty? raise(LogStash::ConfigurationError, "Prepared Statement Mode validation errors: " + validation_errors.join(", ")) end else # symbolise and wrap value in parameter handler unless @parameters.values.all?{|v| v.is_a?(PluginMixins::JdbcStreaming::ParameterHandler)} @parameters = parameters.inject({}) do |hash,(k,value)| hash[k.to_sym] = PluginMixins::JdbcStreaming::ParameterHandler.build_parameter_handler(value) hash end end end @statement_handler = LogStash::PluginMixins::JdbcStreaming::StatementHandler.build_statement_handler(self) prepare_jdbc_connection end
Private Instance Methods
convert_config_options()
click to toggle source
# File lib/logstash/filters/jdbc_streaming.rb, line 165 def convert_config_options # create these object once they will be cloned for every filter call anyway, # lets not create a new object for each @default_array = [@default_hash] end
process_event(event, value)
click to toggle source
# File lib/logstash/filters/jdbc_streaming.rb, line 159 def process_event(event, value) # use deep clone here so other filter function don't taint the cached payload by reference event.set(@target, ::LogStash::Util.deep_clone(value)) filter_matched(event) end
tag_default(event)
click to toggle source
# File lib/logstash/filters/jdbc_streaming.rb, line 153 def tag_default(event) @tag_on_default_use.each do |tag| event.tag(tag) end end
tag_failure(event)
click to toggle source
# File lib/logstash/filters/jdbc_streaming.rb, line 147 def tag_failure(event) @tag_on_failure.each do |tag| event.tag(tag) end end
validate_prepared_statement_mode()
click to toggle source
# File lib/logstash/filters/jdbc_streaming.rb, line 171 def validate_prepared_statement_mode @prepared_statement_constant_warned = false error_messages = [] if @prepared_statement_name.empty? error_messages << "must provide a name for the Prepared Statement, it must be unique for the db session" end if @statement.count("?") != @prepared_statement_bind_values.size # mismatch in number of bind value elements to placeholder characters error_messages << "there is a mismatch between the number of statement `?` placeholders and :prepared_statement_bind_values array setting elements" end unless @prepared_statement_bind_values.all?{|v| v.is_a?(PluginMixins::JdbcStreaming::ParameterHandler)} @prepared_statement_bind_values = prepared_statement_bind_values.map do |value| ParameterHandler.build_bind_value_handler(value) end end if prepared_statement_warn_on_constant_usage warnables = @prepared_statement_bind_values.select {|handler| handler.is_a?(PluginMixins::JdbcStreaming::ConstantParameter) && handler.given_value.is_a?(String)} unless warnables.empty? @prepared_statement_constant_warned = true msg = "When using prepared statements, the following `prepared_statement_bind_values` will be treated as constants, if you intend them to be field references please use the square bracket field reference syntax e.g. '[field]'" logger.warn(msg, :constants => warnables) end end error_messages end