fluent-plugin-http-pull 0.7.0 → 0.8.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 +4 -4
- data/.coveralls.yml +1 -1
- data/.gitignore +8 -8
- data/.travis.yml +10 -10
- data/Gemfile +3 -3
- data/LICENSE +202 -202
- data/README.md +227 -204
- data/Rakefile +24 -24
- data/appveyor.yml +23 -23
- data/fluent-plugin-http-pull.gemspec +33 -33
- data/lib/fluent/plugin/in_http_pull.rb +168 -147
- data/test/helper.rb +29 -29
- data/test/helper/.ssl/README +25 -0
- data/test/helper/.ssl/server.crt +19 -0
- data/test/helper/.ssl/server.csr +16 -0
- data/test/helper/.ssl/server.key +27 -0
- data/test/helper/.ssl/server.key.org +30 -0
- data/test/helper/stub_proxy.rb +39 -39
- data/test/helper/stub_server.rb +134 -119
- data/test/plugin/test_in_http_pull.rb +92 -71
- data/test/plugin/test_in_http_pull_auth.rb +116 -116
- data/test/plugin/test_in_http_pull_basic.rb +228 -227
- data/test/plugin/test_in_http_pull_http_header.rb +126 -126
- data/test/plugin/test_in_http_pull_proxy.rb +119 -119
- data/test/plugin/test_in_http_pull_request_method.rb +79 -79
- data/test/plugin/test_in_http_pull_ssl.rb +173 -0
- metadata +14 -2
data/appveyor.yml
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
version: '{build}'
|
2
|
-
|
3
|
-
install:
|
4
|
-
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
|
5
|
-
- "%devkit%\\devkitvars.bat"
|
6
|
-
- ruby --version
|
7
|
-
- gem --version
|
8
|
-
- bundle install
|
9
|
-
|
10
|
-
build: off
|
11
|
-
|
12
|
-
test_script:
|
13
|
-
- bundle exec rake test TESTOPTS=-v
|
14
|
-
|
15
|
-
branches:
|
16
|
-
only:
|
17
|
-
- master
|
18
|
-
|
19
|
-
# https://www.appveyor.com/docs/installed-software/#ruby
|
20
|
-
environment:
|
21
|
-
matrix:
|
22
|
-
- ruby_version: "23-x64"
|
23
|
-
devkit: C:\Ruby23-x64\DevKit
|
1
|
+
version: '{build}'
|
2
|
+
|
3
|
+
install:
|
4
|
+
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
|
5
|
+
- "%devkit%\\devkitvars.bat"
|
6
|
+
- ruby --version
|
7
|
+
- gem --version
|
8
|
+
- bundle install
|
9
|
+
|
10
|
+
build: off
|
11
|
+
|
12
|
+
test_script:
|
13
|
+
- bundle exec rake test TESTOPTS=-v
|
14
|
+
|
15
|
+
branches:
|
16
|
+
only:
|
17
|
+
- master
|
18
|
+
|
19
|
+
# https://www.appveyor.com/docs/installed-software/#ruby
|
20
|
+
environment:
|
21
|
+
matrix:
|
22
|
+
- ruby_version: "23-x64"
|
23
|
+
devkit: C:\Ruby23-x64\DevKit
|
@@ -1,33 +1,33 @@
|
|
1
|
-
lib = File.expand_path("../lib", __FILE__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
|
4
|
-
Gem::Specification.new do |spec|
|
5
|
-
spec.name = "fluent-plugin-http-pull"
|
6
|
-
spec.version = "0.
|
7
|
-
spec.authors = ["filepang"]
|
8
|
-
spec.email = ["filepang@gmail.com"]
|
9
|
-
|
10
|
-
spec.summary = %q{fluent-plugin-http-pull}
|
11
|
-
spec.description = %q{The input plugin of fluentd to pull log from rest api}
|
12
|
-
spec.homepage = "https://github.com/HatsuneMiku3939/fluent-plugin-http-pull"
|
13
|
-
spec.license = "Apache-2.0"
|
14
|
-
|
15
|
-
test_files, files = `git ls-files -z`.split("\x0").partition do |f|
|
16
|
-
f.match(%r{^(test|spec|features)/})
|
17
|
-
end
|
18
|
-
spec.files = files
|
19
|
-
spec.executables = files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
-
spec.test_files = test_files
|
21
|
-
spec.require_paths = ["lib"]
|
22
|
-
|
23
|
-
spec.required_ruby_version = '>= 2.1'
|
24
|
-
|
25
|
-
spec.add_development_dependency "rake", "~> 12.0"
|
26
|
-
spec.add_development_dependency "simplecov", "~> 0.7"
|
27
|
-
spec.add_development_dependency "test-unit", "~> 3.0"
|
28
|
-
spec.add_development_dependency "test-unit-rr", "~> 1.0", "~> 1.0.2"
|
29
|
-
spec.add_development_dependency "coveralls", "~> 0.7"
|
30
|
-
|
31
|
-
spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
|
32
|
-
spec.add_runtime_dependency "rest-client", [">= 2.0.0", "< 3"]
|
33
|
-
end
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "fluent-plugin-http-pull"
|
6
|
+
spec.version = "0.8.1"
|
7
|
+
spec.authors = ["filepang"]
|
8
|
+
spec.email = ["filepang@gmail.com"]
|
9
|
+
|
10
|
+
spec.summary = %q{fluent-plugin-http-pull}
|
11
|
+
spec.description = %q{The input plugin of fluentd to pull log from rest api}
|
12
|
+
spec.homepage = "https://github.com/HatsuneMiku3939/fluent-plugin-http-pull"
|
13
|
+
spec.license = "Apache-2.0"
|
14
|
+
|
15
|
+
test_files, files = `git ls-files -z`.split("\x0").partition do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.files = files
|
19
|
+
spec.executables = files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = test_files
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.required_ruby_version = '>= 2.1'
|
24
|
+
|
25
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
26
|
+
spec.add_development_dependency "simplecov", "~> 0.7"
|
27
|
+
spec.add_development_dependency "test-unit", "~> 3.0"
|
28
|
+
spec.add_development_dependency "test-unit-rr", "~> 1.0", "~> 1.0.2"
|
29
|
+
spec.add_development_dependency "coveralls", "~> 0.7"
|
30
|
+
|
31
|
+
spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
|
32
|
+
spec.add_runtime_dependency "rest-client", [">= 2.0.0", "< 3"]
|
33
|
+
end
|
@@ -1,147 +1,168 @@
|
|
1
|
-
#
|
2
|
-
# Copyright 2017- filepang
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
|
16
|
-
require "fluent/plugin/input"
|
17
|
-
require "rest-client"
|
18
|
-
|
19
|
-
module Fluent
|
20
|
-
module Plugin
|
21
|
-
class HttpPullInput < Fluent::Plugin::Input
|
22
|
-
Fluent::Plugin.register_input("http_pull", self)
|
23
|
-
helpers :timer, :parser, :compat_parameters
|
24
|
-
|
25
|
-
def initialize
|
26
|
-
super
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
desc '
|
57
|
-
config_param :
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
if
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
end
|
1
|
+
#
|
2
|
+
# Copyright 2017- filepang
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require "fluent/plugin/input"
|
17
|
+
require "rest-client"
|
18
|
+
|
19
|
+
module Fluent
|
20
|
+
module Plugin
|
21
|
+
class HttpPullInput < Fluent::Plugin::Input
|
22
|
+
Fluent::Plugin.register_input("http_pull", self)
|
23
|
+
helpers :timer, :parser, :compat_parameters
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
# basic options
|
30
|
+
desc 'The tag of the event.'
|
31
|
+
config_param :tag, :string
|
32
|
+
|
33
|
+
desc 'The url of monitoring target'
|
34
|
+
config_param :url, :string
|
35
|
+
|
36
|
+
desc 'The interval time between periodic request'
|
37
|
+
config_param :interval, :time
|
38
|
+
|
39
|
+
desc 'The user agent string of request'
|
40
|
+
config_param :agent, :string, default: "fluent-plugin-http-pull"
|
41
|
+
|
42
|
+
desc 'status_only'
|
43
|
+
config_param :status_only, :bool, default: false
|
44
|
+
|
45
|
+
desc 'The http method for each request'
|
46
|
+
config_param :http_method, :enum, list: [:get, :post, :delete], default: :get
|
47
|
+
|
48
|
+
desc 'The timeout second of each request'
|
49
|
+
config_param :timeout, :time, default: 10
|
50
|
+
|
51
|
+
# proxy options
|
52
|
+
desc 'The HTTP proxy URL to use for each requests'
|
53
|
+
config_param :proxy, :string, default: nil
|
54
|
+
|
55
|
+
# basic auth options
|
56
|
+
desc 'user of basic auth'
|
57
|
+
config_param :user, :string, default: nil
|
58
|
+
|
59
|
+
desc 'password of basic auth'
|
60
|
+
config_param :password, :string, default: nil
|
61
|
+
|
62
|
+
# req/res header options
|
63
|
+
config_section :response_header, param_name: :response_headers, multi: true do
|
64
|
+
desc 'The name of header to cature from response'
|
65
|
+
config_param :header, :string
|
66
|
+
end
|
67
|
+
|
68
|
+
config_section :request_header, param_name: :request_headers, multi: true do
|
69
|
+
desc 'The name of request header'
|
70
|
+
config_param :header, :string
|
71
|
+
|
72
|
+
desc 'The value of request header'
|
73
|
+
config_param :value, :string
|
74
|
+
end
|
75
|
+
|
76
|
+
# ssl options
|
77
|
+
desc 'verify_ssl'
|
78
|
+
config_param :verify_ssl, :bool, default: true
|
79
|
+
|
80
|
+
desc "The absolute path of directory where ca_file stored"
|
81
|
+
config_param :ca_path, :string, default: nil
|
82
|
+
|
83
|
+
desc "The absolute path of ca_file"
|
84
|
+
config_param :ca_file, :string, default: nil
|
85
|
+
|
86
|
+
|
87
|
+
def configure(conf)
|
88
|
+
compat_parameters_convert(conf, :parser)
|
89
|
+
super
|
90
|
+
|
91
|
+
@parser = parser_create unless @status_only
|
92
|
+
@_request_headers = {
|
93
|
+
"Content-Type" => "application/x-www-form-urlencoded",
|
94
|
+
"User-Agent" => @agent
|
95
|
+
}.merge(@request_headers.map do |section|
|
96
|
+
header = section["header"]
|
97
|
+
value = section["value"]
|
98
|
+
|
99
|
+
[header.to_sym, value]
|
100
|
+
end.to_h)
|
101
|
+
|
102
|
+
@http_method = :head if @status_only
|
103
|
+
end
|
104
|
+
|
105
|
+
def start
|
106
|
+
super
|
107
|
+
|
108
|
+
timer_execute(:in_http_pull, @interval, &method(:on_timer))
|
109
|
+
end
|
110
|
+
|
111
|
+
def on_timer
|
112
|
+
record = { "url" => @url }
|
113
|
+
|
114
|
+
begin
|
115
|
+
request_options = { method: @http_method, url: @url, timeout: @timeout, headers: @_request_headers }
|
116
|
+
|
117
|
+
request_options[:proxy] = @proxy if @proxy
|
118
|
+
request_options[:user] = @user if @user
|
119
|
+
request_options[:password] = @password if @password
|
120
|
+
|
121
|
+
request_options[:verify_ssl] = @verify_ssl
|
122
|
+
if @verify_ssl and @ca_path and @ca_file
|
123
|
+
request_options[:ssl_ca_path] = @ca_path
|
124
|
+
request_options[:ssl_ca_file] = @ca_file
|
125
|
+
end
|
126
|
+
|
127
|
+
res = RestClient::Request.execute request_options
|
128
|
+
|
129
|
+
record["status"] = res.code
|
130
|
+
record["body"] = res.body
|
131
|
+
|
132
|
+
record["header"] = {} unless @response_headers.empty?
|
133
|
+
@response_headers.each do |section|
|
134
|
+
name = section["header"]
|
135
|
+
symbolize_name = name.downcase.gsub(/-/, '_').to_sym
|
136
|
+
|
137
|
+
record["header"][name] = res.headers[symbolize_name]
|
138
|
+
end
|
139
|
+
rescue StandardError => err
|
140
|
+
if err.respond_to? :http_code
|
141
|
+
record["status"] = err.http_code || 0
|
142
|
+
else
|
143
|
+
record["status"] = 0
|
144
|
+
end
|
145
|
+
|
146
|
+
record["error"] = err.message
|
147
|
+
end
|
148
|
+
|
149
|
+
record_time = Engine.now
|
150
|
+
|
151
|
+
if !@status_only && record["body"] != nil
|
152
|
+
@parser.parse(record["body"]) do |time, message|
|
153
|
+
record["message"] = message
|
154
|
+
record_time = time
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
record.delete("body")
|
159
|
+
router.emit(@tag, record_time, record)
|
160
|
+
end
|
161
|
+
|
162
|
+
def shutdown
|
163
|
+
super
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
data/test/helper.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
# simplecov must be loaded before any of target code
|
2
|
-
require 'simplecov'
|
3
|
-
require 'coveralls'
|
4
|
-
Coveralls.wear!
|
5
|
-
|
6
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
7
|
-
SimpleCov::Formatter::HTMLFormatter,
|
8
|
-
Coveralls::SimpleCov::Formatter
|
9
|
-
])
|
10
|
-
|
11
|
-
SimpleCov.start do
|
12
|
-
add_filter '/test/'
|
13
|
-
end
|
14
|
-
|
15
|
-
# load our target code
|
16
|
-
$LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
|
17
|
-
require "test-unit"
|
18
|
-
require "fluent/test"
|
19
|
-
require "fluent/test/driver/input"
|
20
|
-
require "fluent/test/helpers"
|
21
|
-
|
22
|
-
require "test/unit/rr"
|
23
|
-
|
24
|
-
# require stub_server
|
25
|
-
require "test/helper/stub_server"
|
26
|
-
require "test/helper/stub_proxy"
|
27
|
-
|
28
|
-
Test::Unit::TestCase.include(Fluent::Test::Helpers)
|
29
|
-
Test::Unit::TestCase.extend(Fluent::Test::Helpers)
|
1
|
+
# simplecov must be loaded before any of target code
|
2
|
+
require 'simplecov'
|
3
|
+
require 'coveralls'
|
4
|
+
Coveralls.wear!
|
5
|
+
|
6
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
7
|
+
SimpleCov::Formatter::HTMLFormatter,
|
8
|
+
Coveralls::SimpleCov::Formatter
|
9
|
+
])
|
10
|
+
|
11
|
+
SimpleCov.start do
|
12
|
+
add_filter '/test/'
|
13
|
+
end
|
14
|
+
|
15
|
+
# load our target code
|
16
|
+
$LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
|
17
|
+
require "test-unit"
|
18
|
+
require "fluent/test"
|
19
|
+
require "fluent/test/driver/input"
|
20
|
+
require "fluent/test/helpers"
|
21
|
+
|
22
|
+
require "test/unit/rr"
|
23
|
+
|
24
|
+
# require stub_server
|
25
|
+
require "test/helper/stub_server"
|
26
|
+
require "test/helper/stub_proxy"
|
27
|
+
|
28
|
+
Test::Unit::TestCase.include(Fluent::Test::Helpers)
|
29
|
+
Test::Unit::TestCase.extend(Fluent::Test::Helpers)
|