fluent-plugin-xml-parser 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fluent-plugin-xml-parser.gemspec +1 -1
- data/lib/fluent/plugin/parser_xml.rb +22 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44c77dc562482affd2975f6a695a00307610d9e0
|
4
|
+
data.tar.gz: e0db1b2675515ce230dfd0b987100b79cb6aa34e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e8a95bcb3ad0c5481b8603524cda28a9678cb3a2ea29a535e17c2da95d24357b47bbdd017b19ed309fa2062de69e07ef7900cec13460f23fd34966b5a01d00f
|
7
|
+
data.tar.gz: c6075abd38b55ef0a88042fbb59d39c6cd21607863a8c8c003f66a29e5649a91f7a5510881555290d43a57cb72930d5b08da5ef7b070114186d91645b604b6f3
|
@@ -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.
|
7
|
+
spec.version = "0.0.4"
|
8
8
|
spec.authors = ["Toyokazu Akiyama"]
|
9
9
|
spec.email = ["toyokazu@gmail.com"]
|
10
10
|
spec.summary = %q{fluentd xml parser plugin}
|
@@ -27,21 +27,23 @@ module Fluent
|
|
27
27
|
# doc = REXML::Document.new(open("test.xml"))
|
28
28
|
# doc.elements['cap:alert/cap:info'].children
|
29
29
|
#
|
30
|
-
config_param :time_xpath, :string, :default =>
|
30
|
+
config_param :time_xpath, :string, :default => nil
|
31
|
+
config_param :time_key, :string, :default => nil
|
32
|
+
config_param :time_format, :string, :default => nil # time_format is configurable
|
31
33
|
config_param :attr_xpaths, :string, :default => '[]'
|
32
34
|
config_param :value_xpaths, :string, :default => '[]'
|
33
|
-
config_param :time_format, :string, :default => nil # time_format is configurable
|
34
35
|
# This method is called after config_params have read configuration parameters
|
35
36
|
def configure(conf)
|
36
37
|
super
|
37
38
|
|
38
39
|
@time_xpath = json_parse(conf['time_xpath'])
|
40
|
+
@time_key = conf['time_key']
|
41
|
+
@time_format = conf['time_format']
|
42
|
+
@time_parser = TimeParser.new(@time_format)
|
39
43
|
@attr_xpaths = json_parse(conf['attr_xpaths'])
|
40
44
|
@value_xpaths = json_parse(conf['value_xpaths'])
|
41
|
-
@time_format = conf['time_format']
|
42
45
|
# TimeParser class is already given. It takes a single argument as the time format
|
43
46
|
# to parse the time string with.
|
44
|
-
@time_parser = TimeParser.new(@time_format)
|
45
47
|
end
|
46
48
|
|
47
49
|
# This is the main method. The input "text" is the unit of data to be parsed.
|
@@ -52,8 +54,15 @@ module Fluent
|
|
52
54
|
doc = REXML::Document.new(text)
|
53
55
|
$log.debug doc
|
54
56
|
# parse time field
|
55
|
-
|
57
|
+
if @time_xpath.nil?
|
58
|
+
@time = Fluent::Engine.now
|
59
|
+
else
|
60
|
+
@time = @time_parser.parse(doc.elements[@time_xpath[0]].method(@time_xpath[1]).call)
|
61
|
+
end
|
56
62
|
record = {}
|
63
|
+
if !@time_key.nil?
|
64
|
+
record = {@time_key => format_time(@time)}
|
65
|
+
end
|
57
66
|
attrs = @attr_xpaths.map do |attr_xpath|
|
58
67
|
if attr_xpath[0].nil? # when null is specified
|
59
68
|
attr_xpath[1] # second parameter is used as the attribute name
|
@@ -81,6 +90,14 @@ module Fluent
|
|
81
90
|
end
|
82
91
|
end
|
83
92
|
|
93
|
+
def format_time(time)
|
94
|
+
if @time_format.nil?
|
95
|
+
Time.at(time).iso8601
|
96
|
+
else
|
97
|
+
Time.at(time).strftime(@time_format)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
84
101
|
def json_parse message
|
85
102
|
begin
|
86
103
|
y = Yajl::Parser.new
|
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.
|
4
|
+
version: 0.0.4
|
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-
|
11
|
+
date: 2015-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|