fluent-plugin-resolv 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.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +11 -0
- data/fluent-plugin-resolv.gemspec +25 -0
- data/lib/fluent/plugin/resolv/version.rb +7 -0
- data/lib/fluent/plugin/resolv.rb +27 -0
- data/test/helper.rb +29 -0
- data/test/plugin/test_resolv.rb +86 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cc04bd98417b70f6fe881be2c83181bb8b012d86
|
4
|
+
data.tar.gz: cee9bcac4fc03d824bbba4e84edfccb83b1b1229
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7896a4d4d4e3c0d4d849ccaf733cfedfdc9ce824c344afde6a33ed005109a0aeaca2abcad3103fcf4ac05540327f0d2e393b82e00ce0fc046c7801d514dd80d2
|
7
|
+
data.tar.gz: aadc675cf38a7b268459f983d2a341a05c61adbbd6b5e17530de81cc8644e8aa02daa6a0cbe0ca72d620a30027401d1b58a7133f4da4e0d30fc695089691a19d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Kohei MATSUSHITA <ma2shita+git@ma2shita.jp>
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
Fluent::Plugin::Resolv
|
2
|
+
======================
|
3
|
+
|
4
|
+
Fluent plugin, IP address resolv and rewrite.
|
5
|
+
|
6
|
+
|
7
|
+
Installation
|
8
|
+
------------
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'fluent-plugin-resolv'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install fluent-plugin-resolv
|
21
|
+
|
22
|
+
|
23
|
+
Usage
|
24
|
+
-----
|
25
|
+
|
26
|
+
<match hoge.foo>
|
27
|
+
type resolv
|
28
|
+
</match>
|
29
|
+
|
30
|
+
|
31
|
+
Configuration
|
32
|
+
-------------
|
33
|
+
|
34
|
+
- key_name
|
35
|
+
|
36
|
+
target key. default is `host`.
|
37
|
+
|
38
|
+
- add_prefix / remove_prefix
|
39
|
+
|
40
|
+
remove_prefix: removes the string from a prefix of tag.
|
41
|
+
|
42
|
+
add_prefix: prepend the string to a tag.
|
43
|
+
|
44
|
+
|
45
|
+
inside
|
46
|
+
------
|
47
|
+
|
48
|
+
using ruby Resolv.
|
49
|
+
|
50
|
+
|
51
|
+
TODO
|
52
|
+
----
|
53
|
+
|
54
|
+
any patches, fork and so on. welcome !
|
55
|
+
|
56
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fluent/plugin/resolv/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fluent-plugin-resolv"
|
8
|
+
spec.version = Fluent::Plugin::Resolv::VERSION
|
9
|
+
spec.authors = ["Kohei MATSUSHITA"]
|
10
|
+
spec.email = ["ma2shita+git@ma2shita.jp"]
|
11
|
+
spec.description = %q{Fluent plugin, IP address resolv and rewrite.}
|
12
|
+
spec.summary = %q{Fluent plugin, IP address resolv and rewrite.}
|
13
|
+
spec.homepage = %q{https://github.com/ma2shita/fluent-plugin-resolv}
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "fluentd"
|
24
|
+
spec.add_runtime_dependency "fluentd"
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "fluent/plugin/resolv/version"
|
2
|
+
require 'resolv'
|
3
|
+
|
4
|
+
class Fluent::ResolvOutput < Fluent::Output
|
5
|
+
Fluent::Plugin.register_output('resolv', self)
|
6
|
+
|
7
|
+
config_param :key_name, :string, :default => 'host'
|
8
|
+
config_param :remove_prefix, :string, :default => nil
|
9
|
+
config_param :add_prefix, :string, :default => nil
|
10
|
+
|
11
|
+
def configure(conf)
|
12
|
+
super
|
13
|
+
@remove_prefix = Regexp.new("^#{Regexp.escape(remove_prefix)}\.?") unless conf['remove_prefix'].nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
def emit(tag, es, chain)
|
17
|
+
tag = tag.sub(@remove_prefix, '') if @remove_prefix
|
18
|
+
tag = (@add_prefix + '.' + tag) if @add_prefix
|
19
|
+
es.each do |time,record|
|
20
|
+
record[@key_name] = Resolv.getname(record[@key_name]) rescue record[@key_name].empty? ? 'n/a' : record[@key_name]
|
21
|
+
Fluent::Engine.emit(tag, time, record)
|
22
|
+
end
|
23
|
+
chain.next
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
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/resolv'
|
26
|
+
|
27
|
+
class Test::Unit::TestCase
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class ResolvOutputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
def create_driver(conf, tag = 'test')
|
9
|
+
Fluent::Test::OutputTestDriver.new(Fluent::ResolvOutput, tag).configure(conf)
|
10
|
+
end
|
11
|
+
|
12
|
+
CONFIG0 = %[]
|
13
|
+
def test_resolv
|
14
|
+
time = Time.now.to_i
|
15
|
+
d = create_driver(CONFIG0)
|
16
|
+
d.run do
|
17
|
+
d.emit({'host' => '124.39.181.36'})
|
18
|
+
d.emit({'host' => '192.0.2.1'})
|
19
|
+
d.emit({'host' => 'cannot.resolv'})
|
20
|
+
d.emit({'host' => ''})
|
21
|
+
end
|
22
|
+
assert_equal 4, d.emits.length
|
23
|
+
assert_equal 'www.plathome.co.jp', d.emits[0][2]['host']
|
24
|
+
assert_equal '192.0.2.1', d.emits[1][2]['host']
|
25
|
+
assert_equal 'cannot.resolv', d.emits[2][2]['host']
|
26
|
+
assert_equal 'n/a', d.emits[3][2]['host']
|
27
|
+
end
|
28
|
+
|
29
|
+
CONFIG1 = %[
|
30
|
+
key_name any_key_name
|
31
|
+
]
|
32
|
+
def test_key_name
|
33
|
+
time = Time.now.to_i
|
34
|
+
d = create_driver(CONFIG1)
|
35
|
+
d.run do
|
36
|
+
d.emit({'any_key_name' => '124.39.181.36'})
|
37
|
+
end
|
38
|
+
assert_equal 1, d.emits.length
|
39
|
+
assert_equal 'www.plathome.co.jp', d.emits[0][2]['any_key_name']
|
40
|
+
end
|
41
|
+
|
42
|
+
CONFIG2 = %[
|
43
|
+
add_prefix foo
|
44
|
+
]
|
45
|
+
def test_add_prefix
|
46
|
+
time = Time.now.to_i
|
47
|
+
d = create_driver(CONFIG2)
|
48
|
+
d.run do
|
49
|
+
d.emit({'host' => '124.39.181.36'})
|
50
|
+
end
|
51
|
+
assert_equal 1, d.emits.length
|
52
|
+
assert_equal 'www.plathome.co.jp', d.emits[0][2]['host']
|
53
|
+
assert_equal 'foo.test', d.emits[0][0]
|
54
|
+
end
|
55
|
+
|
56
|
+
CONFIG3 = %[
|
57
|
+
remove_prefix tag
|
58
|
+
]
|
59
|
+
def test_remove_prefix
|
60
|
+
time = Time.now.to_i
|
61
|
+
d = create_driver(CONFIG3, 'tag.tag1.tag2')
|
62
|
+
d.run do
|
63
|
+
d.emit({'host' => '124.39.181.36'})
|
64
|
+
end
|
65
|
+
assert_equal 1, d.emits.length
|
66
|
+
assert_equal 'www.plathome.co.jp', d.emits[0][2]['host']
|
67
|
+
assert_equal 'tag1.tag2', d.emits[0][0]
|
68
|
+
end
|
69
|
+
|
70
|
+
CONFIG4 = %[
|
71
|
+
remove_prefix tag
|
72
|
+
add_prefix good
|
73
|
+
]
|
74
|
+
def test_remove_and_add_prefix
|
75
|
+
time = Time.now.to_i
|
76
|
+
d = create_driver(CONFIG4, 'tag.tag1')
|
77
|
+
d.run do
|
78
|
+
d.emit({'host' => '124.39.181.36'})
|
79
|
+
end
|
80
|
+
assert_equal 1, d.emits.length
|
81
|
+
assert_equal 'www.plathome.co.jp', d.emits[0][2]['host']
|
82
|
+
assert_equal 'good.tag1', d.emits[0][0]
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-resolv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kohei MATSUSHITA
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-07 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: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fluentd
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Fluent plugin, IP address resolv and rewrite.
|
70
|
+
email:
|
71
|
+
- ma2shita+git@ma2shita.jp
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- fluent-plugin-resolv.gemspec
|
82
|
+
- lib/fluent/plugin/resolv.rb
|
83
|
+
- lib/fluent/plugin/resolv/version.rb
|
84
|
+
- test/helper.rb
|
85
|
+
- test/plugin/test_resolv.rb
|
86
|
+
homepage: https://github.com/ma2shita/fluent-plugin-resolv
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.0.2
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Fluent plugin, IP address resolv and rewrite.
|
110
|
+
test_files:
|
111
|
+
- test/helper.rb
|
112
|
+
- test/plugin/test_resolv.rb
|