class LogStash::Filters::Translate

Attributes

lookup[R]
updater[R]

Public Instance Methods

close() click to toggle source
# File lib/logstash/filters/translate.rb, line 233
def close
  @lookup.stop_scheduler
end
filter(event) click to toggle source
# File lib/logstash/filters/translate.rb, line 237
def filter(event)
  return unless @updater.test_for_inclusion(event, @override)
  begin
    filter_matched(event) if @updater.update(event) || @source == @target
  rescue => e
    @logger.error("Something went wrong when attempting to translate from dictionary", :exception => e, :source => @source, :event => event.to_hash)
  end
end
register() click to toggle source
# File lib/logstash/filters/translate.rb, line 170
def register
  if @dictionary_path && !@dictionary.empty?
    raise LogStash::ConfigurationError, I18n.t(
      "logstash.agent.configuration.invalid_plugin_register",
      :plugin => "filter",
      :type => "translate",
      :error => "The configuration options 'dictionary' and 'dictionary_path' are mutually exclusive"
    )
  end

  if @dictionary_path
    @lookup = Dictionary::File.create(@dictionary_path, @refresh_interval, @refresh_behaviour, @exact, @regex)
  else
    @lookup = Dictionary::Memory.new(@dictionary, @exact, @regex)
  end

  if @field
    if @source
      raise LogStash::ConfigurationError, "Please remove `field => #{@field.inspect}` and only set the `source => ...` option instead"
    else
      deprecation_logger.deprecated("`field` option is deprecated; use `source` instead.")
      logger.debug("intercepting `field` to populate `source`: `#{@field}`")
      @source = @field
    end
  end
  unless @source
    raise LogStash::ConfigurationError, "No source field specified, please provide the `source => ...` option"
  end

  if @destination
    if @target
      raise LogStash::ConfigurationError, "Please remove `destination => #{@destination.inspect}` and only set the `target => ...` option instead"
    else
      deprecation_logger.deprecated("`destination` option is deprecated; use `target` instead.")
      logger.debug("intercepting `destination` to populate `target`: `#{@destination}`")
      @target = @destination
    end
  end
  @target ||= ecs_select[disabled: 'translation', v1: @source]

  if @source == @target
    @override = true if @override.nil?
    if @override.eql?(false)
      raise LogStash::ConfigurationError, "Configuring `override => false` with in-place translation has no effect, please remove the option"
    end
  end

  if @iterate_on.nil?
    @updater = SingleValueUpdate.new(@source, @target, @fallback, @lookup)
  elsif @iterate_on == @source
    @updater = ArrayOfValuesUpdate.new(@iterate_on, @target, @fallback, @lookup)
  else
    @updater = ArrayOfMapsValueUpdate.new(@iterate_on, @source, @target, @fallback, @lookup)
  end

  @logger.debug? && @logger.debug("#{self.class.name}: Dictionary - ", :dictionary => @lookup.dictionary)
  if @exact
    @logger.debug? && @logger.debug("#{self.class.name}: Dictionary translation method - Exact")
  else
    @logger.debug? && @logger.debug("#{self.class.name}: Dictionary translation method - Fuzzy")
  end
end