fluent-plugin-tail-ex 0.1.0

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.
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.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
2
+
3
+ [![Build Status](https://secure.travis-ci.org/yosisa/fluent-plugin-tail-ex.png)](http://travis-ci.org/yosisa/fluent-plugin-tail-ex)
4
+
5
+ fluent-plugin-tail-ex provides `tail_ex` input plugin.
6
+ In addition to in_tail plugin features, this plugin support more feature for comfortable.
7
+
8
+ A main feature of the plugin is support path parameter expansions.
9
+ A path parameter can be configured using glob and/or date format (strftime).
10
+ Furthermore, the plugin append file path to the configured tag.
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
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
+ format /^(?<message>.*)$/
42
+ pos_file /var/tmp/fluentd.pos
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,22 @@
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/yosisa/fluent-plugin-tail-ex"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "fluent-plugin-tail-ex"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = "0.1.0"
17
+
18
+ requires = ['fluentd', 'fluent-mixin-config-placeholders']
19
+ requires.each {|name| gem.add_runtime_dependency name}
20
+ requires += ['rake', 'flexmock']
21
+ requires.each {|name| gem.add_development_dependency name}
22
+ end
@@ -0,0 +1,132 @@
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
+ end
17
+
18
+ def configure(conf)
19
+ super
20
+ if @tag.index('*')
21
+ @tag_prefix, @tag_suffix = @tag.split('*')
22
+ @tag_suffix ||= ''
23
+ else
24
+ @tag_prefix = nil
25
+ @tag_suffix = nil
26
+ end
27
+ @watchers = {}
28
+ @refresh_trigger = TailWatcher::TimerWatcher.new(@refresh_interval, true, &method(:refresh_watchers))
29
+ end
30
+
31
+ def expand_paths
32
+ date = Time.now
33
+ paths = []
34
+ for path in @paths
35
+ if @expand_date
36
+ path = date.strftime(path)
37
+ end
38
+ paths += Dir.glob(path)
39
+ end
40
+ paths
41
+ end
42
+
43
+ def refresh_watchers
44
+ paths = expand_paths
45
+ missing = @watchers.keys - paths
46
+ added = paths - @watchers.keys
47
+
48
+ stop_watch(missing) unless missing.empty?
49
+ start_watch(added) unless added.empty?
50
+ end
51
+
52
+ def start_watch(paths)
53
+ paths.each do |path|
54
+ if @pf
55
+ pe = @pf[path]
56
+ if @read_all && pe.read_inode == 0
57
+ inode = File::Stat.new(path).ino
58
+ pe.update(inode, 0)
59
+ end
60
+ else
61
+ pe = nil
62
+ end
63
+
64
+ watcher = TailExWatcher.new(path, @rotate_wait, pe, &method(:receive_lines))
65
+ watcher.attach(@loop)
66
+ @watchers[path] = watcher
67
+ end
68
+ end
69
+
70
+ def stop_watch(paths, immediate=false)
71
+ paths.each do |path|
72
+ watcher = @watchers.delete(path)
73
+ if watcher
74
+ watcher.close(immediate ? nil : @loop)
75
+ end
76
+ end
77
+ end
78
+
79
+ def receive_lines(lines, tag)
80
+ if @tag_prefix || @tag_suffix
81
+ @tag = @tag_prefix + tag + @tag_suffix
82
+ end
83
+ super(lines)
84
+ end
85
+
86
+ def start
87
+ @loop = Coolio::Loop.new
88
+ refresh_watchers
89
+ @refresh_trigger.attach(@loop)
90
+ @thread = Thread.new(&method(:run))
91
+ end
92
+
93
+ def shutdown
94
+ @refresh_trigger.detach
95
+ stop_watch(@watchers.keys, true)
96
+ @loop.stop
97
+ @thread.join
98
+ @pf_file.close if @pf_file
99
+ end
100
+
101
+ class TailExWatcher < TailWatcher
102
+ def initialize(path, rotate_wait, pe, &receive_lines)
103
+ @parent_receive_lines = receive_lines
104
+ super(path, rotate_wait, pe, &method(:_receive_lines))
105
+ @close_trigger = TimerWatcher.new(rotate_wait * 2, false, &method(:_close))
106
+ end
107
+
108
+ def _receive_lines(lines)
109
+ tag = @path.tr('/', '.').gsub(/\.+/, '.').gsub(/^\./, '')
110
+ @parent_receive_lines.call(lines, tag)
111
+ end
112
+
113
+ def close(loop=nil)
114
+ detach # detach first to avoid timer conflict
115
+ if loop
116
+ @close_trigger.attach(loop)
117
+ else
118
+ _close
119
+ end
120
+ end
121
+
122
+ def _close
123
+ @close_trigger.detach if @close_trigger.attached?
124
+ self.class.superclass.instance_method(:close).bind(self).call
125
+
126
+ @io_handler.on_notify
127
+ @io_handler.close
128
+ $log.info "stop following of #{@path}"
129
+ end
130
+ end
131
+ end
132
+ 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,169 @@
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 /var/tmp/fluentd.pos
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_expand_paths
30
+ plugin = create_driver.instance
31
+ flexstub(Time) do |timeclass|
32
+ timeclass.should_receive(:now).with_no_args.and_return(
33
+ Time.new(2010, 1, 2, 3, 4, 5))
34
+ assert_equal PATHS, plugin.expand_paths.sort
35
+ end
36
+ end
37
+
38
+ def test_start_watch_without_pos_file
39
+ config = %[
40
+ tag tail_ex
41
+ path test/plugin/*/%Y/%m/%Y%m%d-%H%M%S.log,test/plugin/data/log/**/*.log
42
+ format /^(?<message>.*)$/
43
+ refresh_interval 30
44
+ ]
45
+ plugin = create_driver(config).instance
46
+ flexstub(Fluent::TailExInput::TailExWatcher) do |watcherclass|
47
+ PATHS.each do |path|
48
+ watcherclass.should_receive(:new).with(path, 5, nil, any).once.and_return do
49
+ flexmock('TailExWatcher') {|watcher| watcher.should_receive(:attach).once}
50
+ end
51
+ end
52
+ plugin.start_watch(PATHS)
53
+ end
54
+ end
55
+
56
+ def test_refresh_watchers
57
+ plugin = create_driver.instance
58
+ sio = StringIO.new
59
+ plugin.instance_eval do
60
+ @pf = Fluent::TailInput::PositionFile.parse(sio)
61
+ end
62
+
63
+ flexstub(Time) do |timeclass|
64
+ timeclass.should_receive(:now).with_no_args.and_return(
65
+ Time.new(2010, 1, 2, 3, 4, 5), Time.new(2010, 1, 2, 3, 4, 6),
66
+ Time.new(2010, 1, 2, 3, 4, 7))
67
+
68
+ flexstub(Fluent::TailExInput::TailExWatcher) do |watcherclass|
69
+ PATHS.each do |path|
70
+ watcherclass.should_receive(:new).with(path, 5, Fluent::TailInput::FilePositionEntry, any).once.and_return do
71
+ flexmock('TailExWatcher') {|watcher| watcher.should_receive(:attach).once}
72
+ end
73
+ end
74
+ plugin.refresh_watchers
75
+ end
76
+
77
+ plugin.instance_eval do
78
+ @watchers['test/plugin/data/2010/01/20100102-030405.log'].should_receive(:close).once
79
+ end
80
+
81
+ flexstub(Fluent::TailExInput::TailExWatcher) do |watcherclass|
82
+ watcherclass.should_receive(:new).with('test/plugin/data/2010/01/20100102-030406.log', 5, Fluent::TailInput::FilePositionEntry, any).once.and_return do
83
+ flexmock('TailExWatcher') do |watcher|
84
+ watcher.should_receive(:attach).once
85
+ watcher.should_receive(:close).once
86
+ end
87
+ end
88
+ plugin.refresh_watchers
89
+ end
90
+
91
+ flexstub(Fluent::TailExInput::TailExWatcher) do |watcherclass|
92
+ watcherclass.should_receive(:new).never
93
+ plugin.refresh_watchers
94
+ end
95
+ end
96
+ end
97
+
98
+ def test_receive_lines
99
+ plugin = create_driver.instance
100
+ flexstub(Fluent::Engine) do |engineclass|
101
+ engineclass.should_receive(:emit_stream).with('tail_ex', any).once
102
+ plugin.receive_lines(['foo', 'bar'], 'foo.bar.log')
103
+ end
104
+
105
+ config = %[
106
+ tag pre.*
107
+ path test/plugin/*/%Y/%m/%Y%m%d-%H%M%S.log,test/plugin/data/log/**/*.log
108
+ format /^(?<message>.*)$/
109
+ ]
110
+ plugin = create_driver(config).instance
111
+ flexstub(Fluent::Engine) do |engineclass|
112
+ engineclass.should_receive(:emit_stream).with('pre.foo.bar.log', any).once
113
+ plugin.receive_lines(['foo', 'bar'], 'foo.bar.log')
114
+ end
115
+
116
+ config = %[
117
+ tag *.post
118
+ path test/plugin/*/%Y/%m/%Y%m%d-%H%M%S.log,test/plugin/data/log/**/*.log
119
+ format /^(?<message>.*)$/
120
+ ]
121
+ plugin = create_driver(config).instance
122
+ flexstub(Fluent::Engine) do |engineclass|
123
+ engineclass.should_receive(:emit_stream).with('foo.bar.log.post', any).once
124
+ plugin.receive_lines(['foo', 'bar'], 'foo.bar.log')
125
+ end
126
+
127
+ config = %[
128
+ tag pre.*.post
129
+ path test/plugin/*/%Y/%m/%Y%m%d-%H%M%S.log,test/plugin/data/log/**/*.log
130
+ format /^(?<message>.*)$/
131
+ ]
132
+ plugin = create_driver(config).instance
133
+ flexstub(Fluent::Engine) do |engineclass|
134
+ engineclass.should_receive(:emit_stream).with('pre.foo.bar.log.post', any).once
135
+ plugin.receive_lines(['foo', 'bar'], 'foo.bar.log')
136
+ end
137
+
138
+ config = %[
139
+ tag pre.*.post*ignore
140
+ path test/plugin/*/%Y/%m/%Y%m%d-%H%M%S.log,test/plugin/data/log/**/*.log
141
+ format /^(?<message>.*)$/
142
+ ]
143
+ plugin = create_driver(config).instance
144
+ flexstub(Fluent::Engine) do |engineclass|
145
+ engineclass.should_receive(:emit_stream).with('pre.foo.bar.log.post', any).once
146
+ plugin.receive_lines(['foo', 'bar'], 'foo.bar.log')
147
+ end
148
+ end
149
+ end
150
+
151
+
152
+ class TailExWatcherTest < Test::Unit::TestCase
153
+ def setup
154
+ @tag = nil
155
+ @lines = nil
156
+ @watcher = Fluent::TailExInput::TailExWatcher.new('/var/tmp//foo.log', 5, nil, &method(:callback))
157
+ end
158
+
159
+ def callback(lines, tag)
160
+ @tag = tag
161
+ @lines = lines
162
+ end
163
+
164
+ def test_receive_lines
165
+ @watcher.instance_eval { @receive_lines.call(['l1', 'l2']) }
166
+ assert_equal 'var.tmp.foo.log', @tag
167
+ assert_equal ['l1', 'l2'], @lines
168
+ end
169
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-tail-ex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yoshihisa Tanaka
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluentd
16
+ requirement: &70240843162660 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70240843162660
25
+ - !ruby/object:Gem::Dependency
26
+ name: fluent-mixin-config-placeholders
27
+ requirement: &70240843161320 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70240843161320
36
+ - !ruby/object:Gem::Dependency
37
+ name: fluentd
38
+ requirement: &70240843160000 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70240843160000
47
+ - !ruby/object:Gem::Dependency
48
+ name: fluent-mixin-config-placeholders
49
+ requirement: &70240843157000 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70240843157000
58
+ - !ruby/object:Gem::Dependency
59
+ name: rake
60
+ requirement: &70240843155180 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70240843155180
69
+ - !ruby/object:Gem::Dependency
70
+ name: flexmock
71
+ requirement: &70240843152680 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70240843152680
80
+ description: Extended tail input plugin
81
+ email:
82
+ - yt.hisa@gmail.com
83
+ executables: []
84
+ extensions: []
85
+ extra_rdoc_files: []
86
+ files:
87
+ - .gitignore
88
+ - .travis.yml
89
+ - Gemfile
90
+ - LICENSE
91
+ - README.md
92
+ - Rakefile
93
+ - fluent-plugin-tail-ex.gemspec
94
+ - lib/fluent/plugin/in_tail_ex.rb
95
+ - test/helper.rb
96
+ - test/plugin/data/2010/01/20100102-030405.log
97
+ - test/plugin/data/2010/01/20100102-030406.log
98
+ - test/plugin/data/2010/01/20100102.log
99
+ - test/plugin/data/log/bar
100
+ - test/plugin/data/log/foo/bar.log
101
+ - test/plugin/data/log/test.log
102
+ - test/plugin/test_in_tail_ex.rb
103
+ homepage: https://github.com/yosisa/fluent-plugin-tail-ex
104
+ licenses: []
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 1.8.17
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: Extended tail input plugin
127
+ test_files:
128
+ - test/helper.rb
129
+ - test/plugin/data/2010/01/20100102-030405.log
130
+ - test/plugin/data/2010/01/20100102-030406.log
131
+ - test/plugin/data/2010/01/20100102.log
132
+ - test/plugin/data/log/bar
133
+ - test/plugin/data/log/foo/bar.log
134
+ - test/plugin/data/log/test.log
135
+ - test/plugin/test_in_tail_ex.rb