Allow repeating a field in the hash config . Fix LOGSTASH-919

This commit is contained in:
Wiibaa 2013-03-15 06:37:36 +01:00
parent 908e0fd47b
commit 4d5bc7d66e
3 changed files with 64 additions and 4 deletions

View file

@ -13,6 +13,7 @@
- improvement: tcp: ssl now supported! (#318, patch by Matthew Richardson)
## filters
- bugfix: grep: allow repeating a field in the hash config (LOGSTASH-919)
- deprecation: the --grok-patterns-path flag is deprecated and will now
warn you if you use it. (LOGSTASH-803)
- feature: grok: Adds tag_on_failure setting so you can prevent grok from

View file

@ -64,10 +64,13 @@ class LogStash::Filters::Grep < LogStash::Filters::Base
# Skip known config names
next if (RESERVED + ["negate", "match", "drop"]).include?(field)
re = Regexp.new(pattern)
@patterns[field] << re
@logger.debug("Registered grep", :type => @type, :field => field,
:pattern => pattern, :regexp => re)
pattern = [pattern] if pattern.is_a?(String)
pattern.each do |p|
re = Regexp.new(p)
@patterns[field] << re
@logger.debug? and @logger.debug("Registered grep", :type => @type, :field => field,
:pattern => p, :regexp => re)
end
end # @match.merge.each
end # def register

View file

@ -264,4 +264,60 @@ describe LogStash::Filters::Grep do
insist { subject }.nil?
end
end
#LOGSTASH-894 and LOGSTASH-919
describe "repeat a field in match config, similar to piped grep command line" do
config <<-CONFIG
filter {
grep {
match => ["@message", "hello", "@message", "world"]
}
}
CONFIG
#both match
sample "hello world" do
reject { subject }.nil?
end
#one match
sample "bye world" do
insist { subject }.nil?
end
#one match
sample "hello Jordan" do
insist { subject }.nil?
end
#no match
sample "WTF" do
insist { subject }.nil?
end
end
describe "repeat a field in match config, similar to several -e in grep command line" do
config <<-CONFIG
filter {
grep {
match => ["@message", "hello", "@message", "world"]
negate => true
}
}
CONFIG
#both match
sample "hello world" do
insist { subject }.nil?
end
#one match
sample "bye world" do
insist { subject }.nil?
end
#one match
sample "hello Jordan" do
insist { subject }.nil?
end
#no match
sample "WTF" do
reject { subject }.nil?
end
end
end