fluent-plugin-parse_multiple_value_query 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4d4b4c98f4d249b8fdf295c8d897bc5339aab35
4
- data.tar.gz: 84a8d2bf6280767fd28b586f34ed98ce09f5a9e6
3
+ metadata.gz: 7c3d4fd446ddd2cb20f3902970b319a9a674278c
4
+ data.tar.gz: 4f834383bceb6245c9af89bf40cd1448860a525c
5
5
  SHA512:
6
- metadata.gz: d9222b4f174ea83ba4d2e30a8a2b2453738c9f91ef97d0bdf290b570d43a7a7cda8ccced233fffa62a5f6c734d7080c91f17b26d472958b5ce42c2df17e6413a
7
- data.tar.gz: c81f4e976a053c34eccabfbea1f270651886e5757876a6546dc91290166525a07489c4cafea57f87bd83da67487d83d88d13d5bee5ab6e9dcfb61bfd00956d08
6
+ metadata.gz: 7c46a9ee2b53dca420db708b819b89e10d4cd858685d2a9fbf419fec75dfd6d358dea33a13d45fcc8b609ff1563f57c1c88a4be0de45b7c6795681dec875cb13
7
+ data.tar.gz: c6ac4776e8d0783da0e7d212c861c87610ac5b69f30af9f95ad906ff1afb02c8aacae0a10e3c67717951a10a15deb1ba3e6854c0227a3685ba5163c35a1ed436
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.0.4 (2015/03/31)
2
+ without_host option
3
+
4
+ ## 0.0.3 (2015/03/31)
5
+ sub_key option
6
+
1
7
  ## 0.0.2 (2015/02/07)
2
8
  Fix plugin type
3
9
 
data/README.md CHANGED
@@ -123,6 +123,53 @@ output
123
123
  "key2": ["value4", "value5"]
124
124
  }
125
125
  ```
126
+
127
+ If you want create sub key with parsed data.
128
+ ```
129
+ <match foo.**>
130
+ type parse_multiple_value_query
131
+ key url
132
+ sub_key url_parsed
133
+ </match>
134
+
135
+ input
136
+ "test" {
137
+ "url": "http://example.com?key1[]=value1&key1[]=value2&key1[]=value3&key2[]=value4&key2[]=value5&key3[]="
138
+ }
139
+
140
+ output
141
+ "parsed.test" {
142
+ "url": "http://example.com?key1[]=value1&key1[]=value2&key1[]=value3&key2[]=value4&key2[]=value5&key3[]=",
143
+ "url_parsed": {
144
+ "key1": ["value1", "value2", "value3"],
145
+ "key2": ["value4", "value5"],
146
+ "key3": [""]
147
+ }
148
+ }
149
+ ```
150
+
151
+ If you want to parse url withiut host.
152
+ ```
153
+ <match foo.**>
154
+ type parse_multiple_value_query
155
+ key url
156
+ without_host true
157
+ </match>
158
+
159
+ input
160
+ "test" {
161
+ "url": "/custom/path?key1[]=value1&key1[]=value2&key1[]=value3&key2[]=value4&key2[]=value5&key3[]="
162
+ }
163
+
164
+ output
165
+ "parsed.test" {
166
+ "url": "/custom/path?key1[]=value1&key1[]=value2&key1[]=value3&key2[]=value4&key2[]=value5&key3[]=",
167
+ "key1": ["value1", "value2", "value3"],
168
+ "key2": ["value4", "value5"],
169
+ "key3": [""]
170
+ }
171
+ ```
172
+
126
173
  ## Option Parameters
127
174
 
128
175
  ### key :String
@@ -142,6 +189,14 @@ You want to remove parsed value that has [] or [""] or [nil].
142
189
  You must be this option setting true.
143
190
  Default value is false.
144
191
 
192
+ ### sub_key :String
193
+ You want to put parsed data into separate key.
194
+ Default value is false.
195
+
196
+ ### without_host :Bool
197
+ You want to parse url without host.
198
+ Default value is false.
199
+
145
200
  ## Relative
146
201
  - [fluent-plugin-extract_query_params](https://github.com/kentaro/fluent-plugin-extract_query_params)
147
202
 
@@ -6,6 +6,8 @@ module Fluent
6
6
  config_param :tag_prefix, :string, :default => 'parsed.'
7
7
  config_param :only_query_string, :bool, :default => false
8
8
  config_param :remove_empty_array, :bool, :default => false
9
+ config_param :sub_key, :string, :default => nil
10
+ config_param :without_host, :bool, :default => false
9
11
 
10
12
  def initialize
11
13
  super
@@ -49,7 +51,9 @@ module Fluent
49
51
  record = parse_query_string(record,record[key])
50
52
  return record
51
53
  else
52
- query = URI.parse(record[key]).query
54
+ url = without_host ? "http://example.com#{record[key]}" : record[key]
55
+
56
+ query = URI.parse(url).query
53
57
  record = parse_query_string(record, query)
54
58
  return record
55
59
  end
@@ -58,19 +62,21 @@ module Fluent
58
62
 
59
63
  def parse_query_string(record, query_string)
60
64
  begin
65
+ target = sub_key ? (record[sub_key] ||= {}) : record
66
+
61
67
  parsed_query = Rack::Utils.parse_nested_query(query_string)
62
68
  parsed_query.each do |key, value|
63
69
  if value == ""
64
- record[key] = ""
70
+ target[key] = ""
65
71
  else
66
72
  if value.class == Array && remove_empty_array
67
73
  if value.empty? || value == [""] || value == [nil]
68
- record.delete(key)
74
+ target.delete(key)
69
75
  else
70
- record[key] = value
76
+ target[key] = value
71
77
  end
72
78
  else
73
- record[key] = value
79
+ target[key] = value
74
80
  end
75
81
  end
76
82
  end
@@ -1,5 +1,5 @@
1
1
  module Fluent
2
2
  module ParseMultipleValueQuery
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -9,6 +9,7 @@ class ParseMultipleValueQueryOutTest < Test::Unit::TestCase
9
9
  URL_INCLUDE_JP = 'http://example.com:80/?foo=bar&baz=qux&%E3%81%BE%E3%81%84%E3%81%91%E3%82%8B%5B%5D=%E3%82%AD%E3%82%B9%E3%82%AF&%E3%81%BE%E3%81%84%E3%81%91%E3%82%8B%5B%5D=%E3%82%B7%E3%82%A7%E3%83%B3%E3%82%AB%E3%83%BC&%E3%81%BE%E3%81%84%E3%81%91%E3%82%8B%5B%5D=%E3%82%B8%E3%83%A3%E3%82%AF%E3%82%BD%E3%83%B3'
10
10
  ONLY_QUERY_STRING_TEST = 'foo=bar&baz=qux&multiple[]=1&multiple[]=2&multiple[]=3&%E3%81%BE%E3%81%84%E3%81%91%E3%82%8B%5B%5D=%E3%82%AD%E3%82%B9%E3%82%AF&%E3%81%BE%E3%81%84%E3%81%91%E3%82%8B%5B%5D=%E3%82%B7%E3%82%A7%E3%83%B3%E3%82%AB%E3%83%BC&%E3%81%BE%E3%81%84%E3%81%91%E3%82%8B%5B%5D=%E3%82%B8%E3%83%A3%E3%82%AF%E3%82%BD%E3%83%B3'
11
11
  REMOVE_EMPTY_KEY = 'http://example.com:80/?foo=bar&baz=qux&multiple[]=&%E3%81%BE%E3%81%84%E3%81%91%E3%82%8B%5B%5D=%E3%82%AD%E3%82%B9%E3%82%AF&%E3%81%BE%E3%81%84%E3%81%91%E3%82%8B%5B%5D=%E3%82%B7%E3%82%A7%E3%83%B3%E3%82%AB%E3%83%BC&%E3%81%BE%E3%81%84%E3%81%91%E3%82%8B%5B%5D=%E3%82%B8%E3%83%A3%E3%82%AF%E3%82%BD%E3%83%B3&multiple2[]'
12
+ WITHOUT_HOST = '/test/url?foo=bar&baz=qux&multiple[]=1&multiple[]=2&multiple[]=3&multiple2[]='
12
13
 
13
14
  def setup
14
15
  Fluent::Test.setup
@@ -149,4 +150,46 @@ class ParseMultipleValueQueryOutTest < Test::Unit::TestCase
149
150
  end
150
151
  end
151
152
 
153
+ def test_sub_key
154
+ conf = %[
155
+ key url
156
+ sub_key url_parsed
157
+ ]
158
+
159
+ record = {
160
+ 'url' => URL,
161
+ }
162
+
163
+ emits = emit(conf, record)
164
+
165
+ emits.each_with_index do |(tag, time, record), i|
166
+ assert_equal URL, record['url']
167
+ assert_equal 'bar', record['url_parsed']['foo']
168
+ assert_equal 'qux', record['url_parsed']['baz']
169
+ assert_equal ["1", "2", "3"], record['url_parsed']['multiple']
170
+ end
171
+ end
172
+
173
+ def test_without_host
174
+ conf = %[
175
+ key url
176
+ without_host true
177
+ ]
178
+
179
+ record = {
180
+ 'url' => WITHOUT_HOST,
181
+ }
182
+
183
+ emits = emit(conf, record)
184
+
185
+ emits.each_with_index do |(tag, time, record), i|
186
+ assert_equal 'parsed.test', tag
187
+ assert_equal 'bar', record['foo']
188
+ assert_equal 'qux', record['baz']
189
+ assert_equal ["1", "2", "3"], record['multiple']
190
+ assert_equal [""], record['multiple2']
191
+ end
192
+
193
+ end
194
+
152
195
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-parse_multiple_value_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hirokazu Hata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-09 00:00:00.000000000 Z
11
+ date: 2016-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -188,11 +188,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  version: '0'
189
189
  requirements: []
190
190
  rubyforge_project:
191
- rubygems_version: 2.2.2
191
+ rubygems_version: 2.5.1
192
192
  signing_key:
193
193
  specification_version: 4
194
194
  summary: Fluentd plugin to parse query string with rails format
195
195
  test_files:
196
196
  - test/helper.rb
197
197
  - test/plugin/test_out_parse_multiple_value_query.rb
198
- has_rdoc: