mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
Allow repeating a field in the hash config . Fix LOGSTASH-919
This commit is contained in:
parent
908e0fd47b
commit
4d5bc7d66e
3 changed files with 64 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue