class LogStash::Filters::Clone

The clone filter is for duplicating events. A clone will be created for each type in the clone list. The original event is left unchanged. Created events are inserted into the pipeline as normal events and will be processed by the remaining pipeline configuration starting from the filter that generated them (i.e. this plugin).

ECS disabled: set the value of the root-level `type` (undefined in ECS) of each resulting event to one of the values provided in its `clones` directive. ECS enabled: add a `tags` of each resulting event to one of the values provided in its `clones` directive.

Public Class Methods

new(*params) click to toggle source
Calls superclass method
# File lib/logstash/filters/clone.rb, line 26
def initialize(*params)
  super
  @enhance_clone_type_method = method( ecs_select[disabled: :set_event_type, v1: :add_event_tag] )
end

Public Instance Methods

add_event_tag(event, clone_type) click to toggle source
# File lib/logstash/filters/clone.rb, line 53
def add_event_tag(event, clone_type)
  tags = Array(event.get("tags"))
  tags << clone_type
  event.set("tags", tags)
  event
end
filter(event) { |clone| ... } click to toggle source
# File lib/logstash/filters/clone.rb, line 36
def filter(event)
  @clones.each do |type|
    clone = event.clone
    @enhance_clone_type_method.(clone, type)
    filter_matched(clone)
    @logger.debug("Cloned event", :clone => clone, :event => event)

    # Push this new event onto the stack at the LogStash::FilterWorker
    yield clone
  end
end
register() click to toggle source
# File lib/logstash/filters/clone.rb, line 31
def register
  logger.warn("The parameter 'clones' is empty, so no clones will be created.") if @clones.empty?
end
set_event_type(event, type) click to toggle source
# File lib/logstash/filters/clone.rb, line 48
def set_event_type(event, type)
  event.set("type", type)
  event
end