logstash-filter-mutate 3.3.4 → 3.4.0
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/docs/index.asciidoc +7 -2
- data/lib/logstash/filters/mutate.rb +4 -4
- data/logstash-filter-mutate.gemspec +1 -1
- data/spec/filters/mutate_spec.rb +67 -34
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d864cb702460a9b6b7ab2d3bcf7983df039730306118771e0e62e2f87754c31c
|
4
|
+
data.tar.gz: ee2729fb05d2a18426d8419b917df4137ca90bfd5e45fa4a99a1f32e2ebb5317
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e01156ec1b9be737f2a291a95a270a1a07e90fac8e62ffbebbc1a81db9d983bda817a7539bd9827b4d919abe4defe6cbf1d3755d51e38c76c26a520d90846ca
|
7
|
+
data.tar.gz: 7998a5a7475514816ab8d83f3749dcb7a54c88a2f510da66b57711c4b7282be70b4290f24b3dc2f71872fb8193824d00f02c8f99d67ed4710fc83ace5a396abf
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## 3.4.0
|
2
|
+
- Added ability to directly convert from integer and float to boolean [#127](https://github.com/logstash-plugins/logstash-filter-mutate/pull/127)
|
3
|
+
|
1
4
|
## 3.3.4
|
2
5
|
- Changed documentation to clarify execution order and to provide workaround
|
3
6
|
[#128](https://github.com/logstash-plugins/logstash-filter-mutate/pull/128)
|
data/docs/index.asciidoc
CHANGED
@@ -117,10 +117,15 @@ Valid conversion targets, and their expected behaviour with different inputs are
|
|
117
117
|
* `string`:
|
118
118
|
- all values are stringified and encoded with UTF-8
|
119
119
|
* `boolean`:
|
120
|
-
-
|
121
|
-
-
|
120
|
+
- integer 0 is converted to boolean `false`
|
121
|
+
- integer 1 is converted to boolean `true`
|
122
|
+
- float 0.0 is converted to boolean `false`
|
123
|
+
- float 1.0 is converted to boolean `true`
|
124
|
+
- strings `"true"`, `"t"`, `"yes"`, `"y"`, `"1"`and `"1.0"` are converted to boolean `true`
|
125
|
+
- strings `"false"`, `"f"`, `"no"`, `"n"`, `"0"` and `"0.0"` are converted to boolean `false`
|
122
126
|
- empty strings are converted to boolean `false`
|
123
127
|
- all other values pass straight through without conversion and log a warning message
|
128
|
+
- for arrays each value gets processed separately using rules above
|
124
129
|
|
125
130
|
This plugin can convert multiple fields in the same document, see the example below.
|
126
131
|
|
@@ -207,8 +207,8 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
|
|
207
207
|
# }
|
208
208
|
config :copy, :validate => :hash
|
209
209
|
|
210
|
-
TRUE_REGEX = (/^(true|t|yes|y|1)$/i).freeze
|
211
|
-
FALSE_REGEX = (/^(false|f|no|n|0)$/i).freeze
|
210
|
+
TRUE_REGEX = (/^(true|t|yes|y|1|1.0)$/i).freeze
|
211
|
+
FALSE_REGEX = (/^(false|f|no|n|0|0.0)$/i).freeze
|
212
212
|
CONVERT_PREFIX = "convert_".freeze
|
213
213
|
|
214
214
|
def register
|
@@ -327,8 +327,8 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
|
|
327
327
|
end
|
328
328
|
|
329
329
|
def convert_boolean(value)
|
330
|
-
return true if value =~ TRUE_REGEX
|
331
|
-
return false if value.empty? || value =~ FALSE_REGEX
|
330
|
+
return true if value.to_s =~ TRUE_REGEX
|
331
|
+
return false if value.to_s.empty? || value.to_s =~ FALSE_REGEX
|
332
332
|
@logger.warn("Failed to convert #{value} into boolean.")
|
333
333
|
value
|
334
334
|
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.
|
4
|
+
s.version = '3.4.0'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "Performs mutations on fields"
|
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"
|
data/spec/filters/mutate_spec.rb
CHANGED
@@ -373,45 +373,78 @@ describe LogStash::Filters::Mutate do
|
|
373
373
|
config <<-CONFIG
|
374
374
|
filter {
|
375
375
|
mutate {
|
376
|
-
convert => { "true_field"
|
377
|
-
convert => { "false_field"
|
378
|
-
convert => { "true_upper"
|
379
|
-
convert => { "false_upper"
|
380
|
-
convert => { "true_one"
|
381
|
-
convert => { "false_zero"
|
382
|
-
convert => { "true_yes"
|
383
|
-
convert => { "false_no"
|
384
|
-
convert => { "true_y"
|
385
|
-
convert => { "false_n"
|
386
|
-
convert => { "wrong_field"
|
376
|
+
convert => { "true_field" => "boolean" }
|
377
|
+
convert => { "false_field" => "boolean" }
|
378
|
+
convert => { "true_upper" => "boolean" }
|
379
|
+
convert => { "false_upper" => "boolean" }
|
380
|
+
convert => { "true_one" => "boolean" }
|
381
|
+
convert => { "false_zero" => "boolean" }
|
382
|
+
convert => { "true_yes" => "boolean" }
|
383
|
+
convert => { "false_no" => "boolean" }
|
384
|
+
convert => { "true_y" => "boolean" }
|
385
|
+
convert => { "false_n" => "boolean" }
|
386
|
+
convert => { "wrong_field" => "boolean" }
|
387
|
+
convert => { "integer_false" => "boolean" }
|
388
|
+
convert => { "integer_true" => "boolean" }
|
389
|
+
convert => { "integer_negative" => "boolean" }
|
390
|
+
convert => { "integer_wrong" => "boolean" }
|
391
|
+
convert => { "float_true" => "boolean" }
|
392
|
+
convert => { "float_false" => "boolean" }
|
393
|
+
convert => { "float_negative" => "boolean" }
|
394
|
+
convert => { "float_wrong" => "boolean" }
|
395
|
+
convert => { "float_wrong2" => "boolean" }
|
396
|
+
convert => { "array" => "boolean" }
|
397
|
+
convert => { "hash" => "boolean" }
|
387
398
|
}
|
388
399
|
}
|
389
400
|
CONFIG
|
390
401
|
event = {
|
391
|
-
"true_field"
|
392
|
-
"false_field"
|
393
|
-
"true_upper"
|
394
|
-
"false_upper"
|
395
|
-
"true_one"
|
396
|
-
"false_zero"
|
397
|
-
"true_yes"
|
398
|
-
"false_no"
|
399
|
-
"true_y"
|
400
|
-
"false_n"
|
401
|
-
"wrong_field"
|
402
|
+
"true_field" => "true",
|
403
|
+
"false_field" => "false",
|
404
|
+
"true_upper" => "True",
|
405
|
+
"false_upper" => "False",
|
406
|
+
"true_one" => "1",
|
407
|
+
"false_zero" => "0",
|
408
|
+
"true_yes" => "yes",
|
409
|
+
"false_no" => "no",
|
410
|
+
"true_y" => "Y",
|
411
|
+
"false_n" => "N",
|
412
|
+
"wrong_field" => "none of the above",
|
413
|
+
"integer_false" => 0,
|
414
|
+
"integer_true" => 1,
|
415
|
+
"integer_negative"=> -1,
|
416
|
+
"integer_wrong" => 2,
|
417
|
+
"float_true" => 1.0,
|
418
|
+
"float_false" => 0.0,
|
419
|
+
"float_negative" => -1.0,
|
420
|
+
"float_wrong" => 1.0123,
|
421
|
+
"float_wrong2" => 0.01,
|
422
|
+
"array" => [ "1", "0", 0,1,2],
|
423
|
+
"hash" => { "a" => 0 }
|
402
424
|
}
|
403
425
|
sample event do
|
404
|
-
expect(subject.get("true_field")
|
405
|
-
expect(subject.get("false_field")).to eq(false)
|
406
|
-
expect(subject.get("true_upper")
|
407
|
-
expect(subject.get("false_upper")).to eq(false)
|
408
|
-
expect(subject.get("true_one")
|
409
|
-
expect(subject.get("false_zero")
|
410
|
-
expect(subject.get("true_yes")
|
411
|
-
expect(subject.get("false_no")
|
412
|
-
expect(subject.get("true_y")
|
413
|
-
expect(subject.get("false_n")
|
414
|
-
expect(subject.get("wrong_field")).to eq("none of the above")
|
426
|
+
expect(subject.get("true_field") ).to eq(true)
|
427
|
+
expect(subject.get("false_field") ).to eq(false)
|
428
|
+
expect(subject.get("true_upper") ).to eq(true)
|
429
|
+
expect(subject.get("false_upper") ).to eq(false)
|
430
|
+
expect(subject.get("true_one") ).to eq(true)
|
431
|
+
expect(subject.get("false_zero") ).to eq(false)
|
432
|
+
expect(subject.get("true_yes") ).to eq(true)
|
433
|
+
expect(subject.get("false_no") ).to eq(false)
|
434
|
+
expect(subject.get("true_y") ).to eq(true)
|
435
|
+
expect(subject.get("false_n") ).to eq(false)
|
436
|
+
expect(subject.get("wrong_field") ).to eq("none of the above")
|
437
|
+
expect(subject.get("integer_false") ).to eq(false)
|
438
|
+
expect(subject.get("integer_true") ).to eq(true)
|
439
|
+
expect(subject.get("integer_negative")).to eq(-1)
|
440
|
+
expect(subject.get("integer_wrong") ).to eq(2)
|
441
|
+
expect(subject.get("float_true") ).to eq(true)
|
442
|
+
expect(subject.get("float_false") ).to eq(false)
|
443
|
+
expect(subject.get("float_negative") ).to eq(-1.0)
|
444
|
+
expect(subject.get("float_wrong") ).to eq(1.0123)
|
445
|
+
expect(subject.get("float_wrong2") ).to eq(0.01)
|
446
|
+
expect(subject.get("array") ).to eq([true, false, false, true,2])
|
447
|
+
expect(subject.get("hash") ).to eq({ "a" => 0 })
|
415
448
|
end
|
416
449
|
end
|
417
450
|
|
@@ -487,7 +520,7 @@ describe LogStash::Filters::Mutate do
|
|
487
520
|
end
|
488
521
|
end
|
489
522
|
end
|
490
|
-
|
523
|
+
|
491
524
|
|
492
525
|
describe "convert to float_eu" do
|
493
526
|
config <<-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.
|
4
|
+
version: 3.4.0
|
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: 2019-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|