Class: LogStash::Filters::De_dot

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/filters/de_dot.rb

Overview

This filter appears to rename fields by replacing ‘.` characters with a different separator. In reality, it’s a somewhat expensive filter that has to copy the source field contents to a new destination field (whose name no longer contains dots), and then remove the corresponding source field.

It should only be used if no other options are available.

Instance Method Summary collapse

Instance Method Details

#filter(event) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/logstash/filters/de_dot.rb', line 104

def filter(event)
  @separator = '][' if @nested
  @logger.debug? && @logger.debug("de_dot: Replace dots with separator", :separator => @separator)
  if @fields.nil?
    fields = event.to_hash.keys
  else
    fields = @fields
  end
  @logger.debug? && @logger.debug("de_dot: Act on these fields", :fields => fields)
  fields.each do |ref|
    if event.include?(ref)
      rename_field(event, ref) if has_dot?(ref) || @recursive
    end
  end
  filter_matched(event)
rescue => ex
  meta = { :exception => ex.message }
  meta[:backtrace] = ex.backtrace if logger.debug?
  logger.warn('Exception caught while applying de_dot filter', meta)
  event.tag(@tag_on_failure)
end

#has_dot?(fieldref) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/logstash/filters/de_dot.rb', line 41

def has_dot?(fieldref)
  fieldref =~ /\./
end

#registerObject

Raises:

  • (ArgumentError)


46
47
48
49
# File 'lib/logstash/filters/de_dot.rb', line 46

def register
  raise ArgumentError, "de_dot: separator cannot be or contain '.'" unless (@separator =~ /\./).nil?
  # Add instance variables here, if any
end