fluent-plugin-tail-ex-asis 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 43d1b995a81dbe63377364b7d2aacaaa0713e12d
4
+ data.tar.gz: 3e087a92f430b752accf2ac86cff6d58480503a7
5
+ SHA512:
6
+ metadata.gz: da50da9d4b186f77326a24a2430baacd5844ec75b695772e11a424785f4a051b752182825f3360950e91a3c8182f6bda7bd74275d25d8cd8c8efc3ec4ead318a
7
+ data.tar.gz: 2ddb41be76f3611263fce027f7c6b4654306bb6e0112cb1a9b9c008d5f42217029082b13ff536a2d8e81c28042d4b9c3793b0977ac8d3aae422500f6052ec2bb
data/.gitignore ADDED
@@ -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
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-tail-ex-asis.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # fluent-plugin-tail-ex-asis, a plugin for [Fluentd](http://fluentd.org)
2
+
3
+ fluent-plugin-tail-ex-asis provides `tail_ex_asis` input plugin.
4
+ In addition to in_tail plugin features, this plugin support more feature for comfortable.
5
+
6
+ A main feature of the plugin is support path parameter expansions.
7
+ A path parameter can be configured using glob and/or date format (strftime).
8
+ Furthermore, the plugin append file path to the configured tag.
9
+
10
+ This repo was merged with tail-asis plugin to process the message as-is with no regex applied.
11
+
12
+ Note: In order to pass all tests, this plugin needs fluentd 0.10.26 or above.
13
+
14
+ ## Installation
15
+
16
+ Install it using gem:
17
+
18
+ $ gem install fluent-plugin-tail-ex-asis
19
+
20
+ ## Configuration
21
+
22
+ Below parameters are extended by this plugin:
23
+
24
+ - path: can be specified using glob and strftime format.
25
+ - tag: replace '*' with file path (using dot as a path separator).
26
+
27
+ And, below parameters are added by this plugin:
28
+
29
+ - expand_date: control whether expand strftime format or not.
30
+ - read_all: when new file is found, read from beginning of a file (default), instead of end of file (in_tail).
31
+ - refresh_interval: seconds for re-expand path to find new/old files.
32
+
33
+ Moreover, all configuration parameters support some placeholders which provided by [fluent-mixin-config-placeholders](https://github.com/tagomoris/fluent-mixin-config-placeholders).
34
+
35
+ Sample configuration:
36
+
37
+ <source>
38
+ type tail_ex
39
+ path /var/log/**.log,/var/log/by-date/%Y/messages.%m/%Y%m%d
40
+ tag tail_ex.*.${hostname}
41
+ pos_file /var/tmp/fluentd.pos
42
+ asis_key message
43
+ refresh_interval 1800
44
+ </source>
45
+
46
+ ## License
47
+
48
+ Apache License, Version 2.0
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.test_files = FileList['test/**/test_*.rb']
8
+ test.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Yoshihisa Tanaka"]
6
+ gem.email = ["yt.hisa@gmail.com"]
7
+ gem.description = %q{Extended tail input plugin}
8
+ gem.summary = %q{Extended tail input plugin}
9
+ gem.homepage = "https://github.com/bryanyork/fluent-plugin-tail-ex-asis"
10
+ gem.license = "Apache 2.0"
11
+
12
+ gem.files = `git ls-files`.split($\)
13
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.name = "fluent-plugin-tail-ex-asis"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = "0.1.1"
18
+
19
+ #requires = ['fluentd', 'fluent-mixin-config-placeholders']
20
+ #requires.each {|name| gem.add_runtime_dependency name}
21
+ gem.add_runtime_dependency 'fluentd', '~>0.10', '>=0.10.34'
22
+ gem.add_runtime_dependency 'fluent-mixin-config-placeholders', '~>0.2', '>=0.2.2'
23
+ requires = ['rake', 'flexmock']
24
+ requires.each {|name| gem.add_development_dependency name}
25
+ end
@@ -0,0 +1,161 @@
1
+ module Fluent
2
+ require 'fluent/plugin/in_tail'
3
+ require 'fluent/mixin/config_placeholders'
4
+
5
+ class TailExInput < TailInput
6
+ Plugin.register_input('tail_ex', self)
7
+
8
+ config_param :expand_date, :bool, :default => true
9
+ config_param :read_all, :bool, :default => true
10
+ config_param :refresh_interval, :integer, :default => 3600
11
+
12
+ include Fluent::Mixin::ConfigPlaceholders
13
+
14
+ def initialize
15
+ super
16
+ @ready = false
17
+ @parser = nil
18
+ end
19
+
20
+ def configure_parser(conf)
21
+ @parser = AsisParser.new
22
+ @parser.configure(conf)
23
+ end
24
+
25
+ def configure(conf)
26
+ super
27
+ if @tag.index('*')
28
+ @tag_prefix, @tag_suffix = @tag.split('*')
29
+ @tag_suffix ||= ''
30
+ else
31
+ @tag_prefix = nil
32
+ @tag_suffix = nil
33
+ end
34
+ @watchers = {}
35
+ @refresh_trigger = TailWatcher::TimerWatcher.new(@refresh_interval, true, &method(:refresh_watchers))
36
+ end
37
+
38
+ def expand_paths
39
+ date = Time.now
40
+ paths = []
41
+ for path in @paths
42
+ if @expand_date
43
+ path = date.strftime(path)
44
+ end
45
+ paths += Dir.glob(path)
46
+ end
47
+ paths
48
+ end
49
+
50
+ def refresh_watchers
51
+ paths = expand_paths
52
+ missing = @watchers.keys - paths
53
+ added = paths - @watchers.keys
54
+
55
+ stop_watch(missing) unless missing.empty?
56
+ start_watch(added) unless added.empty?
57
+ end
58
+
59
+ def start_watch(paths)
60
+ paths.each do |path|
61
+ if @pf
62
+ pe = @pf[path]
63
+ if @read_all && pe.read_inode == 0
64
+ inode = File::Stat.new(path).ino
65
+ pe.update(inode, 0)
66
+ end
67
+ else
68
+ pe = nil
69
+ end
70
+
71
+ watcher = TailExWatcher.new(path, @rotate_wait, pe, &method(:receive_lines))
72
+ watcher.attach(@loop)
73
+ @watchers[path] = watcher
74
+ end
75
+ end
76
+
77
+ def stop_watch(paths, immediate=false)
78
+ paths.each do |path|
79
+ watcher = @watchers.delete(path)
80
+ if watcher
81
+ watcher.close(immediate ? nil : @loop)
82
+ end
83
+ end
84
+ end
85
+
86
+ def receive_lines(lines, tag)
87
+ if @tag_prefix || @tag_suffix
88
+ @tag = @tag_prefix + tag + @tag_suffix
89
+ end
90
+ super(lines)
91
+ end
92
+
93
+ def start
94
+ paths, @paths = @paths, []
95
+ super
96
+ @thread.join
97
+ @paths = paths
98
+ refresh_watchers
99
+ @refresh_trigger.attach(@loop)
100
+ @ready = true
101
+ @thread = Thread.new(&method(:run))
102
+ end
103
+
104
+ def shutdown
105
+ @refresh_trigger.detach
106
+ stop_watch(@watchers.keys, true)
107
+ @loop.stop
108
+ @thread.join
109
+ @pf_file.close if @pf_file
110
+ end
111
+
112
+ def run
113
+ # don't run unless ready to avoid coolio error
114
+ if @ready
115
+ super
116
+ end
117
+ end
118
+
119
+ class TailExWatcher < TailWatcher
120
+ def initialize(path, rotate_wait, pe, &receive_lines)
121
+ @parent_receive_lines = receive_lines
122
+ super(path, rotate_wait, pe, &method(:_receive_lines))
123
+ @close_trigger = TimerWatcher.new(rotate_wait * 2, false, &method(:_close))
124
+ end
125
+
126
+ def _receive_lines(lines)
127
+ tag = @path.tr('/', '.').gsub(/\.+/, '.').gsub(/^\./, '')
128
+ @parent_receive_lines.call(lines, tag)
129
+ end
130
+
131
+ def close(loop=nil)
132
+ detach # detach first to avoid timer conflict
133
+ if loop
134
+ @close_trigger.attach(loop)
135
+ else
136
+ _close
137
+ end
138
+ end
139
+
140
+ def _close
141
+ @close_trigger.detach if @close_trigger.attached?
142
+ self.class.superclass.instance_method(:close).bind(self).call
143
+
144
+ @io_handler.on_notify
145
+ @io_handler.close
146
+ $log.info "stop following of #{@path}"
147
+ end
148
+ end
149
+ end
150
+ class AsisParser
151
+ include Configurable
152
+
153
+ config_param :asis_key, :string, :default => 'message'
154
+
155
+ def parse(text)
156
+ record = {}
157
+ record[@asis_key] = text
158
+ return Engine.now, record
159
+ end
160
+ end
161
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,31 @@
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 'stringio'
26
+ require 'flexmock'
27
+ require 'fluent/plugin/in_tail_ex'
28
+
29
+ class Test::Unit::TestCase
30
+ include FlexMock::TestCase
31
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,186 @@
1
+ require 'helper'
2
+
3
+ class TailExInputTest < Test::Unit::TestCase
4
+ def setup
5
+ Fluent::Test.setup
6
+ end
7
+
8
+ CONFIG = %[
9
+ tag tail_ex
10
+ path test/plugin/*/%Y/%m/%Y%m%d-%H%M%S.log,test/plugin/data/log/**/*.log
11
+ format /^(?<message>.*)$/
12
+ pos_file test-pos-file
13
+ refresh_interval 30
14
+ ]
15
+ PATHS = [
16
+ 'test/plugin/data/2010/01/20100102-030405.log',
17
+ 'test/plugin/data/log/foo/bar.log',
18
+ 'test/plugin/data/log/test.log'
19
+ ]
20
+
21
+ def create_driver(conf = CONFIG)
22
+ Fluent::Test::InputTestDriver.new(Fluent::TailExInput).configure(conf)
23
+ end
24
+
25
+ def test_configure
26
+ assert_nothing_raised { create_driver }
27
+ end
28
+
29
+ def test_posfile_creation
30
+ flexstub(Thread) do |threadclass|
31
+ threadclass.should_receive(:new).once.and_return do
32
+ flexmock('Thread') {|t| t.should_receive(:join).once }
33
+ end
34
+ threadclass.should_receive(:new).once
35
+
36
+ plugin = create_driver.instance
37
+ plugin.start
38
+ pf = nil
39
+ plugin.instance_eval do
40
+ pf = @pf
41
+ end
42
+ assert_instance_of Fluent::TailInput::PositionFile, pf
43
+ end
44
+ end
45
+
46
+ def test_expand_paths
47
+ plugin = create_driver.instance
48
+ flexstub(Time) do |timeclass|
49
+ timeclass.should_receive(:now).with_no_args.and_return(
50
+ Time.new(2010, 1, 2, 3, 4, 5))
51
+ assert_equal PATHS, plugin.expand_paths.sort
52
+ end
53
+ end
54
+
55
+ def test_start_watch_without_pos_file
56
+ config = %[
57
+ tag tail_ex
58
+ path test/plugin/*/%Y/%m/%Y%m%d-%H%M%S.log,test/plugin/data/log/**/*.log
59
+ format /^(?<message>.*)$/
60
+ refresh_interval 30
61
+ ]
62
+ plugin = create_driver(config).instance
63
+ flexstub(Fluent::TailExInput::TailExWatcher) do |watcherclass|
64
+ PATHS.each do |path|
65
+ watcherclass.should_receive(:new).with(path, 5, nil, any).once.and_return do
66
+ flexmock('TailExWatcher') {|watcher| watcher.should_receive(:attach).once}
67
+ end
68
+ end
69
+ plugin.start_watch(PATHS)
70
+ end
71
+ end
72
+
73
+ def test_refresh_watchers
74
+ plugin = create_driver.instance
75
+ sio = StringIO.new
76
+ plugin.instance_eval do
77
+ @pf = Fluent::TailInput::PositionFile.parse(sio)
78
+ end
79
+
80
+ flexstub(Time) do |timeclass|
81
+ timeclass.should_receive(:now).with_no_args.and_return(
82
+ Time.new(2010, 1, 2, 3, 4, 5), Time.new(2010, 1, 2, 3, 4, 6),
83
+ Time.new(2010, 1, 2, 3, 4, 7))
84
+
85
+ flexstub(Fluent::TailExInput::TailExWatcher) do |watcherclass|
86
+ PATHS.each do |path|
87
+ watcherclass.should_receive(:new).with(path, 5, Fluent::TailInput::FilePositionEntry, any).once.and_return do
88
+ flexmock('TailExWatcher') {|watcher| watcher.should_receive(:attach).once}
89
+ end
90
+ end
91
+ plugin.refresh_watchers
92
+ end
93
+
94
+ plugin.instance_eval do
95
+ @watchers['test/plugin/data/2010/01/20100102-030405.log'].should_receive(:close).once
96
+ end
97
+
98
+ flexstub(Fluent::TailExInput::TailExWatcher) do |watcherclass|
99
+ watcherclass.should_receive(:new).with('test/plugin/data/2010/01/20100102-030406.log', 5, Fluent::TailInput::FilePositionEntry, any).once.and_return do
100
+ flexmock('TailExWatcher') do |watcher|
101
+ watcher.should_receive(:attach).once
102
+ watcher.should_receive(:close).once
103
+ end
104
+ end
105
+ plugin.refresh_watchers
106
+ end
107
+
108
+ flexstub(Fluent::TailExInput::TailExWatcher) do |watcherclass|
109
+ watcherclass.should_receive(:new).never
110
+ plugin.refresh_watchers
111
+ end
112
+ end
113
+ end
114
+
115
+ def test_receive_lines
116
+ plugin = create_driver.instance
117
+ flexstub(Fluent::Engine) do |engineclass|
118
+ engineclass.should_receive(:emit_stream).with('tail_ex', any).once
119
+ plugin.receive_lines(['foo', 'bar'], 'foo.bar.log')
120
+ end
121
+
122
+ config = %[
123
+ tag pre.*
124
+ path test/plugin/*/%Y/%m/%Y%m%d-%H%M%S.log,test/plugin/data/log/**/*.log
125
+ format /^(?<message>.*)$/
126
+ ]
127
+ plugin = create_driver(config).instance
128
+ flexstub(Fluent::Engine) do |engineclass|
129
+ engineclass.should_receive(:emit_stream).with('pre.foo.bar.log', any).once
130
+ plugin.receive_lines(['foo', 'bar'], 'foo.bar.log')
131
+ end
132
+
133
+ config = %[
134
+ tag *.post
135
+ path test/plugin/*/%Y/%m/%Y%m%d-%H%M%S.log,test/plugin/data/log/**/*.log
136
+ format /^(?<message>.*)$/
137
+ ]
138
+ plugin = create_driver(config).instance
139
+ flexstub(Fluent::Engine) do |engineclass|
140
+ engineclass.should_receive(:emit_stream).with('foo.bar.log.post', any).once
141
+ plugin.receive_lines(['foo', 'bar'], 'foo.bar.log')
142
+ end
143
+
144
+ config = %[
145
+ tag pre.*.post
146
+ path test/plugin/*/%Y/%m/%Y%m%d-%H%M%S.log,test/plugin/data/log/**/*.log
147
+ format /^(?<message>.*)$/
148
+ ]
149
+ plugin = create_driver(config).instance
150
+ flexstub(Fluent::Engine) do |engineclass|
151
+ engineclass.should_receive(:emit_stream).with('pre.foo.bar.log.post', any).once
152
+ plugin.receive_lines(['foo', 'bar'], 'foo.bar.log')
153
+ end
154
+
155
+ config = %[
156
+ tag pre.*.post*ignore
157
+ path test/plugin/*/%Y/%m/%Y%m%d-%H%M%S.log,test/plugin/data/log/**/*.log
158
+ format /^(?<message>.*)$/
159
+ ]
160
+ plugin = create_driver(config).instance
161
+ flexstub(Fluent::Engine) do |engineclass|
162
+ engineclass.should_receive(:emit_stream).with('pre.foo.bar.log.post', any).once
163
+ plugin.receive_lines(['foo', 'bar'], 'foo.bar.log')
164
+ end
165
+ end
166
+ end
167
+
168
+
169
+ class TailExWatcherTest < Test::Unit::TestCase
170
+ def setup
171
+ @tag = nil
172
+ @lines = nil
173
+ @watcher = Fluent::TailExInput::TailExWatcher.new('/var/tmp//foo.log', 5, nil, &method(:callback))
174
+ end
175
+
176
+ def callback(lines, tag)
177
+ @tag = tag
178
+ @lines = lines
179
+ end
180
+
181
+ def test_receive_lines
182
+ @watcher.instance_eval { @receive_lines.call(['l1', 'l2']) }
183
+ assert_equal 'var.tmp.foo.log', @tag
184
+ assert_equal ['l1', 'l2'], @lines
185
+ end
186
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-tail-ex-asis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Yoshihisa Tanaka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.10'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.10.34
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.10'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.10.34
33
+ - !ruby/object:Gem::Dependency
34
+ name: fluent-mixin-config-placeholders
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.2'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.2.2
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.2'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.2.2
53
+ - !ruby/object:Gem::Dependency
54
+ name: rake
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: flexmock
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ description: Extended tail input plugin
82
+ email:
83
+ - yt.hisa@gmail.com
84
+ executables: []
85
+ extensions: []
86
+ extra_rdoc_files: []
87
+ files:
88
+ - ".gitignore"
89
+ - ".travis.yml"
90
+ - Gemfile
91
+ - LICENSE
92
+ - README.md
93
+ - Rakefile
94
+ - fluent-plugin-tail-ex-asis.gemspec
95
+ - lib/fluent/plugin/in_tail_ex_asis.rb
96
+ - test/helper.rb
97
+ - test/plugin/data/2010/01/20100102-030405.log
98
+ - test/plugin/data/2010/01/20100102-030406.log
99
+ - test/plugin/data/2010/01/20100102.log
100
+ - test/plugin/data/log/bar
101
+ - test/plugin/data/log/foo/bar.log
102
+ - test/plugin/data/log/test.log
103
+ - test/plugin/test_in_tail_ex_asis.rb
104
+ homepage: https://github.com/bryanyork/fluent-plugin-tail-ex-asis
105
+ licenses:
106
+ - Apache 2.0
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.2
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Extended tail input plugin
128
+ test_files:
129
+ - test/helper.rb
130
+ - test/plugin/data/2010/01/20100102-030405.log
131
+ - test/plugin/data/2010/01/20100102-030406.log
132
+ - test/plugin/data/2010/01/20100102.log
133
+ - test/plugin/data/log/bar
134
+ - test/plugin/data/log/foo/bar.log
135
+ - test/plugin/data/log/test.log
136
+ - test/plugin/test_in_tail_ex_asis.rb