fluent-plugin-ping_port 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/.document +3 -0
- data/.gitignore +9 -0
- data/.travis.yml +15 -0
- data/.yardopts +1 -0
- data/Gemfile +7 -0
- data/README.md +53 -0
- data/Rakefile +11 -0
- data/exsample/exsample.conf +16 -0
- data/fluent-plugin-ping_port.gemspec +25 -0
- data/lib/fluent/plugin/in_ping_port.rb +81 -0
- data/test/helper.rb +18 -0
- data/test/plugin/test_in_ping_port.rb +76 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7ec005c29934c3d4ea17c8f4c726a2bcf5a55de3
|
4
|
+
data.tar.gz: f607664a643358561d05234800379e8163683687
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5a72ac6aaa8da2421b1dae842729248420faa0c9dea71259b64183243339168be3822ace3f7131bfeb91b11af5046e610ee41085c0efdb629d3a2f7ef68cb66a
|
7
|
+
data.tar.gz: 7097e8f836cb9c393354491f0f90b71bba923f3011dcc53f5ee80cdcae3bbeaeb1c74c4ef3b7d1f9e0159681860d8085e0422bb1e6ab76be7e1cfc9f4e3cccaa
|
data/.document
ADDED
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown --title "fluent-plugin-ping_port Documentation" --protected
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# fluent-plugin-ping_port [](http://travis-ci.org/toyama0919/fluent-plugin-ping_port)
|
2
|
+
|
3
|
+
health check with port plugin for fluentd
|
4
|
+
|
5
|
+
## Examples
|
6
|
+
```
|
7
|
+
<source>
|
8
|
+
type ping_port
|
9
|
+
tag ping_port.exsample
|
10
|
+
host forwarder-host
|
11
|
+
port 24224
|
12
|
+
timeout 10
|
13
|
+
interval 1s
|
14
|
+
retry_count 2
|
15
|
+
</source>
|
16
|
+
|
17
|
+
<match ping_port.exsample>
|
18
|
+
type stdout
|
19
|
+
</match>
|
20
|
+
```
|
21
|
+
|
22
|
+
#### output
|
23
|
+
```
|
24
|
+
2015-05-13 16:24:05 +0900 ping_port.exsample: {"message":"forwarder-host:24224 Connect Error."}
|
25
|
+
```
|
26
|
+
|
27
|
+
## parameter
|
28
|
+
|
29
|
+
|
30
|
+
## Installation
|
31
|
+
```
|
32
|
+
fluent-gem install fluent-plugin-ping_port
|
33
|
+
```
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create new [Pull Request](../../pull/new/master)
|
42
|
+
|
43
|
+
## Information
|
44
|
+
|
45
|
+
* [Homepage](https://github.com/toyama0919/fluent-plugin-ping_port)
|
46
|
+
* [Issues](https://github.com/toyama0919/fluent-plugin-ping_port/issues)
|
47
|
+
* [Documentation](http://rubydoc.info/gems/fluent-plugin-ping_port/frames)
|
48
|
+
* [Email](mailto:toyama0919@gmail.com)
|
49
|
+
|
50
|
+
## Copyright
|
51
|
+
|
52
|
+
Copyright (c) 2015 Hiroshi Toyama
|
53
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = "fluent-plugin-ping_port"
|
5
|
+
gem.version = "0.0.1"
|
6
|
+
gem.summary = %q{health check with port plugin for fluentd.}
|
7
|
+
gem.description = %q{health check with port plugin for fluentd.}
|
8
|
+
gem.license = "MIT"
|
9
|
+
gem.authors = ["Hiroshi Toyama"]
|
10
|
+
gem.email = "toyama0919@gmail.com"
|
11
|
+
gem.homepage = "https://github.com/toyama0919/fluent-plugin-ping_port"
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($/)
|
14
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
+
gem.require_paths = ['lib']
|
17
|
+
|
18
|
+
gem.add_development_dependency 'bundler', '~> 1.7.2'
|
19
|
+
gem.add_development_dependency 'fluentd', '~> 0.10.53'
|
20
|
+
gem.add_development_dependency 'pry', '~> 0.10.1'
|
21
|
+
gem.add_development_dependency 'rake', '~> 10.3.2'
|
22
|
+
gem.add_development_dependency 'rubocop', '~> 0.24.1'
|
23
|
+
gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
|
24
|
+
gem.add_development_dependency 'yard', '~> 0.8'
|
25
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Fluent
|
2
|
+
class PingPortInput < Fluent::Input
|
3
|
+
Plugin.register_input 'ping_port', self
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
require 'socket'
|
8
|
+
require 'timeout'
|
9
|
+
end
|
10
|
+
|
11
|
+
config_param :tag, :string
|
12
|
+
config_param :host, :string
|
13
|
+
config_param :port, :string
|
14
|
+
config_param :timeout, :integer, default: 1
|
15
|
+
config_param :retry_count, :integer, default: 3
|
16
|
+
config_param :interval, :time, default: '5m'
|
17
|
+
|
18
|
+
def configure(conf)
|
19
|
+
super
|
20
|
+
@ports = @port.split(',')
|
21
|
+
@state = @ports.inject({}) {|state, port|
|
22
|
+
state[port] = 0
|
23
|
+
state
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def start
|
28
|
+
@thread = Thread.new(&method(:run))
|
29
|
+
end
|
30
|
+
|
31
|
+
def shutdown
|
32
|
+
Thread.kill(@thread)
|
33
|
+
end
|
34
|
+
|
35
|
+
def run
|
36
|
+
loop do
|
37
|
+
Thread.new(&method(:emit_ping_port))
|
38
|
+
sleep @interval
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def emit_ping_port
|
43
|
+
begin
|
44
|
+
@ports.each do |port|
|
45
|
+
unless is_port_open?(@host, port, @timeout)
|
46
|
+
@state[port] = @state[port] + 1
|
47
|
+
if @state[port] >= @retry_count
|
48
|
+
record = {
|
49
|
+
'message' => "#{@host}:#{port} Connect Error."
|
50
|
+
}
|
51
|
+
Fluent::Engine.emit @tag, Fluent::Engine.now, record
|
52
|
+
@state[port] = 0
|
53
|
+
end
|
54
|
+
else
|
55
|
+
@state[port] = 0
|
56
|
+
end
|
57
|
+
end
|
58
|
+
rescue => e
|
59
|
+
log.error e
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def is_port_open?(host, port, timeout)
|
66
|
+
begin
|
67
|
+
Timeout::timeout(timeout) do
|
68
|
+
begin
|
69
|
+
s = TCPSocket.new(host, port)
|
70
|
+
s.close
|
71
|
+
return true
|
72
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
73
|
+
return false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
rescue Timeout::Error
|
77
|
+
end
|
78
|
+
return false
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
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
|
+
require 'fluent/plugin/in_ping_port'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class PingPortInputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
def create_driver(conf)
|
9
|
+
Fluent::Test::InputTestDriver.new(Fluent::PingPortInput).configure(conf)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_configure_full
|
13
|
+
d = create_driver %q{
|
14
|
+
tag ping_port.exsample
|
15
|
+
host web01
|
16
|
+
port 24224,80
|
17
|
+
timeout 10
|
18
|
+
interval 10m
|
19
|
+
retry_count 5
|
20
|
+
}
|
21
|
+
|
22
|
+
assert_equal 'ping_port.exsample', d.instance.tag
|
23
|
+
assert_equal 10 * 60, d.instance.interval
|
24
|
+
assert_equal 10, d.instance.timeout
|
25
|
+
assert_equal ["24224", "80"], d.instance.instance_variable_get(:@ports)
|
26
|
+
assert_equal ({"24224" => 0, "80" => 0}), d.instance.instance_variable_get(:@state)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_configure_error_when_config_is_empty
|
30
|
+
assert_raise(Fluent::ConfigError) do
|
31
|
+
create_driver %q{
|
32
|
+
tag ping_port.exsample
|
33
|
+
host web01
|
34
|
+
timeout 10
|
35
|
+
interval 10m
|
36
|
+
retry_count 5
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_emit_ng
|
42
|
+
d = create_driver %q{
|
43
|
+
tag ping_port.exsample
|
44
|
+
host localhost
|
45
|
+
port 9999
|
46
|
+
timeout 10
|
47
|
+
interval 1s
|
48
|
+
retry_count 2
|
49
|
+
}
|
50
|
+
|
51
|
+
d.run do
|
52
|
+
sleep 3
|
53
|
+
emits = d.emits
|
54
|
+
assert_equal true, emits.length > 0
|
55
|
+
assert_equal "ping_port.exsample", emits[0].first
|
56
|
+
assert_equal ({"message"=>"localhost:9999 Connect Error."}), emits[0].last
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_emit_ok
|
61
|
+
d = create_driver %q{
|
62
|
+
tag ping_port.exsample
|
63
|
+
host fluentd.org
|
64
|
+
port 80
|
65
|
+
timeout 10
|
66
|
+
interval 1s
|
67
|
+
retry_count 2
|
68
|
+
}
|
69
|
+
|
70
|
+
d.run do
|
71
|
+
sleep 3
|
72
|
+
emits = d.emits
|
73
|
+
assert_equal 0, emits.size
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-ping_port
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hiroshi Toyama
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-29 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.7.2
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.7.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fluentd
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.10.53
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.10.53
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.10.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.10.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 10.3.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 10.3.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.24.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.24.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubygems-tasks
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.2'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.2'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.8'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.8'
|
111
|
+
description: health check with port plugin for fluentd.
|
112
|
+
email: toyama0919@gmail.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- ".document"
|
118
|
+
- ".gitignore"
|
119
|
+
- ".travis.yml"
|
120
|
+
- ".yardopts"
|
121
|
+
- Gemfile
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- exsample/exsample.conf
|
125
|
+
- fluent-plugin-ping_port.gemspec
|
126
|
+
- lib/fluent/plugin/in_ping_port.rb
|
127
|
+
- test/helper.rb
|
128
|
+
- test/plugin/test_in_ping_port.rb
|
129
|
+
homepage: https://github.com/toyama0919/fluent-plugin-ping_port
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.4.2
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: health check with port plugin for fluentd.
|
153
|
+
test_files:
|
154
|
+
- test/helper.rb
|
155
|
+
- test/plugin/test_in_ping_port.rb
|
156
|
+
has_rdoc:
|