sensu-plugin 2.4.0 → 2.5.0
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/lib/sensu-handler.rb +15 -4
- data/lib/sensu-plugin.rb +1 -1
- data/test/handle_api_request_test.rb +29 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 789c3f9cdd93f38450e3c7fa33a076570d17c3ba
|
4
|
+
data.tar.gz: e1e46b0ec50069844d69e447bfb5546928bdc887
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14d1e113b578a0690fcf0fd6f2512d8a2b146366e6c3e39b4fee4af11a024c66c4c4aa9312bcdc9bf0b10f50e020fcfebfddecd7a0dd3feb8aca64678ec1c368
|
7
|
+
data.tar.gz: 161a7ace2d9a55d2f47c0724e1fc3a9a3d66ac919763fac2a9f9bb453166487c9956d54621ede9c483d78fe51d1ac74f06db8b72384a31c762d71c2830ffaefc
|
data/lib/sensu-handler.rb
CHANGED
@@ -99,6 +99,14 @@ module Sensu
|
|
99
99
|
exit 0
|
100
100
|
end
|
101
101
|
|
102
|
+
# Override API settings (for testing purposes)
|
103
|
+
#
|
104
|
+
# @param api_settings [Hash]
|
105
|
+
# @return [Hash]
|
106
|
+
def api_settings=(api_settings)
|
107
|
+
@api_settings = api_settings
|
108
|
+
end
|
109
|
+
|
102
110
|
# Return a hash of API settings derived first from ENV['SENSU_API_URL'] if set,
|
103
111
|
# then Sensu config `api` scope if configured, and finally falling back to
|
104
112
|
# to ipv4 localhost address on default API port.
|
@@ -108,7 +116,9 @@ module Sensu
|
|
108
116
|
return @api_settings if @api_settings
|
109
117
|
if ENV['SENSU_API_URL']
|
110
118
|
uri = URI(ENV['SENSU_API_URL'])
|
119
|
+
ssl = uri.scheme == 'https' ? {} : nil
|
111
120
|
@api_settings = {
|
121
|
+
'ssl' => ssl,
|
112
122
|
'host' => uri.host,
|
113
123
|
'port' => uri.port,
|
114
124
|
'user' => uri.user,
|
@@ -126,14 +136,15 @@ module Sensu
|
|
126
136
|
if api_settings.nil?
|
127
137
|
raise 'api.json settings not found.'
|
128
138
|
end
|
129
|
-
|
130
|
-
|
131
|
-
|
139
|
+
use_ssl = api_settings['ssl'].is_a?(Hash) ||
|
140
|
+
api_settings['host'].start_with?('https')
|
141
|
+
hostname = api_settings['host'].gsub(/https?:\/\//, '')
|
142
|
+
req = net_http_req_class(method).new(path)
|
132
143
|
if api_settings['user'] && api_settings['password']
|
133
144
|
req.basic_auth(api_settings['user'], api_settings['password'])
|
134
145
|
end
|
135
146
|
yield(req) if block_given?
|
136
|
-
res = Net::HTTP.start(
|
147
|
+
res = Net::HTTP.start(hostname, api_settings['port'], use_ssl: use_ssl) do |http|
|
137
148
|
http.request(req)
|
138
149
|
end
|
139
150
|
res
|
data/lib/sensu-plugin.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'webmock/minitest'
|
3
|
+
require 'sensu-handler'
|
4
|
+
|
5
|
+
class TestHandleAPIRequest < MiniTest::Test
|
6
|
+
include SensuPluginTestHelper
|
7
|
+
|
8
|
+
Sensu::Handler.disable_autorun
|
9
|
+
|
10
|
+
def test_http_request
|
11
|
+
stub_request(:get, 'http://127.0.0.1:4567/foo').to_return(status: 200, body: '', headers: {})
|
12
|
+
|
13
|
+
handler = Sensu::Handler.new([])
|
14
|
+
response = handler.api_request(:get, '/foo')
|
15
|
+
|
16
|
+
assert_equal(response.code, '200')
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_https_request
|
20
|
+
stub_request(:get, 'https://127.0.0.1:4567/foo').to_return(status: 200, body: '', headers: {})
|
21
|
+
|
22
|
+
handler = Sensu::Handler.new([])
|
23
|
+
handler.api_settings = handler.api_settings.merge('ssl' => {})
|
24
|
+
|
25
|
+
response = handler.api_request(:get, '/foo')
|
26
|
+
|
27
|
+
assert_equal(response.code, '200')
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Decklin Foster
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-04-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -81,6 +81,20 @@ dependencies:
|
|
81
81
|
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: webmock
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
84
98
|
description: Plugins and helper libraries for Sensu, a monitoring framework
|
85
99
|
email:
|
86
100
|
- decklin@red-bean.com
|
@@ -102,6 +116,7 @@ files:
|
|
102
116
|
- test/external_handler_argument_test.rb
|
103
117
|
- test/external_handler_test.rb
|
104
118
|
- test/external_metric_test.rb
|
119
|
+
- test/handle_api_request_test.rb
|
105
120
|
- test/handle_filter_test.rb
|
106
121
|
- test/handle_helper_test.rb
|
107
122
|
- test/mutator_test.rb
|
@@ -131,6 +146,7 @@ signing_key:
|
|
131
146
|
specification_version: 4
|
132
147
|
summary: Sensu Plugins
|
133
148
|
test_files:
|
149
|
+
- test/handle_api_request_test.rb
|
134
150
|
- test/handle_helper_test.rb
|
135
151
|
- test/external_handler_test.rb
|
136
152
|
- test/external_metric_test.rb
|