class LogStash::Filters::Collect

This filter will replace the contents of the default message field with whatever you specify in the configuration.

It is only intended to be used as an .

Public Instance Methods

filter(event) click to toggle source
# File lib/logstash/filters/collect.rb, line 52
def filter(event)
  object_array = event.get(@field)
  if not object_array.class == Array
    begin
      object_array = JSON.parse(object_array)
    rescue
      nil
    end

    if not object_array.class == Array
      plugin_error("Error, #{@field} is not an array or parseable JSON", event)
      return
    end
  end

  new_collection = []
  object_array.each { |obj|
    # Add the value to the new collection
    new_collection.push(get_nested_property_from_object(@property, obj))
  }

  event.set(@collection, new_collection)
  filter_matched(event)
end
register() click to toggle source
# File lib/logstash/filters/collect.rb, line 32
def register
  # Add instance variables
end

Private Instance Methods

get_nested_property_from_object(property_array, source) click to toggle source
# File lib/logstash/filters/collect.rb, line 43
def get_nested_property_from_object(property_array, source)
  interim_object = source
  @property.each { |x|
    interim_object = interim_object[x]
  }
  return interim_object
end
plugin_error(message, event) click to toggle source
# File lib/logstash/filters/collect.rb, line 37
def plugin_error(message, event)
  @logger.error("Collect filter error: #{message}")
  LogStash::Util::Decorators.add_tags(@error_tags, event, "filters/#{self.class.name}")
end