logstash-filter-mutate 0.1.6 → 0.1.7

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: 7d26ee5529a4d9879fb70a0267ce32060712f100
4
- data.tar.gz: a18fdc2cc2140ccbc6bab53086642c9e51cb78bb
3
+ metadata.gz: 2deb0b46d89acc42b78efb99ca7b9ff488c0549a
4
+ data.tar.gz: 3fcf4bdb6d92975fcb936a5f215587b3d1b0c0d8
5
5
  SHA512:
6
- metadata.gz: ad38c92e66e0a5dc47d8dac485a8e2c16619b8c50b9c068f6f15c7fe2bf3275fa1fd7b0da1a94b123e5f6486442da6a7122922cf9051970e9ae4284291cbd744
7
- data.tar.gz: c6a00cc9e2a431f0fdb1674ceb6cfc2284f0a6e8e623f12601f9d51b1b3fb0f129ae2aaed5fbf4e63198ab63609d4a116398e6b4f55c324cb1389de67d732178
6
+ metadata.gz: 9cfdca9495c7a3c22c29886a4724aa9549f43a6ab6f7754e48d236cd212135bdcc3849e449b4df45719c07e8373474e6734e7c6f4a79b489db59170a367d5b63
7
+ data.tar.gz: 0322e26d0696ac60709dd205df9377a91016d8d510e4496cc6e459e436f684140dc5ecd3232980958c0e940617149ef5a1c6123e03873990fcd13e270e36c01f
@@ -63,7 +63,13 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
63
63
  # integer. If the field value is an array, all members will be converted.
64
64
  # If the field is a hash, no action will be taken.
65
65
  #
66
- # Valid conversion targets are: integer, float, string.
66
+ # If the conversion type is `boolean`, the acceptable values are:
67
+ # **True:** `true`, `t`, `yes`, `y`, and `1`
68
+ # **False:** `false`, `f`, `no`, `n`, and `0`
69
+ # "true" and "false". If a value other than these is provided, it will
70
+ # pass straight through and log a warning message.
71
+ #
72
+ # Valid conversion targets are: integer, float, string, and boolean.
67
73
  #
68
74
  # Example:
69
75
  # [source,ruby]
@@ -172,7 +178,7 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
172
178
 
173
179
  public
174
180
  def register
175
- valid_conversions = %w(string integer float)
181
+ valid_conversions = %w(string integer float boolean)
176
182
  # TODO(sissel): Validate conversion requests if provided.
177
183
  @convert.nil? or @convert.each do |field, type|
178
184
  if !valid_conversions.include?(type)
@@ -254,8 +260,7 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
254
260
  @convert.each do |field, type|
255
261
  next unless event.include?(field)
256
262
  original = event[field]
257
-
258
- # calls convert_{string,integer,float} depending on type requested.
263
+ # calls convert_{string,integer,float,boolean} depending on type requested.
259
264
  converter = method("convert_" + type)
260
265
  if original.nil?
261
266
  next
@@ -288,6 +293,13 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
288
293
  return value.to_f
289
294
  end # def convert_float
290
295
 
296
+ def convert_boolean(value)
297
+ return true if value =~ (/^(true|t|yes|y|1)$/i)
298
+ return false if value.empty? || value =~ (/^(false|f|no|n|0)$/i)
299
+ @logger.warn("Failed to convert #{value} into boolean.")
300
+ return value
301
+ end # def convert_boolean
302
+
291
303
  private
292
304
  def gsub(event)
293
305
  @gsub_parsed.each do |config|
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-mutate'
4
- s.version = '0.1.6'
4
+ s.version = '0.1.7'
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/plugin install gemname. This gem is not a stand-alone program"
@@ -25,4 +25,3 @@ Gem::Specification.new do |s|
25
25
  s.add_runtime_dependency 'logstash-filter-grok'
26
26
  s.add_development_dependency 'logstash-devutils'
27
27
  end
28
-
@@ -114,6 +114,52 @@ describe LogStash::Filters::Mutate do
114
114
  end
115
115
  end
116
116
 
117
+ describe "convert strings to boolean values" do
118
+ config <<-CONFIG
119
+ filter {
120
+ mutate {
121
+ convert => { "true_field" => "boolean" }
122
+ convert => { "false_field" => "boolean" }
123
+ convert => { "true_upper" => "boolean" }
124
+ convert => { "false_upper" => "boolean" }
125
+ convert => { "true_one" => "boolean" }
126
+ convert => { "false_zero" => "boolean" }
127
+ convert => { "true_yes" => "boolean" }
128
+ convert => { "false_no" => "boolean" }
129
+ convert => { "true_y" => "boolean" }
130
+ convert => { "false_n" => "boolean" }
131
+ convert => { "wrong_field" => "boolean" }
132
+ }
133
+ }
134
+ CONFIG
135
+ event = {
136
+ "true_field" => "true",
137
+ "false_field" => "false",
138
+ "true_upper" => "True",
139
+ "false_upper" => "False",
140
+ "true_one" => "1",
141
+ "false_zero" => "0",
142
+ "true_yes" => "yes",
143
+ "false_no" => "no",
144
+ "true_y" => "Y",
145
+ "false_n" => "N",
146
+ "wrong_field" => "none of the above"
147
+ }
148
+ sample event do
149
+ expect(subject["true_field"] ).to eq(true)
150
+ expect(subject["false_field"]).to eq(false)
151
+ expect(subject["true_upper"] ).to eq(true)
152
+ expect(subject["false_upper"]).to eq(false)
153
+ expect(subject["true_one"] ).to eq(true)
154
+ expect(subject["false_zero"] ).to eq(false)
155
+ expect(subject["true_yes"] ).to eq(true)
156
+ expect(subject["false_no"] ).to eq(false)
157
+ expect(subject["true_y"] ).to eq(true)
158
+ expect(subject["false_n"] ).to eq(false)
159
+ expect(subject["wrong_field"]).to eq("none of the above")
160
+ end
161
+ end
162
+
117
163
  describe "gsub on a String" do
118
164
  config '
119
165
  filter {
@@ -382,4 +428,3 @@ describe LogStash::Filters::Mutate do
382
428
  end
383
429
 
384
430
  end
385
-
metadata CHANGED
@@ -1,17 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-mutate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2015-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- requirement: !ruby/object:Gem::Requirement
14
+ name: logstash-core
15
+ version_requirements: !ruby/object:Gem::Requirement
15
16
  requirements:
16
17
  - - '>='
17
18
  - !ruby/object:Gem::Version
@@ -19,10 +20,7 @@ dependencies:
19
20
  - - <
20
21
  - !ruby/object:Gem::Version
21
22
  version: 2.0.0
22
- name: logstash-core
23
- prerelease: false
24
- type: :runtime
25
- version_requirements: !ruby/object:Gem::Requirement
23
+ requirement: !ruby/object:Gem::Requirement
26
24
  requirements:
27
25
  - - '>='
28
26
  - !ruby/object:Gem::Version
@@ -30,48 +28,50 @@ dependencies:
30
28
  - - <
31
29
  - !ruby/object:Gem::Version
32
30
  version: 2.0.0
31
+ prerelease: false
32
+ type: :runtime
33
33
  - !ruby/object:Gem::Dependency
34
+ name: logstash-patterns-core
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
34
40
  requirement: !ruby/object:Gem::Requirement
35
41
  requirements:
36
42
  - - '>='
37
43
  - !ruby/object:Gem::Version
38
44
  version: '0'
39
- name: logstash-patterns-core
40
45
  prerelease: false
41
46
  type: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: logstash-filter-grok
42
49
  version_requirements: !ruby/object:Gem::Requirement
43
50
  requirements:
44
51
  - - '>='
45
52
  - !ruby/object:Gem::Version
46
53
  version: '0'
47
- - !ruby/object:Gem::Dependency
48
54
  requirement: !ruby/object:Gem::Requirement
49
55
  requirements:
50
56
  - - '>='
51
57
  - !ruby/object:Gem::Version
52
58
  version: '0'
53
- name: logstash-filter-grok
54
59
  prerelease: false
55
60
  type: :runtime
61
+ - !ruby/object:Gem::Dependency
62
+ name: logstash-devutils
56
63
  version_requirements: !ruby/object:Gem::Requirement
57
64
  requirements:
58
65
  - - '>='
59
66
  - !ruby/object:Gem::Version
60
67
  version: '0'
61
- - !ruby/object:Gem::Dependency
62
68
  requirement: !ruby/object:Gem::Requirement
63
69
  requirements:
64
70
  - - '>='
65
71
  - !ruby/object:Gem::Version
66
72
  version: '0'
67
- name: logstash-devutils
68
73
  prerelease: false
69
74
  type: :development
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - '>='
73
- - !ruby/object:Gem::Version
74
- version: '0'
75
75
  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
76
76
  email: info@elastic.co
77
77
  executables: []
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  requirements: []
111
111
  rubyforge_project:
112
- rubygems_version: 2.1.9
112
+ rubygems_version: 2.2.2
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: The mutate filter allows you to perform general mutations on fields. You can rename, remove, replace, and modify fields in your events.