logstash-filter-de_dot 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/logstash/filters/de_dot.rb +36 -4
- data/logstash-filter-de_dot.gemspec +1 -1
- data/spec/filters/de_dot_spec.rb +30 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28e3ce95451aea24574ed2b0f86e699140537a3e
|
4
|
+
data.tar.gz: 7bb70232fea7b261a9a92ce57c386c13b2deae42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff44ec509d4582fc128dba358b20f4446a9bce0b778cbe2da6f2b365a92307bf580a1ac2fff5138ef6a1002b75ec1046a3df8ef22e57b3748255a5c158e6bf80
|
7
|
+
data.tar.gz: 083bbed40f2322060aade113b65d06bed09c7052c6189272877c82f77afbefd07e6a3011a732e8b6a99bcfdd438da56ca70753ffe21854a825364059f481db48
|
data/CHANGELOG.md
CHANGED
@@ -1,2 +1,9 @@
|
|
1
|
+
## 0.1.1
|
2
|
+
- Fix issue #4, where fields specified by `fields => ` were added to events if
|
3
|
+
they were not present.
|
4
|
+
- Fixed a bug where objects (nested fields) were not properly deleted if there
|
5
|
+
were multiple levels and each had a dotted field name.
|
6
|
+
- Fix issue #3, where dynamic fields are not recognized properly because of the
|
7
|
+
instance variable.
|
1
8
|
## 0.1.0
|
2
9
|
- Initial release
|
@@ -28,6 +28,10 @@ class LogStash::Filters::De_dot < LogStash::Filters::Base
|
|
28
28
|
#
|
29
29
|
config :fields, :validate => :array
|
30
30
|
|
31
|
+
public
|
32
|
+
def has_dot?(fieldref)
|
33
|
+
fieldref =~ /\./
|
34
|
+
end
|
31
35
|
|
32
36
|
public
|
33
37
|
def register
|
@@ -35,6 +39,26 @@ class LogStash::Filters::De_dot < LogStash::Filters::Base
|
|
35
39
|
# Add instance variables here, if any
|
36
40
|
end # def register
|
37
41
|
|
42
|
+
private
|
43
|
+
def find_fieldref_for_delete(source)
|
44
|
+
# In cases where fieldref may look like [a.b][c.d][e.f], we only want to delete
|
45
|
+
# the first level at which the dotted field appears.
|
46
|
+
fieldref = ''
|
47
|
+
@logger.debug? && @logger.debug("de_dot: source fieldref for delete", :source => source)
|
48
|
+
# Iterate over each level of source
|
49
|
+
source.delete('[').split(']').each do |ref|
|
50
|
+
fieldref = fieldref + '['
|
51
|
+
if has_dot?(ref)
|
52
|
+
# return when we find the first ref with a '.'
|
53
|
+
@logger.debug? && @logger.debug("de_dot: fieldref for delete", :fieldref => fieldref + ref + ']')
|
54
|
+
return fieldref + ref + ']'
|
55
|
+
else
|
56
|
+
fieldref = fieldref + ref + ']'
|
57
|
+
@logger.debug? && @logger.debug("de_dot: fieldref still building", :fieldref => fieldref)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
38
62
|
private
|
39
63
|
def rename_field(event, fieldref)
|
40
64
|
@logger.debug? && @logger.debug("de_dot: preprocess", :event => event.to_hash.to_s)
|
@@ -49,7 +73,7 @@ class LogStash::Filters::De_dot < LogStash::Filters::Base
|
|
49
73
|
@logger.debug? && @logger.debug("de_dot: replacement field reference", :newref => newref)
|
50
74
|
event[newref] = event[fieldref]
|
51
75
|
@logger.debug? && @logger.debug("de_dot: event with both new and old field references", :event => event.to_hash.to_s)
|
52
|
-
event.remove(fieldref)
|
76
|
+
event.remove(find_fieldref_for_delete(fieldref))
|
53
77
|
@logger.debug? && @logger.debug("de_dot: postprocess", :event => event.to_hash.to_s)
|
54
78
|
end
|
55
79
|
|
@@ -57,9 +81,17 @@ class LogStash::Filters::De_dot < LogStash::Filters::Base
|
|
57
81
|
def filter(event)
|
58
82
|
@separator = '][' if @nested
|
59
83
|
@logger.debug? && @logger.debug("de_dot: Replace dots with separator", :separator => @separator)
|
60
|
-
|
61
|
-
|
62
|
-
|
84
|
+
if @fields.nil?
|
85
|
+
fields = event.to_hash.keys
|
86
|
+
else
|
87
|
+
fields = @fields
|
88
|
+
end
|
89
|
+
@logger.debug? && @logger.debug("de_dot: Act on these fields", :fields => fields)
|
90
|
+
fields.each do |ref|
|
91
|
+
if event[ref]
|
92
|
+
rename_field(event, ref) if has_dot?(ref)
|
93
|
+
end
|
94
|
+
end
|
63
95
|
filter_matched(event)
|
64
96
|
end # def filter
|
65
97
|
end # class LogStash::Filters::De_dot
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-filter-de_dot'
|
3
|
-
s.version = '0.1.
|
3
|
+
s.version = '0.1.1'
|
4
4
|
s.licenses = ['Apache License (2.0)']
|
5
5
|
s.summary = "This filter removes dots from field names and replaces them with a different separator."
|
6
6
|
s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
|
data/spec/filters/de_dot_spec.rb
CHANGED
@@ -128,11 +128,40 @@ describe LogStash::Filters::De_dot do
|
|
128
128
|
expect(event['[acme][roller][skates]']).to eq('coyote')
|
129
129
|
expect(event.to_hash.keys).not_to include('foo.bar')
|
130
130
|
expect(event['[foo][bar]']).to eq('nochange')
|
131
|
-
expect(event.to_hash.keys).not_to include('a.
|
131
|
+
expect(event.to_hash.keys).not_to include('a.b')
|
132
132
|
expect(event['[a][b][c][d][e][f]']).to eq('finally')
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
|
+
describe "Multiple specific nested fields with some not present" do
|
137
|
+
let(:config) {
|
138
|
+
{
|
139
|
+
"nested" => true,
|
140
|
+
"fields" => [ "[acme][roller.skates]", "foo.bar", "[a.b][c.d][e.f]" ]
|
141
|
+
}
|
142
|
+
}
|
143
|
+
let(:attrs) {
|
144
|
+
{
|
145
|
+
"acme" => { "roller.skates" => "coyote" },
|
146
|
+
"a.b" => { "c.d" => { "e.f" => "finally"} }
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
it "should replace all dots with underscores within specified fields" do
|
151
|
+
subject.filter(event)
|
152
|
+
expect(event['acme']).not_to include('roller.skates')
|
153
|
+
expect(event['[acme][roller][skates]']).to eq('coyote')
|
154
|
+
expect(event.to_hash.keys).not_to include('a.b')
|
155
|
+
expect(event['[a][b][c][d][e][f]']).to eq('finally')
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should not add [foo][bar]" do
|
159
|
+
subject.filter(event)
|
160
|
+
expect(event.to_hash.keys).not_to include('foo.bar')
|
161
|
+
expect(event.to_hash.keys).not_to include('foo')
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
136
165
|
describe "Specific nested fields with underscores already" do
|
137
166
|
let(:config) {
|
138
167
|
{
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-de_dot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|