Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify custom target field for clone type #12

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
5 changes: 4 additions & 1 deletion lib/logstash/filters/clone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class LogStash::Filters::Clone < LogStash::Filters::Base

# A new clone will be created with the given type for each type in this list.
config :clones, :validate => :array, :default => []

# Optional configuration to specify field in which to store the clone type
config :clone_type_field, :validate => :string, :default => "type"

public
def register
Expand All @@ -24,7 +27,7 @@ def register
def filter(event)
@clones.each do |type|
clone = event.clone
clone.set("type", type)
clone.set(@clone_type_field, type)
filter_matched(clone)
@logger.debug("Cloned event", :clone => clone, :event => event)

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

describe "custom type field" do
config <<-CONFIG
filter {
clone {
clones => ["clone", "clone", "clone"]
clone_type_field => "custom_field"
}
}
CONFIG

sample("message" => "hello world", "type" => "original") do
insist { subject }.is_a? Array
insist { subject.length } == 4
subject.each_with_index do |s,i|
if i == 0 # last one should be 'original'
insist { s.get("type") } == "original"
else
insist { s.get("type")} == "original"
insist { s.get("custom_field")} == "clone"
end
insist { s.get("message") } == "hello world"
end
end
end

describe "Complex use" do
config <<-CONFIG
filter {
Expand Down