fluent-plugin-hostname 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.
- data/.document +5 -0
- data/.gitignore +30 -0
- data/.gitmodules +3 -0
- data/AUTHORS +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +13 -0
- data/README.md +22 -0
- data/Rakefile +11 -0
- data/VERSION +1 -0
- data/fluent-plugin-hostname.gemspec +20 -0
- data/lib/fluent/plugin/out_hostname.rb +31 -0
- data/test/helper.rb +28 -0
- data/test/plugin/test_out_hostname.rb +88 -0
- metadata +108 -0
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
|
4
|
+
# rdoc generated
|
5
|
+
rdoc
|
6
|
+
|
7
|
+
# yard generated
|
8
|
+
doc
|
9
|
+
.yardoc
|
10
|
+
|
11
|
+
# bundler
|
12
|
+
.bundle
|
13
|
+
|
14
|
+
# jeweler generated
|
15
|
+
pkg
|
16
|
+
|
17
|
+
# For MacOS
|
18
|
+
.DS_Store
|
19
|
+
|
20
|
+
# For TextMate, emacs, vim
|
21
|
+
*.tmproj
|
22
|
+
tmtags
|
23
|
+
*~
|
24
|
+
\#*
|
25
|
+
.\#*
|
26
|
+
*.swp
|
27
|
+
|
28
|
+
# not to lock gems version, and for bundler
|
29
|
+
Gemfile.lock
|
30
|
+
vendor
|
data/.gitmodules
ADDED
data/AUTHORS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Tatsuya Fukata <tatsuya.fukata@gmail.com>
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012- Tatsuya Fukata
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# fluent-plugin-hostname
|
2
|
+
|
3
|
+
Fluentd plugin put the hostname in the data.
|
4
|
+
|
5
|
+
## Configuration
|
6
|
+
|
7
|
+
### HostnameOutput
|
8
|
+
|
9
|
+
<match hoge.foo>
|
10
|
+
type hostname
|
11
|
+
key_name host
|
12
|
+
</match>
|
13
|
+
|
14
|
+
Output messages like:
|
15
|
+
|
16
|
+
{"field1": "value1", "field2": "value2", "host": "app01.hoge"}
|
17
|
+
|
18
|
+
## Copyright
|
19
|
+
|
20
|
+
Copyright (c) 2012 Tatsuya Fukata. See LICENSE.txt for
|
21
|
+
further details.
|
22
|
+
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = "fluent-plugin-hostname"
|
5
|
+
gem.version = "0.0.1"
|
6
|
+
gem.authors = ["Tatsuya Fukata"]
|
7
|
+
gem.email = ["tatsuya.fukata@gmail.com"]
|
8
|
+
gem.summary = %q{Fluentd plugin to data mixin hostname}
|
9
|
+
gem.description = %q{}
|
10
|
+
gem.homepage = "https://github.com/fukata/fluent-plugin-hostname"
|
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.require_paths = ["lib"]
|
16
|
+
|
17
|
+
gem.add_development_dependency "fluentd"
|
18
|
+
gem.add_development_dependency "rake"
|
19
|
+
gem.add_runtime_dependency "fluentd"
|
20
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
class Fluent::HostnameOutput < Fluent::Output
|
4
|
+
Fluent::Plugin.register_output('hostname', self)
|
5
|
+
|
6
|
+
include Fluent::SetTagKeyMixin
|
7
|
+
config_set_default :include_tag_key, false
|
8
|
+
|
9
|
+
include Fluent::SetTimeKeyMixin
|
10
|
+
config_set_default :include_time_key, true
|
11
|
+
|
12
|
+
config_param :key_name, :string, :default => 'host'
|
13
|
+
config_param :host, :string, :default => Socket.gethostname
|
14
|
+
|
15
|
+
def configure(conf)
|
16
|
+
super
|
17
|
+
|
18
|
+
if @key_name.empty?
|
19
|
+
raise Fluent::ConfigError, "key_name is must not be specified"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def emit(tag, es, chain)
|
24
|
+
es.each do |time,record|
|
25
|
+
record[@key_name] = @host
|
26
|
+
Fluent::Engine.emit(tag, time, record)
|
27
|
+
end
|
28
|
+
|
29
|
+
chain.next
|
30
|
+
end
|
31
|
+
end
|
data/test/helper.rb
ADDED
@@ -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_hostname'
|
26
|
+
|
27
|
+
class Test::Unit::TestCase
|
28
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class HostnameOutputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
CONFIG1 = %[
|
9
|
+
host app01.hoge
|
10
|
+
]
|
11
|
+
CONFIG2 = %[
|
12
|
+
key_name server
|
13
|
+
host app02.hoge
|
14
|
+
]
|
15
|
+
CONFIG3 = %[
|
16
|
+
host app03.hoge
|
17
|
+
]
|
18
|
+
|
19
|
+
def create_driver(conf = CONFIG, tag='test')
|
20
|
+
Fluent::Test::OutputTestDriver.new(Fluent::HostnameOutput, tag).configure(conf)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_emit1
|
24
|
+
d = create_driver(CONFIG1)
|
25
|
+
time = Time.now.to_i
|
26
|
+
d.run do
|
27
|
+
d.emit({'foo' => 'bar', 'baz' => 'boo'}, time)
|
28
|
+
d.emit({'foo' => 'bar', 'baz' => 'boo'}, time)
|
29
|
+
end
|
30
|
+
emits = d.emits
|
31
|
+
assert_equal 2, emits.length
|
32
|
+
|
33
|
+
assert_equal 'test', emits[0][0]
|
34
|
+
assert_equal time, emits[0][1]
|
35
|
+
assert_equal ['foo','baz','host'], emits[0][2].keys
|
36
|
+
assert_equal 'app01.hoge', emits[0][2]['host']
|
37
|
+
|
38
|
+
|
39
|
+
assert_equal 'test', emits[0][0]
|
40
|
+
assert_equal time, emits[0][1]
|
41
|
+
assert_equal ['foo','baz','host'], emits[0][2].keys
|
42
|
+
assert_equal 'app01.hoge', emits[0][2]['host']
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_emit2
|
46
|
+
d = create_driver(CONFIG2)
|
47
|
+
time = Time.now.to_i
|
48
|
+
d.run do
|
49
|
+
d.emit({'foo' => 'bar', 'baz' => 'boo'}, time)
|
50
|
+
d.emit({'foo' => 'bar', 'baz' => 'boo'}, time)
|
51
|
+
end
|
52
|
+
emits = d.emits
|
53
|
+
assert_equal 2, emits.length
|
54
|
+
|
55
|
+
assert_equal 'test', emits[0][0]
|
56
|
+
assert_equal time, emits[0][1]
|
57
|
+
assert_equal ['foo','baz','server'], emits[0][2].keys
|
58
|
+
assert_equal 'app02.hoge', emits[0][2]['server']
|
59
|
+
|
60
|
+
|
61
|
+
assert_equal 'test', emits[0][0]
|
62
|
+
assert_equal time, emits[0][1]
|
63
|
+
assert_equal ['foo','baz','server'], emits[0][2].keys
|
64
|
+
assert_equal 'app02.hoge', emits[0][2]['server']
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_emit3
|
68
|
+
d = create_driver(CONFIG3)
|
69
|
+
time = Time.now.to_i
|
70
|
+
d.run do
|
71
|
+
d.emit({'foo' => 'bar', 'baz' => 'boo', 'host' => 'hoge'}, time)
|
72
|
+
d.emit({'foo' => 'bar', 'baz' => 'boo', 'host' => 'hoge'}, time)
|
73
|
+
end
|
74
|
+
emits = d.emits
|
75
|
+
assert_equal 2, emits.length
|
76
|
+
|
77
|
+
assert_equal 'test', emits[0][0]
|
78
|
+
assert_equal time, emits[0][1]
|
79
|
+
assert_equal ['foo','baz','host'], emits[0][2].keys
|
80
|
+
assert_equal 'app03.hoge', emits[0][2]['host']
|
81
|
+
|
82
|
+
|
83
|
+
assert_equal 'test', emits[0][0]
|
84
|
+
assert_equal time, emits[0][1]
|
85
|
+
assert_equal ['foo','baz','host'], emits[0][2].keys
|
86
|
+
assert_equal 'app03.hoge', emits[0][2]['host']
|
87
|
+
end
|
88
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-hostname
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tatsuya Fukata
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: fluentd
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: fluentd
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: ''
|
63
|
+
email:
|
64
|
+
- tatsuya.fukata@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .document
|
70
|
+
- .gitignore
|
71
|
+
- .gitmodules
|
72
|
+
- AUTHORS
|
73
|
+
- Gemfile
|
74
|
+
- LICENSE.txt
|
75
|
+
- README.md
|
76
|
+
- Rakefile
|
77
|
+
- VERSION
|
78
|
+
- fluent-plugin-hostname.gemspec
|
79
|
+
- lib/fluent/plugin/out_hostname.rb
|
80
|
+
- test/helper.rb
|
81
|
+
- test/plugin/test_out_hostname.rb
|
82
|
+
homepage: https://github.com/fukata/fluent-plugin-hostname
|
83
|
+
licenses: []
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.23
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Fluentd plugin to data mixin hostname
|
106
|
+
test_files:
|
107
|
+
- test/helper.rb
|
108
|
+
- test/plugin/test_out_hostname.rb
|