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



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

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)
    end
  end
  filter_matched(event)
end

#has_dot?(fieldref) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/logstash/filters/de_dot.rb', line 32

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

#registerObject

Raises:

  • (ArgumentError)


37
38
39
40
# File 'lib/logstash/filters/de_dot.rb', line 37

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