fluent-plugin-xml-parser 0.0.1 → 0.0.2

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: b080b8bbb4fef60f53d153d3a0c7f72a71465906
4
- data.tar.gz: 0ade2363ce81d3d3639b7fa7977382b3dfdb4f8c
3
+ metadata.gz: 23d3406d82a44a2830bb0c1f1efbbbf38e9b4f44
4
+ data.tar.gz: 3af74358485266fabc9b6aa6c3a71438a5a9ecd9
5
5
  SHA512:
6
- metadata.gz: ba3f247d30b10a7e21bfebaaff9b1ce569e7f7366c2a22e69dbc1486937b05396529ed4ae3eed15609f3b46efd88abbd68bf5cca8f51af14506002f2747de0fb
7
- data.tar.gz: 8535026f8b26aac6d7ec9d5005419f94a65a2f3c1257de02caea45f2ee7648709a160a82b463e12b0d685adbe65f805a0b6cf650eb716b1722aadef8c53baf64
6
+ metadata.gz: 8c8a19e8665cf5b276017378c337ac3c5cb8da6f02ad457587ac8d9593acc2c81959cde3c2a42e8c7ef3bdac3aaf447f60280cba08b77ab7c3a8fd308e647ac8
7
+ data.tar.gz: eb7de25d711da38b66fdf67c9ec3ed9a56e46c33d97c1ac773b88dbc7cd92479f65638fb5d061d4da574faf2e98a9895e236b551cee2210e035870554ef92ab2
data/README.md CHANGED
@@ -31,12 +31,16 @@ The followings are an example description for Libelium SmartCity sensor data.
31
31
  bind 127.0.0.1
32
32
  port 1883
33
33
  format xml
34
- attr_xpaths '[[null, "@timestamp"], ["cap:alert/cap:info/cap:parameter/cap:valueName", "text"], [null, "location"]]'
35
- value_xpaths '[["cap:alert/cap:info/cap:onset", "text"], ["cap:alert/cap:info/cap:parameter/cap:value", "text"], [null, "Kyoto"]]'
34
+ time_xpath '["cap:alert/cap:info/cap:onset", "text"]'
35
+ attr_xpaths '[[null, "description"], ["cap:alert/cap:info/cap:parameter/cap:valueName", "text"]]'
36
+ value_xpaths '[["cap:alert/cap:info/cap:description", "text"], ["cap:alert/cap:info/cap:parameter/cap:value", "text"]]'
36
37
  </source>
37
38
 
38
39
  ```
39
40
 
41
+ time_xpath specifies timestamp filed value. An array with two strings means xpath of
42
+ the value and the attribute of the XML element (name, text etc).
43
+
40
44
  attr_xpaths indicates attribute name of the target value. Each array with two strings
41
45
  means xpath of the attribute name and the attribute of the XML element (name, text etc).
42
46
  XPath can be omitted as 'null' and specify your own attribute name as the second
@@ -46,6 +50,8 @@ value_xpaths indicates the target value to be extracted. Each array with two str
46
50
  means xpath of the target value and the attribute of the XML element (name, text etc).
47
51
  XPath can be omitted as 'null' and specify your own value as the second parameter.
48
52
 
53
+ The extracted fields are packed into Hash structure (record field) to emit the next procedure in fluentd.
54
+
49
55
  You can check your own XML data structure by using irb or pry
50
56
 
51
57
  ```
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-xml-parser"
7
- spec.version = "0.0.1"
7
+ spec.version = "0.0.2"
8
8
  spec.authors = ["Toyokazu Akiyama"]
9
9
  spec.email = ["toyokazu@gmail.com"]
10
10
  spec.summary = %q{fluentd xml parser plugin}
@@ -8,8 +8,9 @@ module Fluent
8
8
  # How to specify the target attributes and values
9
9
  # The followings are an example description for Libelium SmartCity sensor data.
10
10
  #
11
- # attr_xpaths '[[null, "@timestamp"], ["cap:alert/cap:info/cap:parameter/cap:valueName", "text"], [null, "location"]]'
12
- # value_xpaths '[["cap:alert/cap:info/cap:onset", "text"], ["cap:alert/cap:info/cap:parameter/cap:value", "text"], [null, "Kyoto"]]'
11
+ # time_xpath '["cap:alert/cap:info/cap:onset", "text"]'
12
+ # attr_xpaths '[[null, "description"], ["cap:alert/cap:info/cap:parameter/cap:valueName", "text"]]'
13
+ # value_xpaths '[["cap:alert/cap:info/cap:description", "text"], ["cap:alert/cap:info/cap:parameter/cap:value", "text"]]'
13
14
  #
14
15
  # attr_xpaths indicates attribute name of the target value. Each array with two strings
15
16
  # means xpath of the attribute name and the attribute of the XML element (name, text etc).
@@ -26,6 +27,7 @@ module Fluent
26
27
  # doc = REXML::Document.new(open("test.xml"))
27
28
  # doc.elements['cap:alert/cap:info'].children
28
29
  #
30
+ config_param :time_xpath, :string, :default => '[]'
29
31
  config_param :attr_xpaths, :string, :default => '[]'
30
32
  config_param :value_xpaths, :string, :default => '[]'
31
33
  config_param :time_format, :string, :default => nil # time_format is configurable
@@ -33,6 +35,7 @@ module Fluent
33
35
  def configure(conf)
34
36
  super
35
37
 
38
+ @time_xpath = json_parse(conf['time_xpath'])
36
39
  @attr_xpaths = json_parse(conf['attr_xpaths'])
37
40
  @value_xpaths = json_parse(conf['value_xpaths'])
38
41
  @time_format = conf['time_format']
@@ -48,6 +51,8 @@ module Fluent
48
51
  begin
49
52
  doc = REXML::Document.new(text)
50
53
  $log.debug doc
54
+ # parse time field
55
+ @time = @time_parser.parse(doc.elements[@time_xpath[0]].method(@time_xpath[1]).call)
51
56
  record = {}
52
57
  attrs = @attr_xpaths.map do |attr_xpath|
53
58
  if attr_xpath[0].nil? # when null is specified
@@ -64,12 +69,7 @@ module Fluent
64
69
  end
65
70
  end
66
71
  attrs.size.times do |i|
67
- if i == 0 # time value
68
- @time = @time_parser.parse(values[i])
69
- record[attrs[i]] = @time
70
- else
71
- record[attrs[i]] = values[i]
72
- end
72
+ record[attrs[i]] = values[i]
73
73
  end
74
74
  yield @time, record
75
75
  rescue REXML::ParseException => e
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-xml-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toyokazu Akiyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-03 00:00:00.000000000 Z
11
+ date: 2015-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler