fluent-plugin-stdin 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +20 -0
- data/Gemfile +3 -0
- data/README.md +41 -0
- data/Rakefile +13 -0
- data/VERSION +1 -0
- data/fluent-plugin-stdin.gemspec +23 -0
- data/lib/fluent/plugin/in_stdin.rb +78 -0
- data/test/test_in_stdin.rb +58 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b2ea3c32514a386aa25828404b061916931bc597
|
4
|
+
data.tar.gz: ae4d073b0fcd6ad01b785a3633f16ec547809d11
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e9b0869419b7c5d07220cd15c8a0e286f3d22f313baad513e76cf912eb25ee79d9cef05e67c4085aedf5fdbb6ae643ed702f8bfc11fd8e734ba8aaf2be7135bc
|
7
|
+
data.tar.gz: 406870d59ffbc5cb42590cf846f73268f2f32b222212ab369dad03b213418dca1e0a69045d535e24b0a306a99b325a3270891bf4b66f8034494457b4b8ff4663
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Fluentd plugin for reading events from stdin
|
2
|
+
|
3
|
+
Reading events from stdin for testing or small bulk loading.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Use RubyGems:
|
8
|
+
|
9
|
+
gem install fluent-plugin-stdin
|
10
|
+
|
11
|
+
## Configuration
|
12
|
+
|
13
|
+
<source>
|
14
|
+
type stdin
|
15
|
+
|
16
|
+
# Input pattern. It depends on Parser plugin
|
17
|
+
format none
|
18
|
+
|
19
|
+
# Optional. default is stdin.events
|
20
|
+
tag test.input
|
21
|
+
</source>
|
22
|
+
|
23
|
+
After that, you can send logs to fluentd via stdin like below.
|
24
|
+
|
25
|
+
cat /path/to/logs | fluentd -c stdin.conf
|
26
|
+
|
27
|
+
This plugin works on only non-daemon mode.
|
28
|
+
|
29
|
+
## Copyright
|
30
|
+
|
31
|
+
<table>
|
32
|
+
<tr>
|
33
|
+
<td>Author</td><td>Masahiro Nakagawa <repeatedly@gmail.com></td>
|
34
|
+
</tr>
|
35
|
+
<tr>
|
36
|
+
<td>Copyright</td><td>Copyright (c) 2015- Masahiro Nakagawa</td>
|
37
|
+
</tr>
|
38
|
+
<tr>
|
39
|
+
<td>License</td><td>MIT License</td>
|
40
|
+
</tr>
|
41
|
+
</table>
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
require 'bundler'
|
3
|
+
Bundler::GemHelper.install_tasks
|
4
|
+
|
5
|
+
require 'rake/testtask'
|
6
|
+
|
7
|
+
Rake::TestTask.new(:test) do |test|
|
8
|
+
test.libs << 'lib' << 'test'
|
9
|
+
test.test_files = FileList['test/*.rb']
|
10
|
+
test.verbose = true
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => [:build]
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "fluent-plugin-stdin"
|
6
|
+
gem.description = "Fluentd plugin for reading events from stdin"
|
7
|
+
gem.homepage = "https://github.com/repeatedly/fluent-plugin-stdin"
|
8
|
+
gem.summary = gem.description
|
9
|
+
gem.version = File.read("VERSION").strip
|
10
|
+
gem.authors = ["Masahiro Nakagawa"]
|
11
|
+
gem.email = "repeatedly@gmail.com"
|
12
|
+
gem.has_rdoc = false
|
13
|
+
#gem.platform = Gem::Platform::RUBY
|
14
|
+
gem.license = 'MIT'
|
15
|
+
gem.files = `git ls-files`.split("\n")
|
16
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
gem.add_dependency "fluentd", ">= 0.10.17"
|
21
|
+
gem.add_development_dependency "rake", ">= 0.9.2"
|
22
|
+
gem.add_development_dependency "test-unit", "~> 3.0.2"
|
23
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
module Fluent
|
18
|
+
class StdinInput < Input
|
19
|
+
Plugin.register_input('stdin', self)
|
20
|
+
|
21
|
+
config_param :format, :string
|
22
|
+
config_param :delimiter, :string, :default => "\n"
|
23
|
+
config_param :tag, :string, :default => 'stdin.events'
|
24
|
+
|
25
|
+
def configure(conf)
|
26
|
+
super
|
27
|
+
|
28
|
+
@parser = Plugin.new_parser(@format)
|
29
|
+
@parser.configure(conf)
|
30
|
+
end
|
31
|
+
|
32
|
+
def start
|
33
|
+
@buffer = "".force_encoding('ASCII-8BIT')
|
34
|
+
@thread = Thread.new(&method(:run))
|
35
|
+
end
|
36
|
+
|
37
|
+
def shutdown
|
38
|
+
@thread.join
|
39
|
+
end
|
40
|
+
|
41
|
+
def run
|
42
|
+
while true
|
43
|
+
begin
|
44
|
+
@buffer << $stdin.sysread(4000)
|
45
|
+
pos = 0
|
46
|
+
|
47
|
+
while i = @buffer.index(@delimiter, pos)
|
48
|
+
msg = @buffer[pos...i]
|
49
|
+
emit_event(msg)
|
50
|
+
pos = i + @delimiter.length
|
51
|
+
end
|
52
|
+
@buffer.slice!(0, pos) if pos > 0
|
53
|
+
rescue IOError, EOFError => e
|
54
|
+
# ignore above exceptions because can't re-open stdin automatically
|
55
|
+
break
|
56
|
+
rescue => e
|
57
|
+
log.error "unexpected error", :error=> e.to_s
|
58
|
+
log.error_backtrace
|
59
|
+
break
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def emit_event(msg)
|
65
|
+
@parser.parse(msg) { |time, record|
|
66
|
+
unless time && record
|
67
|
+
log.warn "pattern not match: #{msg.inspect}"
|
68
|
+
return
|
69
|
+
end
|
70
|
+
|
71
|
+
router.emit(@tag, time, record)
|
72
|
+
}
|
73
|
+
rescue => e
|
74
|
+
log.error msg.dump, :error => e, :error_class => e.class
|
75
|
+
log.error_backtrace
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'fluent/test'
|
2
|
+
require 'fluent/plugin/in_stdin'
|
3
|
+
|
4
|
+
class StdinInputTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Fluent::Test.setup
|
7
|
+
r, w = IO.pipe
|
8
|
+
$stdin = r
|
9
|
+
@writer = w
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
$stdin = STDIN
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_driver(conf)
|
17
|
+
Fluent::Test::InputTestDriver.new(Fluent::StdinInput).configure(conf)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_configure
|
21
|
+
d = create_driver("format none")
|
22
|
+
assert_equal 'stdin.events', d.instance.tag
|
23
|
+
assert_equal "\n", d.instance.delimiter
|
24
|
+
end
|
25
|
+
|
26
|
+
{
|
27
|
+
'none' => [
|
28
|
+
{'msg' => "tcptest1\n", 'expected' => 'tcptest1'},
|
29
|
+
{'msg' => "tcptest2\n", 'expected' => 'tcptest2'},
|
30
|
+
],
|
31
|
+
'json' => [
|
32
|
+
{'msg' => {'k' => 123, 'message' => 'tcptest1'}.to_json + "\n", 'expected' => 'tcptest1'},
|
33
|
+
{'msg' => {'k' => 'tcptest2', 'message' => 456}.to_json + "\n", 'expected' => 456},
|
34
|
+
]
|
35
|
+
}.each { |format, test_cases|
|
36
|
+
define_method("test_msg_size_#{format}") do
|
37
|
+
d = create_driver("format #{format}")
|
38
|
+
tests = test_cases
|
39
|
+
|
40
|
+
d.run do
|
41
|
+
tests.each { |test|
|
42
|
+
@writer.write test['msg']
|
43
|
+
}
|
44
|
+
@writer.close
|
45
|
+
sleep 1
|
46
|
+
end
|
47
|
+
|
48
|
+
compare_test_result(d.emits, tests)
|
49
|
+
end
|
50
|
+
}
|
51
|
+
|
52
|
+
def compare_test_result(emits, tests)
|
53
|
+
assert_equal(2, emits.size)
|
54
|
+
emits.each_index {|i|
|
55
|
+
assert_equal(tests[i]['expected'], emits[i][2]['message'])
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-stdin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Masahiro Nakagawa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-19 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.17
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.10.17
|
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.9.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.9.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.2
|
55
|
+
description: Fluentd plugin for reading events from stdin
|
56
|
+
email: repeatedly@gmail.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- ".travis.yml"
|
62
|
+
- Gemfile
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- VERSION
|
66
|
+
- fluent-plugin-stdin.gemspec
|
67
|
+
- lib/fluent/plugin/in_stdin.rb
|
68
|
+
- test/test_in_stdin.rb
|
69
|
+
homepage: https://github.com/repeatedly/fluent-plugin-stdin
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.4.5
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Fluentd plugin for reading events from stdin
|
93
|
+
test_files:
|
94
|
+
- test/test_in_stdin.rb
|