logstash-filter-xml 3.0.1 → 4.0.0

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: ffb5fe018cd5b200542dbf05659717098a28a774
4
- data.tar.gz: 08e30920d683357ce04971b45baf654ffaaeaeac
3
+ metadata.gz: 8b31248ae74ec510edd487e3fa3027fd74aa42b5
4
+ data.tar.gz: a18009abaf99dd29a9f671db974604d8496373ae
5
5
  SHA512:
6
- metadata.gz: 3503a6edfc5b325008d21993b36a5545004836c258387f756cc33ee75f1c0212726e79b03097c136f333208722611d6d44d76276de13abed094214a077a81b00
7
- data.tar.gz: e09bcb380e9a1d04a8d04932a0c268f139a7450a676d26e7cf1839b48afc0a70e1023299ed2c08b5abbf454fefe392ee036e7e01e8fe5fe49f77b06df2c2d26f
6
+ metadata.gz: 7eef1c44fbfa9b7d8ea09fe1fb077c92a4ebd4dc0614a2e19eb9fd71f14410bc3369385ad78ec51d60242436dc8b5ff8e3c07f9fb34da347077590bb2951c7f2
7
+ data.tar.gz: b1231cacd1b1502de53383b8c059828925b826f206c66eb2e2d2383d39bb0c235e16e3d0c65ad9623a818d76bf5bd45a01a4f59fe29bae3d2a0728c81e93f1dc
data/CHANGELOG.md CHANGED
@@ -1,13 +1,24 @@
1
+ ## 4.0.0
2
+ - breaking,config: New configuration `suppress_empty`. Default to true change default behaviour of the plugin in favor of avoiding mapping conflicts when reaching elasticsearch
3
+ - config: New configuration `force_content`. By default the filter expands attributes differently from content in xml elements.
4
+ This option allows you to force text content and attributes to always parse to a hash value.
5
+ - config: Ensure that `target` is set when storing xml content in the event (`store_xml => true`)
6
+
1
7
  ## 3.0.1
2
8
  - Republish all the gems under jruby.
9
+
3
10
  ## 3.0.0
4
11
  - Update the plugin to the version 2.0 of the plugin api, this change is required for Logstash 5.0 compatibility. See https://github.com/elastic/logstash/issues/5141
5
- # 2.1.4
12
+
13
+ ## 2.1.4
6
14
  - Added setting to disable forcing single values to be added in arrays. Ref: https://github.com/logstash-plugins/logstash-filter-xml/pull/28.
7
- # 2.1.3
15
+
16
+ ## 2.1.3
8
17
  - Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash
9
- # 2.1.2
18
+
19
+ ## 2.1.2
10
20
  - New dependency requirements for logstash-core for the 5.0 release
21
+
11
22
  ## 2.1.1
12
23
  - Refactored field references, code cleanups
13
24
 
@@ -51,10 +51,10 @@ class LogStash::Filters::Xml < LogStash::Filters::Base
51
51
  # destination field as an array. As such, multiple matches across
52
52
  # multiple source fields will produce duplicate entries in the field.
53
53
  #
54
- # More on XPath: http://www.w3schools.com/xpath/
54
+ # More on XPath: http://www.w3schools.com/xml/xml_xpath.asp
55
55
  #
56
56
  # The XPath functions are particularly powerful:
57
- # http://www.w3schools.com/xpath/xpath_functions.asp
57
+ # http://www.w3schools.com/xsl/xsl_functions.asp
58
58
  #
59
59
  config :xpath, :validate => :hash, :default => {}
60
60
 
@@ -66,6 +66,11 @@ class LogStash::Filters::Xml < LogStash::Filters::Base
66
66
  # false will prevent storing single elements in arrays.
67
67
  config :force_array, :validate => :boolean, :default => true
68
68
 
69
+ # By default the filter will expand attributes differently from content inside
70
+ # of tags. This option allows you to force text content and attributes to always
71
+ # parse to a hash value.
72
+ config :force_content, :validate => :boolean, :default => false
73
+
69
74
  # By default only namespaces declarations on the root element are considered.
70
75
  # This allows to configure all namespace declarations to parse the XML document.
71
76
  #
@@ -87,11 +92,24 @@ class LogStash::Filters::Xml < LogStash::Filters::Base
87
92
  # Of course, if the document had nodes with the same names but different namespaces, they will now be ambiguous.
88
93
  config :remove_namespaces, :validate => :boolean, :default => false
89
94
 
95
+ # By default, output nothing if the element is empty.
96
+ # If set to `false`, empty element will result in an empty hash object.
97
+ config :suppress_empty, :validate => :boolean, :default => true
98
+
90
99
  XMLPARSEFAILURE_TAG = "_xmlparsefailure"
91
100
 
92
101
  def register
93
102
  require "nokogiri"
94
103
  require "xmlsimple"
104
+
105
+ if @store_xml && (!@target || @target.empty?)
106
+ raise LogStash::ConfigurationError, I18n.t(
107
+ "logstash.agent.configuration.invalid_plugin_register",
108
+ :plugin => "filter",
109
+ :type => "xml",
110
+ :error => "When the 'store_xml' configuration option is true, 'target' must also be set"
111
+ )
112
+ end
95
113
  end
96
114
 
97
115
  def filter(event)
@@ -159,7 +177,9 @@ class LogStash::Filters::Xml < LogStash::Filters::Base
159
177
 
160
178
  if @store_xml
161
179
  begin
162
- event.set(@target, XmlSimple.xml_in(value, "ForceArray" => @force_array))
180
+ xml_options = {"ForceArray" => @force_array, "ForceContent" => @force_content}
181
+ xml_options["SuppressEmpty"] = true if @suppress_empty
182
+ event.set(@target, XmlSimple.xml_in(value, xml_options))
163
183
  matched = true
164
184
  rescue => e
165
185
  event.tag(XMLPARSEFAILURE_TAG)
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-xml'
4
- s.version = '3.0.1'
4
+ s.version = '4.0.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Takes a field that contains XML and expands it into an actual datastructure."
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"
@@ -209,6 +209,7 @@ describe LogStash::Filters::Xml do
209
209
  source => "xmldata"
210
210
  xpath => [ "/foo/h:div", "xpath_field" ]
211
211
  remove_namespaces => false
212
+ store_xml => false
212
213
  }
213
214
  }
214
215
  CONFIG
@@ -227,6 +228,7 @@ describe LogStash::Filters::Xml do
227
228
  xpath => [ "/foo/h:div", "xpath_field" ]
228
229
  namespaces => {"h" => "http://www.w3.org/TR/html4/"}
229
230
  remove_namespaces => false
231
+ store_xml => false
230
232
  }
231
233
  }
232
234
  CONFIG
@@ -245,6 +247,7 @@ describe LogStash::Filters::Xml do
245
247
  xpath => [ "/foo/h:div", "xpath_field" ]
246
248
  namespaces => {"h" => "http://www.w3.org/TR/html4/"}
247
249
  remove_namespaces => false
250
+ store_xml => false
248
251
  }
249
252
  }
250
253
  CONFIG
@@ -262,6 +265,7 @@ describe LogStash::Filters::Xml do
262
265
  source => "xmldata"
263
266
  xpath => [ "/foo/div", "xpath_field" ]
264
267
  remove_namespaces => true
268
+ store_xml => false
265
269
  }
266
270
  }
267
271
  CONFIG
@@ -305,4 +309,92 @@ describe LogStash::Filters::Xml do
305
309
  insist { subject.get("parseddata") } == { "bar" => "Content" }
306
310
  end
307
311
  end
312
+
313
+ context "Using suppress_empty option" do
314
+ describe "suppress_empty => false" do
315
+ config <<-CONFIG
316
+ filter {
317
+ xml {
318
+ source => "xmldata"
319
+ target => "data"
320
+ suppress_empty => false
321
+ }
322
+ }
323
+ CONFIG
324
+
325
+ sample("xmldata" => '<foo><key>value1</key><key></key></foo>') do
326
+ insist { subject.get("tags") }.nil?
327
+ insist { subject.get("data") } == {"key" => ["value1", {}]}
328
+ end
329
+ end
330
+
331
+ describe "suppress_empty => true" do
332
+ config <<-CONFIG
333
+ filter {
334
+ xml {
335
+ source => "xmldata"
336
+ target => "data"
337
+ suppress_empty => true
338
+ }
339
+ }
340
+ CONFIG
341
+
342
+ sample("xmldata" => '<foo><key>value1</key><key></key></foo>') do
343
+ insist { subject.get("tags") }.nil?
344
+ insist { subject.get("data") } == {"key" => ["value1"]}
345
+ end
346
+ end
347
+ end
348
+
349
+ context "Using force content option" do
350
+ describe "force_content => false" do
351
+ config <<-CONFIG
352
+ filter {
353
+ xml {
354
+ source => "xmldata"
355
+ target => "data"
356
+ force_array => false
357
+ force_content => false
358
+ }
359
+ }
360
+ CONFIG
361
+
362
+ sample("xmldata" => '<opt><x>text1</x><y a="2">text2</y></opt>') do
363
+ insist { subject.get("tags") }.nil?
364
+ insist { subject.get("data") } == { 'x' => 'text1', 'y' => { 'a' => '2', 'content' => 'text2' } }
365
+ end
366
+ end
367
+ describe "force_content => true" do
368
+ config <<-CONFIG
369
+ filter {
370
+ xml {
371
+ source => "xmldata"
372
+ target => "data"
373
+ force_array => false
374
+ force_content => true
375
+ }
376
+ }
377
+ CONFIG
378
+
379
+ sample("xmldata" => '<opt><x>text1</x><y a="2">text2</y></opt>') do
380
+ insist { subject.get("tags") }.nil?
381
+ insist { subject.get("data") } == { 'x' => { 'content' => 'text1' }, 'y' => { 'a' => '2', 'content' => 'text2' } }
382
+ end
383
+ end
384
+ end
385
+
386
+ describe "plugin registration" do
387
+ config <<-CONFIG
388
+ filter {
389
+ xml {
390
+ xmldata => "message"
391
+ store_xml => true
392
+ }
393
+ }
394
+ CONFIG
395
+
396
+ sample("xmldata" => "<foo>random message</foo>") do
397
+ insist { subject }.raises(LogStash::ConfigurationError)
398
+ end
399
+ end
308
400
  end
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-09 00:00:00.000000000 Z
11
+ date: 2016-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: logstash-core-plugin-api
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
14
20
  requirement: !ruby/object:Gem::Requirement
15
21
  requirements:
16
- - - "~>"
22
+ - - ~>
17
23
  - !ruby/object:Gem::Version
18
24
  version: '2.0'
19
- name: logstash-core-plugin-api
20
25
  prerelease: false
21
26
  type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
22
29
  version_requirements: !ruby/object:Gem::Requirement
23
30
  requirements:
24
- - - "~>"
31
+ - - '>='
25
32
  - !ruby/object:Gem::Version
26
- version: '2.0'
27
- - !ruby/object:Gem::Dependency
33
+ version: '0'
28
34
  requirement: !ruby/object:Gem::Requirement
29
35
  requirements:
30
- - - ">="
36
+ - - '>='
31
37
  - !ruby/object:Gem::Version
32
38
  version: '0'
33
- name: nokogiri
34
39
  prerelease: false
35
40
  type: :runtime
41
+ - !ruby/object:Gem::Dependency
42
+ name: xml-simple
36
43
  version_requirements: !ruby/object:Gem::Requirement
37
44
  requirements:
38
- - - ">="
45
+ - - '>='
39
46
  - !ruby/object:Gem::Version
40
47
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
48
  requirement: !ruby/object:Gem::Requirement
43
49
  requirements:
44
- - - ">="
50
+ - - '>='
45
51
  - !ruby/object:Gem::Version
46
52
  version: '0'
47
- name: xml-simple
48
53
  prerelease: false
49
54
  type: :runtime
55
+ - !ruby/object:Gem::Dependency
56
+ name: logstash-devutils
50
57
  version_requirements: !ruby/object:Gem::Requirement
51
58
  requirements:
52
- - - ">="
59
+ - - '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
62
  requirement: !ruby/object:Gem::Requirement
57
63
  requirements:
58
- - - ">="
64
+ - - '>='
59
65
  - !ruby/object:Gem::Version
60
66
  version: '0'
61
- name: logstash-devutils
62
67
  prerelease: false
63
68
  type: :development
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
69
  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
70
70
  email: info@elastic.co
71
71
  executables: []
@@ -93,12 +93,12 @@ require_paths:
93
93
  - lib
94
94
  required_ruby_version: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - ">="
96
+ - - '>='
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  requirements: []