fluent-plugin-http-pull 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -1
- data/fluent-plugin-http-pull.gemspec +1 -1
- data/lib/fluent/plugin/in_http_pull.rb +13 -3
- data/test/helper/stub_server.rb +26 -0
- data/test/plugin/test_in_http_pull.rb +63 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4431d08247cac9ded691561df1f37e0ca301812c
|
4
|
+
data.tar.gz: 34533a363fe85ac8a9e8fe6f7732d25cebe0ea43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ab0a2aad719fb68cda02595b9b7df31c5d8f611534898aee88323c325358ba0915c7937deff0b317ca51ebea4d3fa535ebc929f08d8783cb4932022d514c55c
|
7
|
+
data.tar.gz: c8ed089e7978a0ae4dc7dea11ac71e5b5b819def2d2136cc9e43f1111c4ddf8cf5d694ebc0b2d9f22707bcecbf2b53677670794153f509bd59c8e19ee84b1d51
|
data/README.md
CHANGED
@@ -34,6 +34,8 @@ $ bundle
|
|
34
34
|
|
35
35
|
## Example
|
36
36
|
|
37
|
+
You can found more examples in `test/plugin/test_in_http_pull.rb`
|
38
|
+
|
37
39
|
### Monitoring http status code only
|
38
40
|
```
|
39
41
|
<source>
|
@@ -133,7 +135,17 @@ for more detail.
|
|
133
135
|
|
134
136
|
### status_only (bool) (optional, default: false)
|
135
137
|
|
136
|
-
If status_only is true, body is not parsed.
|
138
|
+
If `status_only` is true, body is not parsed.
|
139
|
+
|
140
|
+
### http_method (enum) (optional, default: :get)
|
141
|
+
|
142
|
+
The http request method for each requests. Avaliable options are listed below.
|
143
|
+
|
144
|
+
* `get`
|
145
|
+
* `post`
|
146
|
+
* `delete`
|
147
|
+
|
148
|
+
If `status_only` is true, `http_method` was override to `head`
|
137
149
|
|
138
150
|
### timeout (time) (optional, default: 10s)
|
139
151
|
|
@@ -151,6 +163,14 @@ The user for basic auth
|
|
151
163
|
|
152
164
|
The password for basic auth
|
153
165
|
|
166
|
+
### response_header (section) (optional, default: nil)
|
167
|
+
|
168
|
+
The name of response header for capture.
|
169
|
+
|
170
|
+
### request_header (section) (optional, default: nil)
|
171
|
+
|
172
|
+
The name, value pair of custom reuqest header.
|
173
|
+
|
154
174
|
## In case of remote error
|
155
175
|
|
156
176
|
### Can receive response from remote
|
@@ -20,7 +20,6 @@ module Fluent
|
|
20
20
|
module Plugin
|
21
21
|
class HttpPullInput < Fluent::Plugin::Input
|
22
22
|
Fluent::Plugin.register_input("http_pull", self)
|
23
|
-
|
24
23
|
helpers :timer, :parser, :compat_parameters
|
25
24
|
|
26
25
|
def initialize
|
@@ -29,19 +28,28 @@ module Fluent
|
|
29
28
|
|
30
29
|
desc 'The tag of the event.'
|
31
30
|
config_param :tag, :string
|
31
|
+
|
32
32
|
desc 'The url of monitoring target'
|
33
33
|
config_param :url, :string
|
34
|
+
|
34
35
|
desc 'The interval time between periodic request'
|
35
36
|
config_param :interval, :time
|
37
|
+
|
36
38
|
desc 'status_only'
|
37
39
|
config_param :status_only, :bool, default: false
|
38
|
-
|
40
|
+
|
41
|
+
desc 'The http method for each request'
|
42
|
+
config_param :http_method, :enum, list: [:get, :post, :delete], default: :get
|
43
|
+
|
44
|
+
desc 'The timeout second of each request'
|
39
45
|
config_param :timeout, :time, default: 10
|
46
|
+
|
40
47
|
desc 'The HTTP proxy URL to use for each requests'
|
41
48
|
config_param :proxy, :string, default: nil
|
42
49
|
|
43
50
|
desc 'user of basic auth'
|
44
51
|
config_param :user, :string, default: nil
|
52
|
+
|
45
53
|
desc 'password of basic auth'
|
46
54
|
config_param :password, :string, default: nil
|
47
55
|
|
@@ -69,6 +77,8 @@ module Fluent
|
|
69
77
|
|
70
78
|
[header.to_sym, value]
|
71
79
|
end.to_h
|
80
|
+
|
81
|
+
@http_method = :head if @status_only
|
72
82
|
end
|
73
83
|
|
74
84
|
def start
|
@@ -81,7 +91,7 @@ module Fluent
|
|
81
91
|
record = { "url" => @url }
|
82
92
|
|
83
93
|
begin
|
84
|
-
request_options = { method:
|
94
|
+
request_options = { method: @http_method, url: @url, timeout: @timeout }
|
85
95
|
|
86
96
|
request_options[:proxy] = @proxy if @proxy
|
87
97
|
request_options[:user] = @user if @user
|
data/test/helper/stub_server.rb
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
require 'webrick'
|
2
2
|
|
3
|
+
class DeleteService < WEBrick::HTTPServlet::AbstractServlet
|
4
|
+
def service(req, res)
|
5
|
+
if req.request_method != "DELETE"
|
6
|
+
res.status = 405
|
7
|
+
else
|
8
|
+
res.status = 200
|
9
|
+
res['Content-Type'] = 'application/json'
|
10
|
+
res.body = '{ "status": "OK" }'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
3
15
|
class StubServer
|
4
16
|
def initialize
|
5
17
|
create_server
|
@@ -12,6 +24,9 @@ class StubServer
|
|
12
24
|
@server.mount_proc '/redirect', &method(:redirect)
|
13
25
|
@server.mount_proc '/protected', &method(:protected)
|
14
26
|
@server.mount_proc '/custom_header', &method(:custom_header)
|
27
|
+
|
28
|
+
@server.mount_proc '/method_post', &method(:method_post)
|
29
|
+
@server.mount '/method_delete', DeleteService
|
15
30
|
end
|
16
31
|
|
17
32
|
def start
|
@@ -90,4 +105,15 @@ class StubServer
|
|
90
105
|
res['Content-Type'] = 'application/json'
|
91
106
|
res.body = '{ "status": "OK" }'
|
92
107
|
end
|
108
|
+
|
109
|
+
def method_post(req, res)
|
110
|
+
if req.request_method != "POST"
|
111
|
+
res.status = 405
|
112
|
+
else
|
113
|
+
res.status = 200
|
114
|
+
res['Content-Type'] = 'application/json'
|
115
|
+
res.body = '{ "status": "OK" }'
|
116
|
+
end
|
117
|
+
end
|
93
118
|
end
|
119
|
+
|
@@ -58,6 +58,13 @@ class HttpPullInputTest < Test::Unit::TestCase
|
|
58
58
|
|
59
59
|
assert_equal(nil, d.instance.proxy)
|
60
60
|
end
|
61
|
+
|
62
|
+
test 'http_method' do
|
63
|
+
d = create_driver TEST_DEFAULT_VALUE_CONFIG
|
64
|
+
assert_equal("test", d.instance.tag)
|
65
|
+
|
66
|
+
assert_equal(:get, d.instance.http_method)
|
67
|
+
end
|
61
68
|
end
|
62
69
|
|
63
70
|
sub_test_case "success case" do
|
@@ -556,6 +563,62 @@ class HttpPullInputTest < Test::Unit::TestCase
|
|
556
563
|
end
|
557
564
|
end
|
558
565
|
|
566
|
+
sub_test_case "request method" do
|
567
|
+
TEST_INTERVAL_3_POST = %[
|
568
|
+
tag test
|
569
|
+
url http://127.0.0.1:3939/method_post
|
570
|
+
|
571
|
+
interval 3s
|
572
|
+
format json
|
573
|
+
http_method post
|
574
|
+
]
|
575
|
+
|
576
|
+
TEST_INTERVAL_3_DELETE = %[
|
577
|
+
tag test
|
578
|
+
url http://127.0.0.1:3939/method_delete
|
579
|
+
|
580
|
+
interval 3s
|
581
|
+
format json
|
582
|
+
http_method delete
|
583
|
+
]
|
584
|
+
|
585
|
+
test 'interval 3 with :post' do
|
586
|
+
d = create_driver TEST_INTERVAL_3_POST
|
587
|
+
assert_equal("test", d.instance.tag)
|
588
|
+
assert_equal(3, d.instance.interval)
|
589
|
+
|
590
|
+
d.run(timeout: 8) do
|
591
|
+
sleep 7
|
592
|
+
end
|
593
|
+
assert_equal(2, d.events.size)
|
594
|
+
|
595
|
+
d.events.each do |tag, time, record|
|
596
|
+
assert_equal("test", tag)
|
597
|
+
|
598
|
+
assert_equal({"url"=>"http://127.0.0.1:3939/method_post","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
599
|
+
assert(time.is_a?(Fluent::EventTime))
|
600
|
+
end
|
601
|
+
end
|
602
|
+
|
603
|
+
test 'interval 3 with :delete' do
|
604
|
+
d = create_driver TEST_INTERVAL_3_DELETE
|
605
|
+
assert_equal("test", d.instance.tag)
|
606
|
+
assert_equal(3, d.instance.interval)
|
607
|
+
|
608
|
+
d.run(timeout: 8) do
|
609
|
+
sleep 7
|
610
|
+
end
|
611
|
+
assert_equal(2, d.events.size)
|
612
|
+
|
613
|
+
d.events.each do |tag, time, record|
|
614
|
+
assert_equal("test", tag)
|
615
|
+
|
616
|
+
assert_equal({"url"=>"http://127.0.0.1:3939/method_delete","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
617
|
+
assert(time.is_a?(Fluent::EventTime))
|
618
|
+
end
|
619
|
+
end
|
620
|
+
end
|
621
|
+
|
559
622
|
private
|
560
623
|
|
561
624
|
def create_driver(conf)
|
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.
|
4
|
+
version: 0.6.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-
|
11
|
+
date: 2017-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
167
|
version: '0'
|
168
168
|
requirements: []
|
169
169
|
rubyforge_project:
|
170
|
-
rubygems_version: 2.
|
170
|
+
rubygems_version: 2.5.2
|
171
171
|
signing_key:
|
172
172
|
specification_version: 4
|
173
173
|
summary: fluent-plugin-http-pull
|