fluent-plugin-assert 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 88375974bc379d1fe6c9199a06102a34af41f03d
4
+ data.tar.gz: 050a9a6e2b09eebb5af54be7379a3678b6a09927
5
+ SHA512:
6
+ metadata.gz: 358899ed33bfee0ee68fb930ab2de4525ec1b2d802e424ee41933231e1ff72376cb7e22b2c975e53abbc04bb4b7026d84491484d064f38824acbfad784c6c59a
7
+ data.tar.gz: e5f31b3a770a7500659f72966fad7b479e4e799c4aea3b0c8f6a931c6c815e3246af411c3ad61b3645a2c2395b3ac79da2c1b22692fe3107d14fd9f14eba87f8
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1.1
5
+ - 2.0.0
6
+ - 1.9.3
@@ -0,0 +1,3 @@
1
+ # 0.0.1 (2014/06/22)
2
+
3
+ First version
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-assert.gemspec
4
+ gemspec
@@ -0,0 +1,203 @@
1
+ Copyright (c) 2014 Fukui ReTu
2
+
3
+ Apache License
4
+ Version 2.0, January 2004
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may act only
172
+ on Your own behalf and on Your sole responsibility, not on behalf
173
+ of any other Contributor, and only if You agree to indemnify,
174
+ defend, and hold each Contributor harmless for any liability
175
+ incurred by, or claims asserted against, such Contributor by reason
176
+ of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
179
+
180
+ APPENDIX: How to apply the Apache License to your work.
181
+
182
+ To apply the Apache License to your work, attach the following
183
+ boilerplate notice, with the fields enclosed by brackets "[]"
184
+ replaced with your own identifying information. (Don't include
185
+ the brackets!) The text should be enclosed in the appropriate
186
+ comment syntax for the file format. We also recommend that a
187
+ file or class name and description of purpose be included on the
188
+ same "printed page" as the copyright notice for easier
189
+ identification within third-party archives.
190
+
191
+ Copyright [2014] [Fukui ReTu]
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
@@ -0,0 +1,194 @@
1
+ # fluent-plugin-assert, a plugin for [Fluentd](http://fluentd.org)
2
+ [![Build Status](https://travis-ci.org/fukuiretu/fluent-plugin-assert.svg?branch=master)](https://travis-ci.org/fukuiretu/fluent-plugin-assert)
3
+
4
+
5
+ # Overview
6
+ Output Filter Plugin for assertion the data.By the result of the assertion, and rewrites the record and tag.
7
+
8
+ # Configuration
9
+
10
+ ## Ex1. length test
11
+ ```
12
+ <match assert.**>
13
+ assert_pass_remove_tag_prefix assert
14
+ assert_fail_tag_prefix fail
15
+ <test>
16
+ mode len
17
+ key txt
18
+ len 4 up
19
+ </test>
20
+ </match>
21
+ ```
22
+
23
+ ### In.
24
+ ```
25
+ assert.data: {"id":1,"txt":"hoge","created_at":"2014-01-01 00:00:00"}
26
+ assert.data: {"id":2,"txt":"foo","created_at":"2014-01-01 00:00:00"}
27
+ ```
28
+
29
+ ### Out.
30
+ ```
31
+ data: {"id":1,"txt":"hoge,"created_at":"2014-01-01 00:00:00"}
32
+ fail.assert.data: {"fail_1":{"message":"txt=\"foo\" is assert fail.","test":"<test>\n mode len\n key txt\n len 4 up\n</test>\n","origin_record":"{\"id\"=>1, \"txt\"=>\"foo\", \"created_at\"=>\"2014-01-01 00:00:00\"}"}}
33
+ ```
34
+
35
+ ## Ex2. type test
36
+ ```
37
+ <match assert.**>
38
+ assert_pass_remove_tag_prefix assert
39
+ assert_fail_tag_prefix fail
40
+ <test>
41
+ mode type
42
+ key txt
43
+ data_type integer
44
+ </test>
45
+ </match>
46
+ ```
47
+
48
+ ### In.
49
+ ```
50
+ assert.data: {"id":1,"txt":"12345","created_at":"2014-01-01 00:00:00"}
51
+ assert.data: {"id":2,"txt":"hoge","created_at":"2014-01-01 00:00:00"}
52
+ ```
53
+
54
+ ### Out.
55
+ ```
56
+ data: {"id":1,"txt":"12345","created_at":"2014-01-01 00:00:00"}
57
+ fail.assert.data: {"fail_1":{"message":"txt=\"hoge\" is assert fail.","test":"<test>\n mode type\n key txt\n data_type integer\n</test>\n","origin_record":"{\"id\"=>1, \"txt\"=>\"hoge\", \"created_at\"=>\"2014-01-01 00:00:00\"}"}}
58
+ ```
59
+
60
+ ## Ex3. type test
61
+ ```
62
+ <match assert.**>
63
+ assert_pass_remove_tag_prefix assert
64
+ assert_fail_tag_prefix fail
65
+ <test>
66
+ mode regexp
67
+ key txt
68
+ regexp_format \Ahoge
69
+ </test>
70
+ </match>
71
+ ```
72
+
73
+ ### In.
74
+ ```
75
+ assert.data: {"id":1,"txt":"hogefoobar","created_at":"2014-01-01 00:00:00"}
76
+ assert.data: {"id":2,"txt":"barhogefoo","created_at":"2014-01-01 00:00:00"}
77
+ ```
78
+
79
+ ### Out.
80
+ ```
81
+ data: {"id":1,"txt":"12345","created_at":"2014-01-01 00:00:00"}
82
+ fail.assert.data: {"fail_1":{"message":"txt=\"barhogefoo\" is assert fail.","test":"<test>\n mode regexp\n key txt\n regexp_format \\Ahoge\n</test>\n","origin_record":"{\"id\"=>1, \"txt\"=>\"barhogefoo\", \"created_at\"=>\"2014-01-01 00:00:00\"}"}}
83
+ ```
84
+
85
+ ## Ex4. mix test
86
+ ```
87
+ <match assert.**>
88
+ assert_pass_remove_tag_prefix assert
89
+ assert_fail_tag_prefix fail
90
+ <test>
91
+ mode type
92
+ key id
93
+ data_type integer
94
+ </test>
95
+ <test>
96
+ mode len,type
97
+ key txt
98
+ len 5 eq
99
+ data_type float
100
+ </test>
101
+ <test>
102
+ mode type
103
+ key created_at
104
+ data_type date
105
+ </test>
106
+ </match>
107
+ ```
108
+
109
+ ### In.
110
+ ```
111
+ assert.data: {"id":1,"txt":"123.4","created_at":"2014-01-01 00:00:00"}
112
+ assert.data: {"id":2,"txt":"1234","created_at":"2014-01-01 00:00:00"}
113
+ ```
114
+
115
+ ### Out.
116
+ ```
117
+ data: {"id":1,"txt":"123.4","created_at":"2014-01-01 00:00:00"}
118
+ fail.assert.data: {"fail_1":{"message":"txt=\"1234\" is assert fail.","test":"<test>\n mode len,type\n key txt\n len 5 eq\n data_type float\n</test>\n","origin_record":"{\"id\"=>1, \"txt\"=>\"1234\", \"created_at\"=>\"2014-01-01 00:00:00\"}"}}
119
+ ```
120
+
121
+ # Parameters
122
+ ### Global
123
+ * **assert_pass_remove_tag_prefix** (required)
124
+
125
+ Specifies the prefix of the tag to clear the test when passing through
126
+
127
+ * **assert_fail_tag_prefix** (required)
128
+
129
+ Specifies the prefix of the tag to be applied to the test failure
130
+
131
+ ### Test Directive
132
+ ##### Common Parameters
133
+ * **mode** (required)
134
+
135
+ Specifies the mode in which to test. It is possible to choose from the following modes. (Multiple selections are allowed, separated by commas)
136
+
137
+ 1. len : check the length of the value
138
+
139
+ 2. type : check the type of value
140
+
141
+ 3. regexp : check in a regular expression value
142
+
143
+ * **key** (required)
144
+
145
+ Specify the value of the key to be checked
146
+
147
+ * **fail_condition** (optional)
148
+
149
+ It specifies the (true or false) condition to be a fail. The default is false.
150
+
151
+ ##### Each Mode Parameters
152
+ ###### mode: len
153
+
154
+ * **len** (required)
155
+
156
+ Specify the up or down or eq numbers and separated by spaces.
157
+
158
+ Ex: len 5 up
159
+
160
+ ###### mode: type
161
+
162
+ * **data_type** (required)
163
+
164
+ The type is specified to be checked. The following types can be selected.
165
+
166
+ 1. integer
167
+
168
+ 2. float
169
+
170
+ 3. date
171
+
172
+ * **time_format** (optional)
173
+
174
+ It is possible that you specify if you have selected a date. The default is "% Y-% m-% d% H:% S: M%".
175
+
176
+ ###### mode: regexp
177
+
178
+ * **regexp_format** (required)
179
+
180
+ Specify the regular expression
181
+
182
+ ### other
183
+
184
+ And Logging of Fluentd Parameters...(>=v0.10.43)
185
+
186
+ * [Logging of Fluentd](http://docs.fluentd.org/articles/logging#per-plugin-log-fluentd-v01043-and-above)
187
+
188
+
189
+ # ChangeLog
190
+
191
+ See [CHANGELOG.md](https://github.com/fukuiretu/fluent-plugin-assert/blob/master/CHANGELOG.md) for details.
192
+
193
+ # Copyright
194
+ Copyright:: Copyright (c) 2014- Fukui ReTu License:: Apache License, Version 2.0
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+ Rake::TestTask.new(:test) do |test|
4
+ test.libs << 'lib' << 'test'
5
+ test.pattern = 'test/**/test_*.rb'
6
+ test.verbose = true
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "fluent-plugin-assert"
4
+ spec.version = "0.0.1"
5
+ spec.authors = ["Fukui ReTu"]
6
+ spec.email = ["s0232101@gmail.com"]
7
+ spec.description = %q{Output Filter plugin to assertion}
8
+ spec.summary = %q{Output Filter plugin to assertion}
9
+ spec.homepage = "https://github.com/fukuiretu/fluent-plugin-assert"
10
+ spec.license = "APL2.0"
11
+
12
+ spec.rubyforge_project = "fluent-plugin-assert"
13
+ spec.files = `git ls-files`.split($/)
14
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_development_dependency "bundler", "~> 1.3"
19
+ spec.add_development_dependency "rake"
20
+ spec.add_runtime_dependency "fluentd"
21
+ end
@@ -0,0 +1,156 @@
1
+ module Fluent
2
+ class AssertOutput < Fluent::Output
3
+ Fluent::Plugin.register_output("assert", self)
4
+
5
+ config_param :assert_pass_remove_tag_prefix, :string, :default => nil
6
+ config_param :assert_fail_tag_prefix, :string, :default => nil
7
+
8
+ # Define `log` method for v0.10.42 or earlier
9
+ unless method_defined?(:log)
10
+ define_method("log") { $log }
11
+ end
12
+
13
+ def initialize
14
+ super
15
+ end
16
+
17
+ def configure(conf)
18
+ super
19
+
20
+ if @assert_fail_tag_prefix
21
+ @assert_fail_tag_prefix_string = @assert_fail_tag_prefix + '.'
22
+ end
23
+
24
+ if @assert_pass_remove_tag_prefix
25
+ assert_pass_remove_tag_prefix_string = @assert_pass_remove_tag_prefix + '.'
26
+ @removed_length = assert_pass_remove_tag_prefix_string.length
27
+ end
28
+
29
+ @tests = conf.elements.select { |element|
30
+ element.name == "test"
31
+ }.each do |element|
32
+ element.keys.each do |k|
33
+ element[k]
34
+ end
35
+ end
36
+
37
+ if @tests.empty?
38
+ raise Fluent::ConfigError, "test elements is empty."
39
+ end
40
+ end
41
+
42
+ def emit(tag, es, chain)
43
+ es.each do |time, record|
44
+ chain.next
45
+
46
+ tag =
47
+ if assert!(record)
48
+ tag[@removed_length..-1]
49
+ else
50
+ @assert_fail_tag_prefix_string + tag
51
+ end
52
+
53
+ Fluent::Engine.emit(tag, time, record)
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def assert!(record)
60
+ origin_record = record.clone
61
+ cleared = false
62
+
63
+ @tests.each.with_index(1) do |element, i|
64
+ key = element["key"]
65
+ val = origin_record[key].to_s
66
+
67
+ fail_condition =
68
+ if element["fail_condition"].nil?
69
+ "false"
70
+ else
71
+ element["fail_condition"]
72
+ end
73
+
74
+ is_success = true
75
+ element["mode"].split(",").each do |mode|
76
+ valid_result = send("valid_#{mode}?", element, val)
77
+ is_success = is_success && valid_result
78
+ end
79
+
80
+ if is_success.to_s == fail_condition
81
+ log.debug "#{key} is assert fail. value=#{val}"
82
+
83
+ unless cleared
84
+ record.clear
85
+ cleared = true
86
+ end
87
+
88
+ record["fail_#{i}"] = {
89
+ "message" => "#{key}=\"#{val}\" is assert fail.",
90
+ "test" => element.to_s,
91
+ "origin_record" => origin_record.to_s
92
+ }
93
+ end
94
+ end
95
+
96
+ !cleared
97
+ end
98
+
99
+ def valid_len?(element, val)
100
+ len = element["len"].split(" ").first.to_i
101
+ comparison = element["len"].split(" ").last
102
+
103
+ case comparison
104
+ when "up"
105
+ val.length >= len
106
+ when "down"
107
+ val.length <= len
108
+ when "eq"
109
+ val.length == len
110
+ else
111
+ raise Fluent::ConfigError, "Unsupported Parameter for mode len. parameter = \"#{comparison}\""
112
+ end
113
+ end
114
+
115
+ def valid_type?(element, val)
116
+ data_type = element["data_type"]
117
+ case data_type
118
+ when "integer"
119
+ begin
120
+ Integer(val)
121
+ true
122
+ rescue ArgumentError
123
+ false
124
+ end
125
+ when "float"
126
+ begin
127
+ Float(val)
128
+ true
129
+ rescue ArgumentError
130
+ false
131
+ end
132
+ when "date"
133
+ time_format =
134
+ if element["time_format"].nil?
135
+ "%Y-%m-%d %H:%M:%S"
136
+ else
137
+ element["time_format"]
138
+ end
139
+
140
+ begin
141
+ d = DateTime.strptime(val, time_format)
142
+ true
143
+ rescue ArgumentError
144
+ false
145
+ end
146
+ else
147
+ raise Fluent::ConfigError, "Unsupported Parameter for mode type. parameter = #{data_type}"
148
+ end
149
+ end
150
+
151
+ def valid_regexp?(element, val)
152
+ regexp_format = element["regexp_format"]
153
+ !/#{regexp_format}/.match(val).nil?
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'fluent/test'
15
+ unless ENV.has_key?('VERBOSE')
16
+ nulllogger = Object.new
17
+ nulllogger.instance_eval {|obj|
18
+ def method_missing(method, *args)
19
+ # pass
20
+ end
21
+ }
22
+ $log = nulllogger
23
+ end
24
+
25
+ require 'fluent/plugin/out_assert'
26
+
27
+ class Test::Unit::TestCase
28
+ end
@@ -0,0 +1,316 @@
1
+ require 'helper'
2
+
3
+ class AssertOutputTest < Test::Unit::TestCase
4
+ def setup
5
+ Fluent::Test.setup
6
+ end
7
+
8
+ CONFIG = %[
9
+ assert_pass_remove_tag_prefix assert
10
+ assert_fail_tag_prefix pre.false
11
+ <test>
12
+ mode type
13
+ key hoge
14
+ len 5 up
15
+ data_type date
16
+ time_format %Y-%m-%d
17
+ </test>
18
+ ]
19
+
20
+ def create_driver(conf = CONFIG, tag='assert.test')
21
+ Fluent::Test::OutputTestDriver.new(Fluent::AssertOutput, tag).configure(conf)
22
+ end
23
+
24
+ def test_configure_1
25
+ d = create_driver
26
+ end
27
+
28
+ def test_emit_valid_len_1
29
+ config = %[
30
+ assert_pass_remove_tag_prefix assert
31
+ assert_fail_tag_prefix false
32
+ <test>
33
+ mode len
34
+ key hoge
35
+ len 5 up
36
+ </test>
37
+ ]
38
+
39
+ d = create_driver(config)
40
+ time = Time.parse("2012-01-02 13:14:15").to_i
41
+ d.run do
42
+ d.emit({'hoge' => "12345"}, time)
43
+ d.emit({'hoge' => "123456"}, time)
44
+ d.emit({'hoge' => "1234"}, time)
45
+ end
46
+
47
+ emits = d.emits
48
+
49
+ assert_equal("test", emits[0][0])
50
+ assert_equal(time, emits[0][1])
51
+ assert_equal("12345", emits[0][2]["hoge"])
52
+
53
+ assert_equal("test", emits[1][0])
54
+ assert_equal(time, emits[1][1])
55
+ assert_equal("123456", emits[1][2]["hoge"])
56
+
57
+ assert_equal("false.assert.test", emits[2][0])
58
+ assert_equal(time, emits[2][1])
59
+ assert_equal("hoge=\"1234\" is assert fail.", emits[2][2]["fail_1"]["message"])
60
+ end
61
+
62
+ def test_emit_valid_len_2
63
+ config = %[
64
+ assert_pass_remove_tag_prefix assert
65
+ assert_fail_tag_prefix false
66
+ <test>
67
+ mode len
68
+ key hoge
69
+ len 5 down
70
+ </test>
71
+ ]
72
+
73
+ d = create_driver(config)
74
+ time = Time.parse("2012-01-02 13:14:15").to_i
75
+ d.run do
76
+ d.emit({'hoge' => "12345"}, time)
77
+ d.emit({'hoge' => "123456"}, time)
78
+ d.emit({'hoge' => "1234"}, time)
79
+ end
80
+
81
+ emits = d.emits
82
+
83
+ assert_equal("test", emits[0][0])
84
+ assert_equal(time, emits[0][1])
85
+ assert_equal("12345", emits[0][2]["hoge"])
86
+
87
+ assert_equal("false.assert.test", emits[1][0])
88
+ assert_equal(time, emits[1][1])
89
+ assert_equal("hoge=\"123456\" is assert fail.", emits[1][2]["fail_1"]["message"])
90
+
91
+ assert_equal("test", emits[2][0])
92
+ assert_equal(time, emits[2][1])
93
+ assert_equal("1234", emits[2][2]["hoge"])
94
+ end
95
+
96
+ def test_emit_valid_len_3
97
+ config = %[
98
+ assert_pass_remove_tag_prefix assert
99
+ assert_fail_tag_prefix false
100
+ <test>
101
+ mode len
102
+ key hoge
103
+ len 5 eq
104
+ </test>
105
+ ]
106
+
107
+ d = create_driver(config)
108
+ time = Time.parse("2012-01-02 13:14:15").to_i
109
+ d.run do
110
+ d.emit({'hoge' => "12345"}, time)
111
+ d.emit({'hoge' => "123456"}, time)
112
+ d.emit({'hoge' => "1234"}, time)
113
+ end
114
+
115
+ emits = d.emits
116
+
117
+ assert_equal("test", emits[0][0])
118
+ assert_equal(time, emits[0][1])
119
+ assert_equal("12345", emits[0][2]["hoge"])
120
+
121
+ assert_equal("false.assert.test", emits[1][0])
122
+ assert_equal(time, emits[1][1])
123
+ assert_equal("hoge=\"123456\" is assert fail.", emits[1][2]["fail_1"]["message"])
124
+
125
+ assert_equal("false.assert.test", emits[2][0])
126
+ assert_equal(time, emits[2][1])
127
+ assert_equal("hoge=\"1234\" is assert fail.", emits[2][2]["fail_1"]["message"])
128
+ end
129
+
130
+ def test_emit_valid_type_1()
131
+ config = %[
132
+ assert_pass_remove_tag_prefix assert
133
+ assert_fail_tag_prefix false
134
+ <test>
135
+ mode type
136
+ key hoge
137
+ data_type integer
138
+ </test>
139
+ ]
140
+
141
+ d = create_driver(config)
142
+ time = Time.parse("2012-01-02 13:14:15").to_i
143
+ d.run do
144
+ d.emit({'hoge' => "12345"}, time)
145
+ d.emit({'hoge' => "123.45"}, time)
146
+ d.emit({'hoge' => "foo"}, time)
147
+ end
148
+
149
+ emits = d.emits
150
+
151
+ assert_equal("test", emits[0][0])
152
+ assert_equal(time, emits[0][1])
153
+ assert_equal("12345", emits[0][2]["hoge"])
154
+
155
+ assert_equal("false.assert.test", emits[1][0])
156
+ assert_equal(time, emits[1][1])
157
+ assert_equal("hoge=\"123.45\" is assert fail.", emits[1][2]["fail_1"]["message"])
158
+
159
+ assert_equal("false.assert.test", emits[2][0])
160
+ assert_equal(time, emits[2][1])
161
+ assert_equal("hoge=\"foo\" is assert fail.", emits[2][2]["fail_1"]["message"])
162
+ end
163
+
164
+ def test_emit_valid_type_2()
165
+ config = %[
166
+ assert_pass_remove_tag_prefix assert
167
+ assert_fail_tag_prefix false
168
+ <test>
169
+ mode type
170
+ key hoge
171
+ data_type float
172
+ </test>
173
+ ]
174
+
175
+ d = create_driver(config)
176
+ time = Time.parse("2012-01-02 13:14:15").to_i
177
+ d.run do
178
+ d.emit({'hoge' => "12345"}, time)
179
+ d.emit({'hoge' => "123.45"}, time)
180
+ d.emit({'hoge' => "foo"}, time)
181
+ end
182
+
183
+ emits = d.emits
184
+
185
+ assert_equal("test", emits[0][0])
186
+ assert_equal(time, emits[0][1])
187
+ assert_equal("12345", emits[0][2]["hoge"])
188
+
189
+ assert_equal("test", emits[1][0])
190
+ assert_equal(time, emits[1][1])
191
+ assert_equal("123.45", emits[1][2]["hoge"])
192
+
193
+ assert_equal("false.assert.test", emits[2][0])
194
+ assert_equal(time, emits[2][1])
195
+ assert_equal("hoge=\"foo\" is assert fail.", emits[2][2]["fail_1"]["message"])
196
+ end
197
+
198
+ def test_emit_valid_type_3()
199
+ config = %[
200
+ assert_pass_remove_tag_prefix assert
201
+ assert_fail_tag_prefix false
202
+ <test>
203
+ mode type
204
+ key hoge
205
+ data_type date
206
+ </test>
207
+ ]
208
+
209
+ d = create_driver(config)
210
+ time = Time.parse("2012-01-02 13:14:15").to_i
211
+ d.run do
212
+ d.emit({'hoge' => "2013-01-01 00:00:00"}, time)
213
+ d.emit({'hoge' => "2013/01/01"}, time)
214
+ end
215
+
216
+ emits = d.emits
217
+
218
+ assert_equal("test", emits[0][0])
219
+ assert_equal(time, emits[0][1])
220
+ assert_equal("2013-01-01 00:00:00", emits[0][2]["hoge"])
221
+
222
+ assert_equal("false.assert.test", emits[1][0])
223
+ assert_equal(time, emits[1][1])
224
+ assert_equal("hoge=\"2013/01/01\" is assert fail.", emits[1][2]["fail_1"]["message"])
225
+ end
226
+
227
+ def test_emit_valid_regexp_1()
228
+ config = %[
229
+ assert_pass_remove_tag_prefix assert
230
+ assert_fail_tag_prefix false
231
+ <test>
232
+ mode regexp
233
+ key hoge
234
+ regexp_format ^ABCDEFG
235
+ </test>
236
+ ]
237
+
238
+ d = create_driver(config)
239
+ time = Time.parse("2012-01-02 13:14:15").to_i
240
+ d.run do
241
+ d.emit({'hoge' => "ABCDEFGhogefoo"}, time)
242
+ d.emit({'hoge' => "hogeABCDEFGfoo"}, time)
243
+ end
244
+
245
+ emits = d.emits
246
+
247
+ assert_equal("test", emits[0][0])
248
+ assert_equal(time, emits[0][1])
249
+ assert_equal("ABCDEFGhogefoo", emits[0][2]["hoge"])
250
+
251
+ assert_equal("false.assert.test", emits[1][0])
252
+ assert_equal(time, emits[1][1])
253
+ assert_equal("hoge=\"hogeABCDEFGfoo\" is assert fail.", emits[1][2]["fail_1"]["message"])
254
+ end
255
+
256
+ def test_emit_mixing_1()
257
+ config = %[
258
+ assert_pass_remove_tag_prefix assert
259
+ assert_fail_tag_prefix false
260
+ <test>
261
+ mode len,type
262
+ key hoge
263
+ len 5 eq
264
+ data_type integer
265
+ </test>
266
+ ]
267
+
268
+ d = create_driver(config)
269
+ time = Time.parse("2012-01-02 13:14:15").to_i
270
+ d.run do
271
+ d.emit({'hoge' => "12345"}, time)
272
+ d.emit({'hoge' => "1234"}, time)
273
+ end
274
+
275
+ emits = d.emits
276
+
277
+ assert_equal("test", emits[0][0])
278
+ assert_equal(time, emits[0][1])
279
+ assert_equal("12345", emits[0][2]["hoge"])
280
+
281
+ assert_equal("test", emits[0][0])
282
+ assert_equal(time, emits[0][1])
283
+ assert_equal("hoge=\"1234\" is assert fail.", emits[1][2]["fail_1"]["message"])
284
+ end
285
+
286
+ def test_emit_mixing_2()
287
+ config = %[
288
+ assert_pass_remove_tag_prefix assert
289
+ assert_fail_tag_prefix false
290
+ <test>
291
+ mode len,type
292
+ key hoge
293
+ len 5 eq
294
+ data_type integer
295
+ fail_condition true
296
+ </test>
297
+ ]
298
+
299
+ d = create_driver(config)
300
+ time = Time.parse("2012-01-02 13:14:15").to_i
301
+ d.run do
302
+ d.emit({'hoge' => "12345"}, time)
303
+ d.emit({'hoge' => "1234"}, time)
304
+ end
305
+
306
+ emits = d.emits
307
+
308
+ assert_equal("false.assert.test", emits[0][0])
309
+ assert_equal(time, emits[0][1])
310
+ assert_equal("hoge=\"12345\" is assert fail.", emits[0][2]["fail_1"]["message"])
311
+
312
+ assert_equal("test", emits[1][0])
313
+ assert_equal(time, emits[1][1])
314
+ assert_equal("1234", emits[1][2]["hoge"])
315
+ end
316
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-assert
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Fukui ReTu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: fluentd
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Output Filter plugin to assertion
56
+ email:
57
+ - s0232101@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .travis.yml
64
+ - CHANGELOG.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - fluent-plugin-assert.gemspec
70
+ - lib/fluent/plugin/out_assert.rb
71
+ - test/helper.rb
72
+ - test/plugin/test_out_assert.rb
73
+ homepage: https://github.com/fukuiretu/fluent-plugin-assert
74
+ licenses:
75
+ - APL2.0
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project: fluent-plugin-assert
93
+ rubygems_version: 2.0.14
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Output Filter plugin to assertion
97
+ test_files:
98
+ - test/helper.rb
99
+ - test/plugin/test_out_assert.rb