Class: LogStash::Filters::JdbcStreaming

Inherits:
Base
  • Object
show all
Includes:
PluginMixins::Jdbc::Common, PluginMixins::JdbcStreaming
Defined in:
lib/logstash/filters/jdbc_streaming.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PluginMixins::JdbcStreaming

included, #prepare_jdbc_connection, #setup_jdbc_config

Instance Attribute Details

#prepared_statement_constant_warnedObject (readonly)

for test verification, remove when warning is deprecated and removed



100
101
102
# File 'lib/logstash/filters/jdbc_streaming.rb', line 100

def prepared_statement_constant_warned
  @prepared_statement_constant_warned
end

Instance Method Details

#closeObject



140
141
142
143
144
# File 'lib/logstash/filters/jdbc_streaming.rb', line 140

def close
  @database.disconnect
rescue => e
  logger.warn("Exception caught when attempting to close filter.", :exception => e.message, :backtrace => e.backtrace)
end

#filter(event) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/logstash/filters/jdbc_streaming.rb', line 125

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

#registerObject



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/logstash/filters/jdbc_streaming.rb', line 105

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