class LogStash::Filters::SingleValueUpdate
Public Class Methods
new(field, destination, fallback, lookup)
click to toggle source
# File lib/logstash/filters/single_value_update.rb, line 15 def initialize(field, destination, fallback, lookup) @field = field @destination = destination @fallback = fallback @use_fallback = !fallback.nil? # fallback is not nil, the user set a value in the config @lookup = lookup @coercers_table = {} @coercers_table.default = CoerceOther.new @coercers_table[String] = CoerceString.new @coercers_table[Array] = CoerceArray.new end
Public Instance Methods
test_for_inclusion(event, override)
click to toggle source
# File lib/logstash/filters/single_value_update.rb, line 27 def test_for_inclusion(event, override) # Skip translation in case @destination field already exists and @override is disabled. return false if !override && event.include?(@destination) event.include?(@field) end
update(event)
click to toggle source
# File lib/logstash/filters/single_value_update.rb, line 33 def update(event) # If source field is array use first value and make sure source value is string # source = Array(event.get(@field)).first.to_s source = event.get(@field) source = @coercers_table[source.class].call(source) matched = [true, nil] @lookup.fetch_strategy.fetch(source, matched) if matched.first event.set(@destination, matched.last) elsif @use_fallback event.set(@destination, event.sprintf(@fallback)) matched[0] = true end return matched.first end