logstash-filter-xml 2.1.4 → 2.2.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: 0bbe7a26079ee72f9c7ff4a22f793757f798d664
4
- data.tar.gz: 463335a351bae555a468961e02f8bd2e06757552
3
+ metadata.gz: 3c54641de27d0a2d3d1521cf95ca13053cf79fdf
4
+ data.tar.gz: 45fa43b4e3e0e8d55de05be69ab68c8b2e63b8e0
5
5
  SHA512:
6
- metadata.gz: 895e1fabb1950929973a761d0c3899e5cfe6854b2c0a1b71184b75260fe10167c52a0e8d4b1a1b176a39d3b3b695b58ea8dfaf42dc68cc1ffc45d4e49b0ffd82
7
- data.tar.gz: ef8a46d212ede4351ffcbf62f562dff080557279530e7cfa432f827a3d8afb7dd4c0fe47f6b314c5392e08c40f3e70728b53a391398c37e5efd41752cd27f5ef
6
+ metadata.gz: e43cd5a04b877149db47c036303f1a74cfef0e6f3033c5994409f2d98edd957dcd9dcefff64e679bee7f134aa1e737c37c5b39adc21143223807e78f2580cec0
7
+ data.tar.gz: a54963d0704933285befe3b70ef4ec35fd921808cea3c631d5900cb0a6934fcc8c48e863f3d722eeccff1d82027289a4b837dd3054d0061698bbb25d1ed1af0c
@@ -1,9 +1,19 @@
1
- # 2.1.4
1
+ ## 2.2.0
2
+ - config: New configuration `suppress_empty`. By default the filter creates empty hash from empty xml elements (`suppress_empty => false`).
3
+ This can now be configured, `supress_empty => true` will not create event fields from empty xml elements.
4
+ - config: New configuration `force_content`. By default the filter expands attributes differently from content in xml elements.
5
+ This option allows you to force text content and attributes to always parse to a hash value.
6
+ - config: Ensure that `target` is set when storing xml content in the event (`store_xml => true`)
7
+
8
+ ## 2.1.4
2
9
  - Added setting to disable forcing single values to be added in arrays. Ref: https://github.com/logstash-plugins/logstash-filter-xml/pull/28.
3
- # 2.1.3
10
+
11
+ ## 2.1.3
4
12
  - Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash
5
- # 2.1.2
13
+
14
+ ## 2.1.2
6
15
  - New dependency requirements for logstash-core for the 5.0 release
16
+
7
17
  ## 2.1.1
8
18
  - Refactored field references, code cleanups
9
19
 
@@ -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, empty element will result in an empty hash object
96
+ # If set to `true`, output nothing if the element is empty..
97
+ config :suppress_empty, :validate => :boolean, :default => false
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)
@@ -163,7 +181,9 @@ class LogStash::Filters::Xml < LogStash::Filters::Base
163
181
 
164
182
  if @store_xml
165
183
  begin
166
- event[@target] = XmlSimple.xml_in(value, "ForceArray" => @force_array)
184
+ xml_options = {"ForceArray" => @force_array, "ForceContent" => @force_content}
185
+ xml_options["SuppressEmpty"] = true if @suppress_empty
186
+ event[@target] = XmlSimple.xml_in(value, xml_options)
167
187
  matched = true
168
188
  rescue => e
169
189
  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 = '2.1.4'
4
+ s.version = '2.2.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
@@ -306,4 +310,92 @@ describe LogStash::Filters::Xml do
306
310
  end
307
311
  end
308
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["tags"] }.nil?
327
+ insist { subject["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["tags"] }.nil?
344
+ insist { subject["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["tags"] }.nil?
364
+ insist { subject["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["tags"] }.nil?
381
+ insist { subject["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
400
+
309
401
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4
4
+ version: 2.2.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-04-25 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
14
  name: logstash-core-plugin-api