fluent-plugin-http-pull 0.7.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.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
- desc 'The tag of the event.'
30
- config_param :tag, :string
31
-
32
- desc 'The url of monitoring target'
33
- config_param :url, :string
34
-
35
- desc 'The interval time between periodic request'
36
- config_param :interval, :time
37
-
38
- desc 'The user agent string of request'
39
- config_param :agent, :string, default: "fluent-plugin-http-pull"
40
-
41
- desc 'status_only'
42
- config_param :status_only, :bool, default: false
43
-
44
- desc 'The http method for each request'
45
- config_param :http_method, :enum, list: [:get, :post, :delete], default: :get
46
-
47
- desc 'The timeout second of each request'
48
- config_param :timeout, :time, default: 10
49
-
50
- desc 'The HTTP proxy URL to use for each requests'
51
- config_param :proxy, :string, default: nil
52
-
53
- desc 'user of basic auth'
54
- config_param :user, :string, default: nil
55
-
56
- desc 'password of basic auth'
57
- config_param :password, :string, default: nil
58
-
59
- config_section :response_header, param_name: :response_headers, multi: true do
60
- desc 'The name of header to cature from response'
61
- config_param :header, :string
62
- end
63
-
64
- config_section :request_header, param_name: :request_headers, multi: true do
65
- desc 'The name of request header'
66
- config_param :header, :string
67
-
68
- desc 'The value of request header'
69
- config_param :value, :string
70
- end
71
-
72
- def configure(conf)
73
- compat_parameters_convert(conf, :parser)
74
- super
75
-
76
- @parser = parser_create unless @status_only
77
- @_request_headers = {
78
- "Content-Type" => "application/x-www-form-urlencoded",
79
- "User-Agent" => @agent
80
- }.merge(@request_headers.map do |section|
81
- header = section["header"]
82
- value = section["value"]
83
-
84
- [header.to_sym, value]
85
- end.to_h)
86
-
87
- @http_method = :head if @status_only
88
- end
89
-
90
- def start
91
- super
92
-
93
- timer_execute(:in_http_pull, @interval, &method(:on_timer))
94
- end
95
-
96
- def on_timer
97
- record = { "url" => @url }
98
-
99
- begin
100
- request_options = { method: @http_method, url: @url, timeout: @timeout, headers: @_request_headers }
101
-
102
- request_options[:proxy] = @proxy if @proxy
103
- request_options[:user] = @user if @user
104
- request_options[:password] = @password if @password
105
-
106
- res = RestClient::Request.execute request_options
107
-
108
- record["status"] = res.code
109
- record["body"] = res.body
110
-
111
- record["header"] = {} unless @response_headers.empty?
112
- @response_headers.each do |section|
113
- name = section["header"]
114
- symbolize_name = name.downcase.gsub(/-/, '_').to_sym
115
-
116
- record["header"][name] = res.headers[symbolize_name]
117
- end
118
- rescue StandardError => err
119
- if err.respond_to? :http_code
120
- record["status"] = err.http_code || 0
121
- else
122
- record["status"] = 0
123
- end
124
-
125
- record["error"] = err.message
126
- end
127
-
128
- record_time = Engine.now
129
-
130
- if !@status_only && record["body"] != nil
131
- @parser.parse(record["body"]) do |time, message|
132
- record["message"] = message
133
- record_time = time
134
- end
135
- end
136
-
137
- record.delete("body")
138
- router.emit(@tag, record_time, record)
139
- end
140
-
141
- def shutdown
142
- super
143
- end
144
-
145
- end
146
- end
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
@@ -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)