diff --git a/docs/index.asciidoc b/docs/index.asciidoc index eaa2c33..26b6b99 100644 --- a/docs/index.asciidoc +++ b/docs/index.asciidoc @@ -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 @@ -36,6 +37,7 @@ This plugin supports the following configuration options plus the <> |<>|Yes +| <> |<>|No |======================================================================= Also see <> for a list of options supported by all @@ -50,10 +52,36 @@ filter plugins. * Value type is <> * 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 <> + * 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[] + diff --git a/lib/logstash/filters/clone.rb b/lib/logstash/filters/clone.rb index be6729c..47b577c 100644 --- a/lib/logstash/filters/clone.rb +++ b/lib/logstash/filters/clone.rb @@ -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 @@ -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) diff --git a/spec/filters/clone_spec.rb b/spec/filters/clone_spec.rb index 9e2df98..969ad28 100644 --- a/spec/filters/clone_spec.rb +++ b/spec/filters/clone_spec.rb @@ -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