mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
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:
commit
1041016bbf
3 changed files with 66 additions and 4 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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