Skip to content

Commit

Permalink
add support for case-insensitive patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
dpb587 committed Jun 16, 2013
1 parent 49c0d08 commit 5a584a0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/logstash/filters/grep.rb
Expand Up @@ -41,6 +41,11 @@ class LogStash::Filters::Grep < LogStash::Filters::Base
# a regular expression.
config :match, :validate => :hash, :default => {}

# Use case-insensitive matching. Similar to 'grep -i'
#
# If enabled, ignore case distinctions in the patterns.
config :ignore_case, :validate => :boolean, :default => false

public
def register
@patterns = Hash.new { |h,k| h[k] = [] }
Expand All @@ -50,7 +55,7 @@ def register

pattern = [pattern] if pattern.is_a?(String)
pattern.each do |p|
re = Regexp.new(p)
re = Regexp.new(p, @ignore_case ? Regexp::IGNORECASE : 0)
@patterns[field] << re
@logger.debug? and @logger.debug("Registered grep", :type => @type, :field => field,
:pattern => p, :regexp => re)
Expand Down
15 changes: 15 additions & 0 deletions spec/filters/grep.rb
Expand Up @@ -324,4 +324,19 @@
reject { subject }.nil?
end
end

describe "case-insensitive matching" do
config <<-CONFIG
filter {
grep {
ignore_case => true
match => [ "str", "test" ]
}
}
CONFIG

sample("str" => "tEsT: this should still be matched") do
reject { subject }.nil?
end
end
end

0 comments on commit 5a584a0

Please sign in to comment.