Class: LogStash::Filters::Jdbc::Lookup
- Inherits:
-
Object
- Object
- LogStash::Filters::Jdbc::Lookup
- Includes:
- PluginMixins::Jdbc::ValueHandler, Util::Loggable
- Defined in:
- lib/logstash/filters/jdbc/lookup.rb
Defined Under Namespace
Classes: Getfier, Sprintfier
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Class Method Summary collapse
Instance Method Summary collapse
- #enhance(local, event) ⇒ Object
- #formatted_errors ⇒ Object
- #id_used_as_target? ⇒ Boolean
-
#initialize(options, globals, default_id) ⇒ Lookup
constructor
A new instance of Lookup.
- #prepare(local) ⇒ Object
- #use_prepared_statement? ⇒ Boolean
- #valid? ⇒ Boolean
Methods included from PluginMixins::Jdbc::ValueHandler
#decorate_value, #extract_values_from
Constructor Details
#initialize(options, globals, default_id) ⇒ Lookup
Returns a new instance of Lookup.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/logstash/filters/jdbc/lookup.rb', line 56 def initialize(, globals, default_id) @id = ["id"] || default_id @target = ["target"] @id_used_as_target = @target.nil? if @id_used_as_target # target shouldn't be nil if ecs_compatibility is not :disabled if globals[:ecs_compatibility] != :disabled logger.info('ECS compatibility is enabled but no ``target`` option was specified, it is recommended'\ ' to set the option to avoid potential schema conflicts (if your data is ECS compliant or'\ ' non-conflicting feel free to ignore this message)') end @target = @id end @options = @globals = globals @valid = false @option_errors = [] @default_result = nil @prepared_statement = nil @symbol_parameters = nil @load_method_ref = method(:load_data_from_local) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
54 55 56 |
# File 'lib/logstash/filters/jdbc/lookup.rb', line 54 def id @id end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
54 55 56 |
# File 'lib/logstash/filters/jdbc/lookup.rb', line 54 def parameters @parameters end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
54 55 56 |
# File 'lib/logstash/filters/jdbc/lookup.rb', line 54 def query @query end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
54 55 56 |
# File 'lib/logstash/filters/jdbc/lookup.rb', line 54 def target @target end |
Class Method Details
.find_validation_errors(array_of_options) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/logstash/filters/jdbc/lookup.rb', line 39 def self.find_validation_errors() if !.is_a?(Array) return "The options must be an Array" end errors = [] .each_with_index do |, i| instance = new(, {}, "lookup-#{i.next}") unless instance.valid? errors << instance.formatted_errors end end return nil if errors.empty? errors.join("; ") end |
Instance Method Details
#enhance(local, event) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/logstash/filters/jdbc/lookup.rb', line 92 def enhance(local, event) result = retrieve_local_data(local, event, &@load_method_ref) # return a LookupResult if result.failed? || result.parameters_invalid? tag_failure(event) end if result.valid? if @use_default && result.empty? tag_default(event) process_event(event, @default_result) else process_event(event, result) end true else false end end |
#formatted_errors ⇒ Object
88 89 90 |
# File 'lib/logstash/filters/jdbc/lookup.rb', line 88 def formatted_errors @option_errors.join(", ") end |
#id_used_as_target? ⇒ Boolean
80 81 82 |
# File 'lib/logstash/filters/jdbc/lookup.rb', line 80 def id_used_as_target? @id_used_as_target end |
#prepare(local) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/logstash/filters/jdbc/lookup.rb', line 115 def prepare(local) hash = {} @prepared_parameters.each_with_index { |v, i| hash[:"$p#{i}"] = v } @prepared_param_placeholder_map = hash @prepared_statement = local.prepare(query, hash.keys) @load_method_ref = method(:load_data_from_prepared) end |
#use_prepared_statement? ⇒ Boolean
111 112 113 |
# File 'lib/logstash/filters/jdbc/lookup.rb', line 111 def use_prepared_statement? @prepared_parameters && !@prepared_parameters.empty? end |
#valid? ⇒ Boolean
84 85 86 |
# File 'lib/logstash/filters/jdbc/lookup.rb', line 84 def valid? @valid end |