logstash-filter-remove_key_pattern 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb505c544490f7cfe27056117ab2cc52418183c3
4
- data.tar.gz: 633abf824180ef2ac092aaea04904b68102014be
3
+ metadata.gz: a2d1273e83cc3bfbe2a32bf6ee739b937d22c65e
4
+ data.tar.gz: 41a69cbde9e4f739626759b8a87138a20afa04aa
5
5
  SHA512:
6
- metadata.gz: 5830c0a33ab3fb4c5c2ee6d818941e8830b56287ce3538937c78c3540468a6cd0b5de292e301731a31192660686e2b5543935d2004a4ad61e7dfe9812f6a3e10
7
- data.tar.gz: 4e0494af7a77ed84d3bbe0742677cc643267eb35829227303149e27e95c5415983e62db42a65029da490e061025284c6f1a56a9e21e6dd34a9316a80a6ec54e1
6
+ metadata.gz: d7b4fe76f479720801d45a30c9fb4e9fa679bcc8d3e5c5cdf42be47cc18a269ab2821b896bcb84d287f08f8ec94d812481b1d77e9cf1cef8f3313c105b101dfc
7
+ data.tar.gz: f2f2ce885ec15cf913b7441f90940225e8ca8babe15f8a9e7b4801854fb86beaccb0c6e651add9570391404c4dc5a75c1291a98ff8a59a9763e1978ea5d902dd
@@ -11,7 +11,7 @@ require "logstash/json"
11
11
  # [source, ruby]
12
12
  # filter {
13
13
  # remove_key_pattern {
14
- # parent_key => "haystack1"
14
+ # parent_keys => ["haystack1", "haystack2"]
15
15
  # pattern => ["\\d", "needle"]
16
16
  # keep_only_ids => "true"
17
17
  # }
@@ -22,7 +22,7 @@ class LogStash::Filters::RemoveKeyPattern < LogStash::Filters::Base
22
22
  config_name "remove_key_pattern"
23
23
 
24
24
  # Array of parent keys to remove from
25
- config :parent_key, :validate => :string, :required => true
25
+ config :parent_keys, :validate => :array, :required => true
26
26
 
27
27
  # Array of patterns to remove
28
28
  config :pattern, :validate => :array, :required => true
@@ -42,14 +42,16 @@ class LogStash::Filters::RemoveKeyPattern < LogStash::Filters::Base
42
42
 
43
43
  public
44
44
  def filter(event)
45
- remove_pattern(event) unless event.get(@parent_key).nil?
45
+ @parent_keys.each do |key|
46
+ remove_pattern(event, key) unless event.get(key).nil?
47
+ end
46
48
  filter_matched(event)
47
49
  end
48
50
 
49
51
  private
50
- def remove_pattern(event)
52
+ def remove_pattern(event, key)
51
53
  hash = {}
52
- event.get(@parent_key).each do |k, v|
54
+ event.get(key).each do |k, v|
53
55
  unless (k =~ @pattern)
54
56
  if @keep_only_ids && (k == 'id' or k =~ /.*_id$/)
55
57
  hash[k] = v
@@ -58,6 +60,7 @@ class LogStash::Filters::RemoveKeyPattern < LogStash::Filters::Base
58
60
  end
59
61
  end
60
62
  end
61
- event.set(@parent_key, hash)
63
+ event.set("#{key}_json", LogStash::Json.dump(event.get(key)))
64
+ event.set(key, hash)
62
65
  end
63
66
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-filter-remove_key_pattern'
3
- s.version = '0.1.4'
3
+ s.version = '0.2.0'
4
4
  s.licenses = ['Apache-2.0']
5
5
  s.summary = 'Remove all keys that match pattern'
6
6
  s.authors = ['Arthur Alfredo']
@@ -8,7 +8,7 @@ describe LogStash::Filters::RemoveKeyPattern do
8
8
  config <<-CONFIG
9
9
  filter {
10
10
  remove_key_pattern {
11
- parent_key => "haystack2"
11
+ parent_keys => ["haystack1", "haystack2"]
12
12
  pattern => ["needle", "\\d"]
13
13
  keep_only_ids => "true"
14
14
  }
@@ -20,7 +20,7 @@ describe LogStash::Filters::RemoveKeyPattern do
20
20
  "numbers" => ["one", "two", "three"],
21
21
  "47" => ["2", "3", "7"],
22
22
  },
23
- "haystack" => {
23
+ "haystack1" => {
24
24
  "key1_id" => ["value1", "value2", "value3"],
25
25
  "id" => ["value1", "value2", "value3"],
26
26
  "key4_id" => ["value1", "value2", "value3"],
@@ -37,6 +37,10 @@ describe LogStash::Filters::RemoveKeyPattern do
37
37
  }
38
38
 
39
39
  sample(hash) do
40
+ insist { subject.get("hello") }.include?("numbers")
41
+ insist { subject.get("haystack1") }.include?("id")
42
+ insist { subject.get("haystack1") }.include?("key_four_id")
43
+ reject { subject.get("haystack1") }.include?("key4_id")
40
44
  reject { subject.get("haystack2") }.include?("needle")
41
45
  insist { subject.get("haystack2") }.include?("key_one_id")
42
46
  reject { subject.get("haystack2") }.include?("key4_id")
@@ -49,7 +53,7 @@ describe LogStash::Filters::RemoveKeyPattern do
49
53
  config <<-CONFIG
50
54
  filter {
51
55
  remove_key_pattern {
52
- parent_key => "haystack"
56
+ parent_keys => ["haystack", "haystack2"]
53
57
  pattern => ["needle", "\\d"]
54
58
  keep_only_ids => "false"
55
59
  }
@@ -81,6 +85,11 @@ describe LogStash::Filters::RemoveKeyPattern do
81
85
  insist { subject.get("haystack") }.include?("id")
82
86
  insist { subject.get("haystack") }.include?("key_four_id")
83
87
  reject { subject.get("haystack") }.include?("key4_id")
88
+ reject { subject.get("haystack2") }.include?("needle")
89
+ insist { subject.get("haystack2") }.include?("key_one_id")
90
+ reject { subject.get("haystack2") }.include?("key4_id")
91
+ insist { subject.get("haystack2") }.include?("key")
92
+ insist { subject.get("haystack2") }.include?("foobar")
84
93
  end
85
94
  end
86
95
 
@@ -88,7 +97,7 @@ describe LogStash::Filters::RemoveKeyPattern do
88
97
  config <<-CONFIG
89
98
  filter {
90
99
  remove_key_pattern {
91
- parent_key => "h2"
100
+ parent_keys => ["h2"]
92
101
  pattern => ["needle", "\\d"]
93
102
  keep_only_ids => "true"
94
103
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-remove_key_pattern
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Alfredo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-19 00:00:00.000000000 Z
11
+ date: 2017-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement