logstash-filter-mutate 3.1.3 → 3.1.5
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 +3 -0
- data/Gemfile +8 -1
- data/docs/index.asciidoc +282 -0
- data/lib/logstash/filters/mutate.rb +20 -0
- data/logstash-filter-mutate.gemspec +2 -2
- data/spec/filters/integration/multi_stage_spec.rb +4 -1
- data/spec/filters/mutate_spec.rb +46 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 501e5df0525fdfe75cd9037ef0c9359a5508f5b5
|
4
|
+
data.tar.gz: 544b226c746ce230aed79bff95e8570a98b70c72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76bb61eff6123e02ea18749d8e797c1617a018b2bdd66b751c0937372da059c5e23074295531c6d0191ce090d85214b3751d7d4d17ea26e827a855351870a4e4
|
7
|
+
data.tar.gz: 9729bc0839d86afe04cd8d515c9fe624c7e70cefe83d489774d98118ca9f2fe9b3deaf0fc90240f504a67c54c8eca9eabdb892c87b3268b57c843023612b942e
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
# Specify your gem's dependencies in logstash-mass_effect.gemspec
|
4
3
|
gemspec
|
4
|
+
|
5
|
+
logstash_path = ENV["LOGSTASH_PATH"] || "../../logstash"
|
6
|
+
use_logstash_source = ENV["LOGSTASH_SOURCE"] && ENV["LOGSTASH_SOURCE"].to_s == "1"
|
7
|
+
|
8
|
+
if Dir.exist?(logstash_path) && use_logstash_source
|
9
|
+
gem 'logstash-core', :path => "#{logstash_path}/logstash-core"
|
10
|
+
gem 'logstash-core-plugin-api', :path => "#{logstash_path}/logstash-core-plugin-api"
|
11
|
+
end
|
data/docs/index.asciidoc
ADDED
@@ -0,0 +1,282 @@
|
|
1
|
+
:plugin: mutate
|
2
|
+
:type: filter
|
3
|
+
|
4
|
+
///////////////////////////////////////////
|
5
|
+
START - GENERATED VARIABLES, DO NOT EDIT!
|
6
|
+
///////////////////////////////////////////
|
7
|
+
:version: %VERSION%
|
8
|
+
:release_date: %RELEASE_DATE%
|
9
|
+
:changelog_url: %CHANGELOG_URL%
|
10
|
+
:include_path: ../../../../logstash/docs/include
|
11
|
+
///////////////////////////////////////////
|
12
|
+
END - GENERATED VARIABLES, DO NOT EDIT!
|
13
|
+
///////////////////////////////////////////
|
14
|
+
|
15
|
+
[id="plugins-{type}-{plugin}"]
|
16
|
+
|
17
|
+
=== Mutate filter plugin
|
18
|
+
|
19
|
+
include::{include_path}/plugin_header.asciidoc[]
|
20
|
+
|
21
|
+
==== Description
|
22
|
+
|
23
|
+
The mutate filter allows you to perform general mutations on fields. You
|
24
|
+
can rename, remove, replace, and modify fields in your events.
|
25
|
+
|
26
|
+
[id="plugins-{type}s-{plugin}-options"]
|
27
|
+
==== Mutate Filter Configuration Options
|
28
|
+
|
29
|
+
This plugin supports the following configuration options plus the <<plugins-{type}s-{plugin}-common-options>> described later.
|
30
|
+
|
31
|
+
[cols="<,<,<",options="header",]
|
32
|
+
|=======================================================================
|
33
|
+
|Setting |Input type|Required
|
34
|
+
| <<plugins-{type}s-{plugin}-convert>> |<<hash,hash>>|No
|
35
|
+
| <<plugins-{type}s-{plugin}-copy>> |<<hash,hash>>|No
|
36
|
+
| <<plugins-{type}s-{plugin}-gsub>> |<<array,array>>|No
|
37
|
+
| <<plugins-{type}s-{plugin}-join>> |<<hash,hash>>|No
|
38
|
+
| <<plugins-{type}s-{plugin}-lowercase>> |<<array,array>>|No
|
39
|
+
| <<plugins-{type}s-{plugin}-merge>> |<<hash,hash>>|No
|
40
|
+
| <<plugins-{type}s-{plugin}-rename>> |<<hash,hash>>|No
|
41
|
+
| <<plugins-{type}s-{plugin}-replace>> |<<hash,hash>>|No
|
42
|
+
| <<plugins-{type}s-{plugin}-split>> |<<hash,hash>>|No
|
43
|
+
| <<plugins-{type}s-{plugin}-strip>> |<<array,array>>|No
|
44
|
+
| <<plugins-{type}s-{plugin}-update>> |<<hash,hash>>|No
|
45
|
+
| <<plugins-{type}s-{plugin}-uppercase>> |<<array,array>>|No
|
46
|
+
|=======================================================================
|
47
|
+
|
48
|
+
Also see <<plugins-{type}s-{plugin}-common-options>> for a list of options supported by all
|
49
|
+
filter plugins.
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
[id="plugins-{type}s-{plugin}-convert"]
|
54
|
+
===== `convert`
|
55
|
+
|
56
|
+
* Value type is <<hash,hash>>
|
57
|
+
* There is no default value for this setting.
|
58
|
+
|
59
|
+
Convert a field's value to a different type, like turning a string to an
|
60
|
+
integer. If the field value is an array, all members will be converted.
|
61
|
+
If the field is a hash, no action will be taken.
|
62
|
+
|
63
|
+
If the conversion type is `boolean`, the acceptable values are:
|
64
|
+
|
65
|
+
* **True:** `true`, `t`, `yes`, `y`, and `1`
|
66
|
+
* **False:** `false`, `f`, `no`, `n`, and `0`
|
67
|
+
|
68
|
+
If a value other than these is provided, it will pass straight through
|
69
|
+
and log a warning message.
|
70
|
+
|
71
|
+
Valid conversion targets are: integer, float, string, and boolean.
|
72
|
+
|
73
|
+
Example:
|
74
|
+
[source,ruby]
|
75
|
+
filter {
|
76
|
+
mutate {
|
77
|
+
convert => { "fieldname" => "integer" }
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
[id="plugins-{type}s-{plugin}-copy"]
|
82
|
+
===== `copy`
|
83
|
+
|
84
|
+
* Value type is <<hash,hash>>
|
85
|
+
* There is no default value for this setting.
|
86
|
+
|
87
|
+
Copy an existing field to another field. Existing target field will be overriden.
|
88
|
+
|
89
|
+
Example:
|
90
|
+
[source,ruby]
|
91
|
+
filter {
|
92
|
+
mutate {
|
93
|
+
copy => { "source_field" => "dest_field" }
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
[id="plugins-{type}s-{plugin}-gsub"]
|
98
|
+
===== `gsub`
|
99
|
+
|
100
|
+
* Value type is <<array,array>>
|
101
|
+
* There is no default value for this setting.
|
102
|
+
|
103
|
+
Convert a string field by applying a regular expression and a replacement.
|
104
|
+
If the field is not a string, no action will be taken.
|
105
|
+
|
106
|
+
This configuration takes an array consisting of 3 elements per
|
107
|
+
field/substitution.
|
108
|
+
|
109
|
+
Be aware of escaping any backslash in the config file.
|
110
|
+
|
111
|
+
Example:
|
112
|
+
[source,ruby]
|
113
|
+
filter {
|
114
|
+
mutate {
|
115
|
+
gsub => [
|
116
|
+
# replace all forward slashes with underscore
|
117
|
+
"fieldname", "/", "_",
|
118
|
+
# replace backslashes, question marks, hashes, and minuses
|
119
|
+
# with a dot "."
|
120
|
+
"fieldname2", "[\\?#-]", "."
|
121
|
+
]
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
[id="plugins-{type}s-{plugin}-join"]
|
127
|
+
===== `join`
|
128
|
+
|
129
|
+
* Value type is <<hash,hash>>
|
130
|
+
* There is no default value for this setting.
|
131
|
+
|
132
|
+
Join an array with a separator character. Does nothing on non-array fields.
|
133
|
+
|
134
|
+
Example:
|
135
|
+
[source,ruby]
|
136
|
+
filter {
|
137
|
+
mutate {
|
138
|
+
join => { "fieldname" => "," }
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
[id="plugins-{type}s-{plugin}-lowercase"]
|
143
|
+
===== `lowercase`
|
144
|
+
|
145
|
+
* Value type is <<array,array>>
|
146
|
+
* There is no default value for this setting.
|
147
|
+
|
148
|
+
Convert a string to its lowercase equivalent.
|
149
|
+
|
150
|
+
Example:
|
151
|
+
[source,ruby]
|
152
|
+
filter {
|
153
|
+
mutate {
|
154
|
+
lowercase => [ "fieldname" ]
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
[id="plugins-{type}s-{plugin}-merge"]
|
159
|
+
===== `merge`
|
160
|
+
|
161
|
+
* Value type is <<hash,hash>>
|
162
|
+
* There is no default value for this setting.
|
163
|
+
|
164
|
+
Merge two fields of arrays or hashes.
|
165
|
+
String fields will be automatically be converted into an array, so:
|
166
|
+
==========================
|
167
|
+
`array` + `string` will work
|
168
|
+
`string` + `string` will result in an 2 entry array in `dest_field`
|
169
|
+
`array` and `hash` will not work
|
170
|
+
==========================
|
171
|
+
Example:
|
172
|
+
[source,ruby]
|
173
|
+
filter {
|
174
|
+
mutate {
|
175
|
+
merge => { "dest_field" => "added_field" }
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
[id="plugins-{type}s-{plugin}-rename"]
|
180
|
+
===== `rename`
|
181
|
+
|
182
|
+
* Value type is <<hash,hash>>
|
183
|
+
* There is no default value for this setting.
|
184
|
+
|
185
|
+
Rename one or more fields.
|
186
|
+
|
187
|
+
Example:
|
188
|
+
[source,ruby]
|
189
|
+
filter {
|
190
|
+
mutate {
|
191
|
+
# Renames the 'HOSTORIP' field to 'client_ip'
|
192
|
+
rename => { "HOSTORIP" => "client_ip" }
|
193
|
+
}
|
194
|
+
}
|
195
|
+
|
196
|
+
[id="plugins-{type}s-{plugin}-replace"]
|
197
|
+
===== `replace`
|
198
|
+
|
199
|
+
* Value type is <<hash,hash>>
|
200
|
+
* There is no default value for this setting.
|
201
|
+
|
202
|
+
Replace a field with a new value. The new value can include `%{foo}` strings
|
203
|
+
to help you build a new value from other parts of the event.
|
204
|
+
|
205
|
+
Example:
|
206
|
+
[source,ruby]
|
207
|
+
filter {
|
208
|
+
mutate {
|
209
|
+
replace => { "message" => "%{source_host}: My new message" }
|
210
|
+
}
|
211
|
+
}
|
212
|
+
|
213
|
+
[id="plugins-{type}s-{plugin}-split"]
|
214
|
+
===== `split`
|
215
|
+
|
216
|
+
* Value type is <<hash,hash>>
|
217
|
+
* There is no default value for this setting.
|
218
|
+
|
219
|
+
Split a field to an array using a separator character. Only works on string
|
220
|
+
fields.
|
221
|
+
|
222
|
+
Example:
|
223
|
+
[source,ruby]
|
224
|
+
filter {
|
225
|
+
mutate {
|
226
|
+
split => { "fieldname" => "," }
|
227
|
+
}
|
228
|
+
}
|
229
|
+
|
230
|
+
[id="plugins-{type}s-{plugin}-strip"]
|
231
|
+
===== `strip`
|
232
|
+
|
233
|
+
* Value type is <<array,array>>
|
234
|
+
* There is no default value for this setting.
|
235
|
+
|
236
|
+
Strip whitespace from field. NOTE: this only works on leading and trailing whitespace.
|
237
|
+
|
238
|
+
Example:
|
239
|
+
[source,ruby]
|
240
|
+
filter {
|
241
|
+
mutate {
|
242
|
+
strip => ["field1", "field2"]
|
243
|
+
}
|
244
|
+
}
|
245
|
+
|
246
|
+
[id="plugins-{type}s-{plugin}-update"]
|
247
|
+
===== `update`
|
248
|
+
|
249
|
+
* Value type is <<hash,hash>>
|
250
|
+
* There is no default value for this setting.
|
251
|
+
|
252
|
+
Update an existing field with a new value. If the field does not exist,
|
253
|
+
then no action will be taken.
|
254
|
+
|
255
|
+
Example:
|
256
|
+
[source,ruby]
|
257
|
+
filter {
|
258
|
+
mutate {
|
259
|
+
update => { "sample" => "My new message" }
|
260
|
+
}
|
261
|
+
}
|
262
|
+
|
263
|
+
[id="plugins-{type}s-{plugin}-uppercase"]
|
264
|
+
===== `uppercase`
|
265
|
+
|
266
|
+
* Value type is <<array,array>>
|
267
|
+
* There is no default value for this setting.
|
268
|
+
|
269
|
+
Convert a string to its uppercase equivalent.
|
270
|
+
|
271
|
+
Example:
|
272
|
+
[source,ruby]
|
273
|
+
filter {
|
274
|
+
mutate {
|
275
|
+
uppercase => [ "fieldname" ]
|
276
|
+
}
|
277
|
+
}
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
[id="plugins-{type}s-{plugin}-common-options"]
|
282
|
+
include::{include_path}/{type}.asciidoc[]
|
@@ -162,6 +162,17 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
|
|
162
162
|
# }
|
163
163
|
config :merge, :validate => :hash
|
164
164
|
|
165
|
+
# Copy an existing field to another field. Existing target field will be overriden.
|
166
|
+
# ==========================
|
167
|
+
# Example:
|
168
|
+
# [source,ruby]
|
169
|
+
# filter {
|
170
|
+
# mutate {
|
171
|
+
# copy => { "source_field" => "dest_field" }
|
172
|
+
# }
|
173
|
+
# }
|
174
|
+
config :copy, :validate => :hash
|
175
|
+
|
165
176
|
TRUE_REGEX = (/^(true|t|yes|y|1)$/i).freeze
|
166
177
|
FALSE_REGEX = (/^(false|f|no|n|0)$/i).freeze
|
167
178
|
CONVERT_PREFIX = "convert_".freeze
|
@@ -212,6 +223,7 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
|
|
212
223
|
split(event) if @split
|
213
224
|
join(event) if @join
|
214
225
|
merge(event) if @merge
|
226
|
+
copy(event) if @copy
|
215
227
|
|
216
228
|
filter_matched(event)
|
217
229
|
end
|
@@ -427,4 +439,12 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
|
|
427
439
|
end
|
428
440
|
end
|
429
441
|
end
|
442
|
+
|
443
|
+
def copy(event)
|
444
|
+
@copy.each do |src_field, dest_field|
|
445
|
+
original = event.get(src_field)
|
446
|
+
next if original.nil?
|
447
|
+
event.set(dest_field,LogStash::Util.deep_clone(original))
|
448
|
+
end
|
449
|
+
end
|
430
450
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-filter-mutate'
|
4
|
-
s.version = '3.1.
|
4
|
+
s.version = '3.1.5'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "The mutate filter allows you to perform general mutations on fields. You can rename, remove, replace, and modify fields in your events."
|
7
7
|
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.require_paths = ["lib"]
|
12
12
|
|
13
13
|
# Files
|
14
|
-
s.files = Dir[
|
14
|
+
s.files = Dir["lib/**/*","spec/**/*","*.gemspec","*.md","CONTRIBUTORS","Gemfile","LICENSE","NOTICE.TXT", "vendor/jar-dependencies/**/*.jar", "vendor/jar-dependencies/**/*.rb", "VERSION", "docs/**/*"]
|
15
15
|
|
16
16
|
# Tests
|
17
17
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
@@ -10,7 +10,10 @@ unless LogStash::Environment.const_defined?(:LOGSTASH_HOME)
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe LogStash::Filters::Mutate do
|
13
|
-
let(:pipeline)
|
13
|
+
let(:pipeline) do
|
14
|
+
new_pipeline_from_string(config)
|
15
|
+
end
|
16
|
+
|
14
17
|
let(:events) do
|
15
18
|
arr = event.is_a?(Array) ? event : [event]
|
16
19
|
arr.map do |evt|
|
data/spec/filters/mutate_spec.rb
CHANGED
@@ -178,6 +178,51 @@ describe LogStash::Filters::Mutate do
|
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|
181
|
+
describe "#copy" do
|
182
|
+
|
183
|
+
let(:config) do
|
184
|
+
{ "copy" => {"field" => "target" } }
|
185
|
+
end
|
186
|
+
|
187
|
+
context "when source field is a string" do
|
188
|
+
|
189
|
+
let(:attrs) { { "field" => "foobar" } }
|
190
|
+
|
191
|
+
it "should deep copy the field" do
|
192
|
+
subject.filter(event)
|
193
|
+
expect(event.get("target")).to eq(event.get("field"))
|
194
|
+
#fields should be independant
|
195
|
+
event.set("field",nil);
|
196
|
+
expect(event.get("target")).not_to eq(event.get("field"))
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context "when source field is an array" do
|
201
|
+
|
202
|
+
let(:attrs) { { "field" => ["foo","bar"] } }
|
203
|
+
|
204
|
+
it "should not modify source field nil" do
|
205
|
+
subject.filter(event)
|
206
|
+
expect(event.get("target")).to eq(event.get("field"))
|
207
|
+
#fields should be independant
|
208
|
+
event.set("field",event.get("field") << "baz")
|
209
|
+
expect(event.get("target")).not_to eq(event.get("field"))
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
context "when source field is a hash" do
|
214
|
+
|
215
|
+
let(:attrs) { { "field" => { "foo" => "bar"} } }
|
216
|
+
|
217
|
+
it "should not modify source field nil" do
|
218
|
+
subject.filter(event)
|
219
|
+
expect(event.get("target")).to eq(event.get("field"))
|
220
|
+
#fields should be independant
|
221
|
+
event.set("[field][foo]","baz")
|
222
|
+
expect(event.get("[target][foo]")).not_to eq(event.get("[field][foo]"))
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
181
226
|
end
|
182
227
|
|
183
228
|
describe LogStash::Filters::Mutate do
|
@@ -187,7 +232,7 @@ describe LogStash::Filters::Mutate do
|
|
187
232
|
config <<-CONFIG
|
188
233
|
filter {
|
189
234
|
mutate {
|
190
|
-
convert => [ "message", "int"]
|
235
|
+
convert => [ "message", "int"] #should be integer
|
191
236
|
}
|
192
237
|
}
|
193
238
|
CONFIG
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-mutate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- LICENSE
|
85
85
|
- NOTICE.TXT
|
86
86
|
- README.md
|
87
|
+
- docs/index.asciidoc
|
87
88
|
- lib/logstash/filters/mutate.rb
|
88
89
|
- logstash-filter-mutate.gemspec
|
89
90
|
- spec/filters/integration/multi_stage_spec.rb
|