logstash-filter-remove_key_pattern 0.1.3 → 0.1.4
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb505c544490f7cfe27056117ab2cc52418183c3
|
4
|
+
data.tar.gz: 633abf824180ef2ac092aaea04904b68102014be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5830c0a33ab3fb4c5c2ee6d818941e8830b56287ce3538937c78c3540468a6cd0b5de292e301731a31192660686e2b5543935d2004a4ad61e7dfe9812f6a3e10
|
7
|
+
data.tar.gz: 4e0494af7a77ed84d3bbe0742677cc643267eb35829227303149e27e95c5415983e62db42a65029da490e061025284c6f1a56a9e21e6dd34a9316a80a6ec54e1
|
@@ -11,7 +11,7 @@ require "logstash/json"
|
|
11
11
|
# [source, ruby]
|
12
12
|
# filter {
|
13
13
|
# remove_key_pattern {
|
14
|
-
#
|
14
|
+
# parent_key => "haystack1"
|
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 :
|
25
|
+
config :parent_key, :validate => :string, :required => true
|
26
26
|
|
27
27
|
# Array of patterns to remove
|
28
28
|
config :pattern, :validate => :array, :required => true
|
@@ -42,16 +42,14 @@ class LogStash::Filters::RemoveKeyPattern < LogStash::Filters::Base
|
|
42
42
|
|
43
43
|
public
|
44
44
|
def filter(event)
|
45
|
-
@
|
46
|
-
remove_pattern(event, key) unless event.get(key).nil?
|
47
|
-
end
|
45
|
+
remove_pattern(event) unless event.get(@parent_key).nil?
|
48
46
|
filter_matched(event)
|
49
47
|
end
|
50
48
|
|
51
49
|
private
|
52
|
-
def remove_pattern(event
|
50
|
+
def remove_pattern(event)
|
53
51
|
hash = {}
|
54
|
-
event.get(
|
52
|
+
event.get(@parent_key).each do |k, v|
|
55
53
|
unless (k =~ @pattern)
|
56
54
|
if @keep_only_ids && (k == 'id' or k =~ /.*_id$/)
|
57
55
|
hash[k] = v
|
@@ -60,10 +58,6 @@ class LogStash::Filters::RemoveKeyPattern < LogStash::Filters::Base
|
|
60
58
|
end
|
61
59
|
end
|
62
60
|
end
|
63
|
-
|
64
|
-
event.set(key, hash)
|
65
|
-
rescue LogStash::Json::GeneratorError
|
66
|
-
return
|
67
|
-
end
|
61
|
+
event.set(@parent_key, hash)
|
68
62
|
end
|
69
63
|
end
|
@@ -8,7 +8,7 @@ describe LogStash::Filters::RemoveKeyPattern do
|
|
8
8
|
config <<-CONFIG
|
9
9
|
filter {
|
10
10
|
remove_key_pattern {
|
11
|
-
|
11
|
+
parent_key => "haystack2"
|
12
12
|
pattern => ["needle", "\\d"]
|
13
13
|
keep_only_ids => "true"
|
14
14
|
}
|
@@ -37,10 +37,6 @@ 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("haystack") }.include?("id")
|
42
|
-
insist { subject.get("haystack") }.include?("key_four_id")
|
43
|
-
reject { subject.get("haystack") }.include?("key4_id")
|
44
40
|
reject { subject.get("haystack2") }.include?("needle")
|
45
41
|
insist { subject.get("haystack2") }.include?("key_one_id")
|
46
42
|
reject { subject.get("haystack2") }.include?("key4_id")
|
@@ -53,7 +49,7 @@ describe LogStash::Filters::RemoveKeyPattern do
|
|
53
49
|
config <<-CONFIG
|
54
50
|
filter {
|
55
51
|
remove_key_pattern {
|
56
|
-
|
52
|
+
parent_key => "haystack"
|
57
53
|
pattern => ["needle", "\\d"]
|
58
54
|
keep_only_ids => "false"
|
59
55
|
}
|
@@ -82,15 +78,9 @@ describe LogStash::Filters::RemoveKeyPattern do
|
|
82
78
|
}
|
83
79
|
|
84
80
|
sample(hash) do
|
85
|
-
insist { subject.get("hello") }.include?("numbers")
|
86
81
|
insist { subject.get("haystack") }.include?("id")
|
87
82
|
insist { subject.get("haystack") }.include?("key_four_id")
|
88
83
|
reject { subject.get("haystack") }.include?("key4_id")
|
89
|
-
reject { subject.get("haystack2") }.include?("needle")
|
90
|
-
insist { subject.get("haystack2") }.include?("key_one_id")
|
91
|
-
reject { subject.get("haystack2") }.include?("key4_id")
|
92
|
-
insist { subject.get("haystack2") }.include?("key")
|
93
|
-
insist { subject.get("haystack2") }.include?("foobar")
|
94
84
|
end
|
95
85
|
end
|
96
86
|
|
@@ -98,7 +88,7 @@ describe LogStash::Filters::RemoveKeyPattern do
|
|
98
88
|
config <<-CONFIG
|
99
89
|
filter {
|
100
90
|
remove_key_pattern {
|
101
|
-
|
91
|
+
parent_key => "h2"
|
102
92
|
pattern => ["needle", "\\d"]
|
103
93
|
keep_only_ids => "true"
|
104
94
|
}
|