fluent-plugin-http-pull 0.2.0.pre → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/README.md +9 -5
- data/fluent-plugin-http-pull.gemspec +1 -1
- data/lib/fluent/plugin/in_http_pull.rb +31 -33
- data/test/plugin/test_in_http_pull.rb +104 -24
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e57e28927445599a7804fccaf99431766cc812f4
|
4
|
+
data.tar.gz: dd25e97f2e55ff1a7f6ab4f4ef857b7ad4d6bc53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08788a78bfec1da171d1781a866974ffce3066dc82ab72a34fed00171d1ead7fb8429856fe468a1ca0c11e3f2719c4de75e9a414e77b78e81df0b28c35387a20'
|
7
|
+
data.tar.gz: 5073957aa4e3ebe5f19c39d33a08eded5fb138cc71649ceb6b51159ac883ee32c8ad79f8797d469ac9431521b5a4764c48eb8d22a5545c6da9369cec35169a6b
|
data/.gitignore
ADDED
data/README.md
CHANGED
@@ -39,7 +39,7 @@ $ bundle
|
|
39
39
|
|
40
40
|
tag test
|
41
41
|
url http://www.google.com
|
42
|
-
interval
|
42
|
+
interval 1s
|
43
43
|
|
44
44
|
status_only true
|
45
45
|
</source>
|
@@ -67,7 +67,7 @@ $ bundle
|
|
67
67
|
|
68
68
|
tag fluentd.status
|
69
69
|
url http://localhost:24220/api/plugins.json
|
70
|
-
interval
|
70
|
+
interval 1s
|
71
71
|
</source>
|
72
72
|
|
73
73
|
<match fluentd.status>
|
@@ -88,7 +88,7 @@ $ bundle
|
|
88
88
|
|
89
89
|
tag es.cluster.health
|
90
90
|
url http://localhost:9200/_cluster/health
|
91
|
-
interval
|
91
|
+
interval 1s
|
92
92
|
</source>
|
93
93
|
|
94
94
|
<match es.cluster.health>
|
@@ -111,14 +111,18 @@ The tag of the event.
|
|
111
111
|
|
112
112
|
The url of remote server.
|
113
113
|
|
114
|
-
### interval (
|
114
|
+
### interval (time) (required)
|
115
115
|
|
116
|
-
The
|
116
|
+
The interval time between periodic request.
|
117
117
|
|
118
118
|
### status_only (bool) (optional, default: false)
|
119
119
|
|
120
120
|
If atatus_only is true, body is not parsed.
|
121
121
|
|
122
|
+
### timeout (integer) (optional, default: 10)
|
123
|
+
|
124
|
+
Timeout second of each request.
|
125
|
+
|
122
126
|
## In case of remote error
|
123
127
|
|
124
128
|
### Can receive response from remote
|
@@ -21,62 +21,60 @@ module Fluent
|
|
21
21
|
class HttpPullInput < Fluent::Plugin::Input
|
22
22
|
Fluent::Plugin.register_input("http_pull", self)
|
23
23
|
|
24
|
+
helpers :timer
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
24
30
|
desc 'The tag of the event.'
|
25
31
|
config_param :tag, :string
|
26
|
-
|
27
32
|
desc 'The uri of monitoring target'
|
28
33
|
config_param :url, :string
|
29
|
-
|
30
|
-
|
31
|
-
config_param :interval, :integer
|
32
|
-
|
34
|
+
desc 'The interval time between periodic request'
|
35
|
+
config_param :interval, :time
|
33
36
|
desc 'status_only'
|
34
37
|
config_param :status_only, :bool, default: false
|
38
|
+
desc 'timeout second of each request'
|
39
|
+
config_param :timeout, :integer, default: 10
|
35
40
|
|
36
41
|
def configure(conf)
|
37
42
|
super
|
38
|
-
|
39
|
-
@shutdown = false
|
40
43
|
end
|
41
44
|
|
42
45
|
def start
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
def run
|
47
|
-
while !@shutdown
|
48
|
-
ts = Time.now.to_f
|
46
|
+
super
|
49
47
|
|
50
|
-
|
48
|
+
timer_execute(:in_http_pull, @interval, &method(:on_timer))
|
49
|
+
end
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
51
|
+
def on_timer
|
52
|
+
log = { "url" => @url }
|
53
|
+
|
54
|
+
begin
|
55
|
+
res = RestClient::Request.execute(method: :get,
|
56
|
+
url: @url,
|
57
|
+
timeout: @timeout)
|
58
|
+
log["status"] = res.code
|
59
|
+
log["body"] = res.body
|
60
|
+
rescue StandardError => err
|
61
|
+
if err.respond_to? :code
|
57
62
|
log["status"] = err.code
|
58
|
-
|
59
|
-
rescue Exception => err
|
63
|
+
else
|
60
64
|
log["status"] = 0
|
61
|
-
log["error"] = err.message
|
62
65
|
end
|
63
66
|
|
64
|
-
log["
|
65
|
-
|
66
|
-
|
67
|
-
router.emit(@tag, Engine.now, log)
|
67
|
+
log["error"] = err.message
|
68
|
+
end
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
delay = delay > 0 ? delay : 0
|
70
|
+
log["message"] = JSON.parse(log["body"]) if !@status_only && log["body"] != nil
|
71
|
+
log.delete("body")
|
72
72
|
|
73
|
-
|
74
|
-
end
|
73
|
+
router.emit(@tag, Engine.now, log)
|
75
74
|
end
|
76
75
|
|
77
76
|
def shutdown
|
78
|
-
|
79
|
-
@thread.join if @thread
|
77
|
+
super
|
80
78
|
end
|
81
79
|
|
82
80
|
end
|
@@ -4,43 +4,73 @@ require "fluent/plugin/in_http_pull.rb"
|
|
4
4
|
require 'ostruct'
|
5
5
|
|
6
6
|
class HttpPullInputTest < Test::Unit::TestCase
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
setup do
|
8
|
+
Fluent::Test.setup
|
9
|
+
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
sub_test_case "default value of each options" do
|
12
|
+
TEST_DEFAULT_VALUE_CONFIG = %[
|
13
|
+
tag test
|
14
|
+
url http://127.0.0.1
|
15
|
+
interval 3s
|
16
|
+
]
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
test 'status_only' do
|
19
|
+
d = create_driver TEST_DEFAULT_VALUE_CONFIG
|
20
|
+
assert_equal("test", d.instance.tag)
|
18
21
|
|
19
|
-
|
20
|
-
|
22
|
+
assert_equal(false, d.instance.status_only)
|
23
|
+
end
|
21
24
|
|
22
|
-
|
23
|
-
|
25
|
+
test 'timeout' do
|
26
|
+
d = create_driver TEST_DEFAULT_VALUE_CONFIG
|
27
|
+
assert_equal("test", d.instance.tag)
|
28
|
+
|
29
|
+
assert_equal(10, d.instance.timeout)
|
30
|
+
end
|
24
31
|
end
|
25
32
|
|
26
33
|
sub_test_case "success case with status only" do
|
34
|
+
TEST_INTERVAL_3_CONFIG = %[
|
35
|
+
tag test
|
36
|
+
url http://127.0.0.1
|
37
|
+
timeout 10
|
38
|
+
|
39
|
+
interval 3s
|
40
|
+
status_only true
|
41
|
+
]
|
42
|
+
|
43
|
+
TEST_INTERVAL_5_CONFIG = %[
|
44
|
+
tag test
|
45
|
+
url http://127.0.0.1
|
46
|
+
timeout 10
|
47
|
+
|
48
|
+
interval 5s
|
49
|
+
]
|
50
|
+
|
27
51
|
setup do
|
28
|
-
mock(RestClient).
|
29
|
-
|
30
|
-
|
52
|
+
mock(RestClient::Request).
|
53
|
+
execute(method: :get,
|
54
|
+
url: "http://127.0.0.1",
|
55
|
+
timeout: 10).
|
56
|
+
times(2) do
|
57
|
+
OpenStruct.new({code: 200, body: '{"status": "OK"}'})
|
58
|
+
end
|
31
59
|
end
|
32
60
|
|
33
61
|
test 'interval 3 with status_only' do
|
34
62
|
d = create_driver TEST_INTERVAL_3_CONFIG
|
35
|
-
assert_equal
|
63
|
+
assert_equal("test", d.instance.tag)
|
64
|
+
assert_equal(3, d.instance.interval)
|
36
65
|
|
37
66
|
d.run(timeout: 5) do
|
38
|
-
sleep
|
67
|
+
sleep 7
|
39
68
|
end
|
40
|
-
assert_equal
|
69
|
+
assert_equal(2, d.events.size)
|
41
70
|
|
42
71
|
d.events.each do |tag, time, record|
|
43
72
|
assert_equal("test", tag)
|
73
|
+
|
44
74
|
assert_equal({"url"=>"http://127.0.0.1","status"=>200}, record)
|
45
75
|
assert(time.is_a?(Fluent::EventTime))
|
46
76
|
end
|
@@ -48,15 +78,17 @@ class HttpPullInputTest < Test::Unit::TestCase
|
|
48
78
|
|
49
79
|
test 'interval 5' do
|
50
80
|
d = create_driver TEST_INTERVAL_5_CONFIG
|
51
|
-
assert_equal
|
81
|
+
assert_equal("test", d.instance.tag)
|
82
|
+
assert_equal(5, d.instance.interval)
|
52
83
|
|
53
84
|
d.run(timeout: 7) do
|
54
|
-
sleep
|
85
|
+
sleep 11
|
55
86
|
end
|
56
|
-
assert_equal
|
87
|
+
assert_equal(2, d.events.size)
|
57
88
|
|
58
89
|
d.events.each do |tag, time, record|
|
59
90
|
assert_equal("test", tag)
|
91
|
+
|
60
92
|
assert_equal({"url"=>"http://127.0.0.1","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
61
93
|
assert(time.is_a?(Fluent::EventTime))
|
62
94
|
end
|
@@ -71,14 +103,62 @@ class HttpPullInputTest < Test::Unit::TestCase
|
|
71
103
|
]
|
72
104
|
test "connection refused by remote" do
|
73
105
|
d = create_driver TEST_REFUSED_CONFIG
|
74
|
-
d.
|
106
|
+
assert_equal("test", d.instance.tag)
|
107
|
+
|
108
|
+
d.run(timeout: 2) do
|
109
|
+
sleep 3
|
110
|
+
end
|
75
111
|
|
76
|
-
assert_equal
|
112
|
+
assert_equal(3, d.events.size)
|
77
113
|
d.events.each do |tag, time, record|
|
78
114
|
assert_equal("test", tag)
|
115
|
+
|
79
116
|
assert_equal("http://127.0.0.1:5927", record["url"])
|
117
|
+
assert(time.is_a?(Fluent::EventTime))
|
118
|
+
|
80
119
|
assert_equal(0, record["status"])
|
120
|
+
assert_not_nil(record["error"])
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
sub_test_case "fail when remote timeout" do
|
126
|
+
TEST_TIMEOUT_FAIL_CONFIG = %[
|
127
|
+
tag test
|
128
|
+
url http://127.0.0.1
|
129
|
+
timeout 2
|
130
|
+
|
131
|
+
interval 3
|
132
|
+
]
|
133
|
+
|
134
|
+
setup do
|
135
|
+
mock(RestClient::Request).
|
136
|
+
execute(method: :get,
|
137
|
+
url: "http://127.0.0.1",
|
138
|
+
timeout: 2).
|
139
|
+
times(2) do
|
140
|
+
sleep 2
|
141
|
+
raise RestClient::Exceptions::Timeout.new
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
test "timeout" do
|
146
|
+
d = create_driver TEST_TIMEOUT_FAIL_CONFIG
|
147
|
+
assert_equal("test", d.instance.tag)
|
148
|
+
|
149
|
+
d.run(timeout: 5) do
|
150
|
+
sleep 7
|
151
|
+
end
|
152
|
+
assert_equal(2, d.events.size)
|
153
|
+
|
154
|
+
d.events.each do |tag, time, record|
|
155
|
+
assert_equal("test", tag)
|
156
|
+
|
157
|
+
assert_equal("http://127.0.0.1", record["url"])
|
81
158
|
assert(time.is_a?(Fluent::EventTime))
|
159
|
+
|
160
|
+
assert_equal(0, record["status"])
|
161
|
+
assert_not_nil(record["error"])
|
82
162
|
end
|
83
163
|
end
|
84
164
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-http-pull
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- filepang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -105,6 +105,7 @@ executables: []
|
|
105
105
|
extensions: []
|
106
106
|
extra_rdoc_files: []
|
107
107
|
files:
|
108
|
+
- ".gitignore"
|
108
109
|
- ".travis.yml"
|
109
110
|
- Gemfile
|
110
111
|
- LICENSE
|
@@ -129,9 +130,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
130
|
version: '0'
|
130
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
132
|
requirements:
|
132
|
-
- - "
|
133
|
+
- - ">="
|
133
134
|
- !ruby/object:Gem::Version
|
134
|
-
version:
|
135
|
+
version: '0'
|
135
136
|
requirements: []
|
136
137
|
rubyforge_project:
|
137
138
|
rubygems_version: 2.5.2
|