diff --git a/CHANGELOG b/CHANGELOG index 45ad01e06..b4f3eb88c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) diff --git a/lib/logstash/filters/grep.rb b/lib/logstash/filters/grep.rb index 282a72c05..1f897369f 100644 --- a/lib/logstash/filters/grep.rb +++ b/lib/logstash/filters/grep.rb @@ -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 diff --git a/spec/filters/grep.rb b/spec/filters/grep.rb index 922f75513..8c5555759 100644 --- a/spec/filters/grep.rb +++ b/spec/filters/grep.rb @@ -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