Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions docs/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ include::{include_path}/plugin_header.asciidoc[]
==== Description

The clone filter is for duplicating events.
A clone will be created for each type in the clone list.
A clone will be created for each value in the clone list.
By default `clones` values overwrite the `type` field, or you can specify an optional `field`.
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
Expand All @@ -36,6 +37,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
|=======================================================================
|Setting |Input type|Required
| <<plugins-{type}s-{plugin}-clones>> |<<array,array>>|Yes
| <<plugins-{type}s-{plugin}-field>> |<<string,string>>|No
|=======================================================================

Also see <<plugins-{type}s-{plugin}-common-options>> for a list of options supported by all
Expand All @@ -50,10 +52,36 @@ filter plugins.
* Value type is <<array,array>>
* There is no default value for this setting.

A new clone will be created with the given type for each type in this list.
A new clone will be created with the given value for each field in this list.

Example:
[source,ruby]
filter {
clone {
clones => [ "clone1", "clone2" ]
}
}

Note: setting an empty array will not create any clones. A warning message is logged.

[id="plugins-{type}s-{plugin}-fields"]
===== `field`

* Value type is <<string,string>>
* Default value is `type`

Specify the field into which `clones` values will be added.

Example:
[source,ruby]
filter {
clone {
field => "clone"
clones => [ "clone1", "clone2" ]
}
}


[id="plugins-{type}s-{plugin}-common-options"]
include::{include_path}/{type}.asciidoc[]

5 changes: 3 additions & 2 deletions lib/logstash/filters/clone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class LogStash::Filters::Clone < LogStash::Filters::Base
config_name "clone"

# A new clone will be created with the given type for each type in this list.
config :field, :validate => :string, :required => false, :default => "type"
config :clones, :validate => :array, :required => true

public
Expand All @@ -22,9 +23,9 @@ def register

public
def filter(event)
@clones.each do |type|
@clones.each do |value|
clone = event.clone
clone.set("type", type)
clone.set(field,value)
filter_matched(clone)
@logger.debug("Cloned event", :clone => clone, :event => event)

Expand Down
22 changes: 22 additions & 0 deletions spec/filters/clone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@
end
end

describe "Other Field" do
config <<-CONFIG
filter {
clone {
field => "clone"
clones => ["clone1", "clone2"]
}
}
CONFIG

sample("message" => "hello world", "type" => "original") do
insist { subject }.is_a? Array
insist { subject.length } == 3
insist { subject[1].get("clone") } == "clone1"
insist { subject[2].get("clone") } == "clone2"
subject.each do |s|
insist { s.get("type") } == "original"
insist { s.get("message") } == "hello world"
end
end
end

describe "Bug LOGSTASH-1225" do
### LOGSTASH-1225: Cannot clone events containing numbers.
config <<-CONFIG
Expand Down