mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 22:27:21 -04:00
add support for case-insensitive patterns
This commit is contained in:
parent
49c0d08c4c
commit
5a584a0863
2 changed files with 21 additions and 1 deletions
|
@ -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] = [] }
|
||||
|
@ -50,7 +55,7 @@ class LogStash::Filters::Grep < LogStash::Filters::Base
|
|||
|
||||
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)
|
||||
|
|
|
@ -324,4 +324,19 @@ describe LogStash::Filters::Grep do
|
|||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue