Class: LogStash::Filters::Jdbc::Lookup

Inherits:
Object
  • Object
show all
Includes:
Util::Loggable
Defined in:
lib/logstash/filters/jdbc/lookup.rb

Defined Under Namespace

Classes: Getfier, Sprintfier

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, globals, default_id) ⇒ Lookup

Returns a new instance of Lookup.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/logstash/filters/jdbc/lookup.rb', line 54

def initialize(options, globals, default_id)
  @id = options["id"] || default_id
  @target = options["target"]
  @id_used_as_target = @target.nil?
  if @id_used_as_target
    @target = @id
  end
  @options = options
  @globals = globals
  @valid = false
  @option_errors = []
  @default_result = nil
  parse_options
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



52
53
54
# File 'lib/logstash/filters/jdbc/lookup.rb', line 52

def id
  @id
end

#parametersObject (readonly)

Returns the value of attribute parameters.



52
53
54
# File 'lib/logstash/filters/jdbc/lookup.rb', line 52

def parameters
  @parameters
end

#queryObject (readonly)

Returns the value of attribute query.



52
53
54
# File 'lib/logstash/filters/jdbc/lookup.rb', line 52

def query
  @query
end

#targetObject (readonly)

Returns the value of attribute target.



52
53
54
# File 'lib/logstash/filters/jdbc/lookup.rb', line 52

def target
  @target
end

Class Method Details

.find_validation_errors(array_of_options) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/logstash/filters/jdbc/lookup.rb', line 37

def self.find_validation_errors(array_of_options)
  if !array_of_options.is_a?(Array)
    return "The options must be an Array"
    end
  errors = []
  array_of_options.each_with_index do |options, i|
    instance = new(options, {}, "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



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/logstash/filters/jdbc/lookup.rb', line 81

def enhance(local, event)
  result = fetch(local, event) # should 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_errorsObject



77
78
79
# File 'lib/logstash/filters/jdbc/lookup.rb', line 77

def formatted_errors
  @option_errors.join(", ")
end

#id_used_as_target?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/logstash/filters/jdbc/lookup.rb', line 69

def id_used_as_target?
  @id_used_as_target
end

#valid?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/logstash/filters/jdbc/lookup.rb', line 73

def valid?
  @valid
end