Merge pull request #403 from wiibaa/grep-params

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

Conflicts:
	CHANGELOG
This commit is contained in:
Jordan Sissel 2013-05-28 15:52:19 -07:00
commit 1041016bbf
3 changed files with 66 additions and 4 deletions

View file

@ -5,6 +5,9 @@
## inputs
- bugfix: gelf: work around gelf parser errors (#476, patch by Chris McCoy)
## filters
- bugfix: grep: allow repeating a field in the hash config (LOGSTASH-919)
## outputs
- feature: irc: add messages_per_second tunable (LOGSTASH-962)

View file

@ -48,10 +48,13 @@ class LogStash::Filters::Grep < LogStash::Filters::Base
# TODO(sissel):
@match.each do |field, pattern|
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