Sha256: 520f9c820533c0e4f995d5ab958026f7ffc88c77e82accad6ba0543236dfaae7

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

# encoding: utf-8

module LogStash module Filters
  class ArrayOfValuesUpdate
    def initialize(iterate_on, destination, fallback, lookup)
      @iterate_on = iterate_on
      @destination = destination
      @fallback = fallback
      @use_fallback = !fallback.nil? # fallback is not nil, the user set a value in the config
      @lookup = lookup
    end

    def test_for_inclusion(event, override)
      # Skip translation in case @destination iterate_on already exists and @override is disabled.
      return false if event.include?(@destination) && !override
      event.include?(@iterate_on)
    end

    def update(event)
      val = event.get(@iterate_on)
      source = Array(val)
      target = Array.new(source.size)
      if @use_fallback
        target.fill(event.sprintf(@fallback))
      end
      source.each_with_index do |inner, index|
        matched = [true, nil]
        @lookup.fetch_strategy.fetch(inner, matched)
        if matched.first
          target[index] = matched.last
        end
      end
      event.set(@destination, target)
      return target.any?
    end
  end
end end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
logstash-filter-translate-3.2.2 lib/logstash/filters/array_of_values_update.rb
logstash-filter-translate-3.2.1 lib/logstash/filters/array_of_values_update.rb
logstash-filter-translate-3.2.0 lib/logstash/filters/array_of_values_update.rb