sensu-plugins-slack 4.0.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45b457dae81022f3260abe503cef2919e2703112061173b097f60cbec5828313
4
- data.tar.gz: 02c17b9e8b9349b5e284e338599dc690f1a314d9149935718a94ab21985f04a0
3
+ metadata.gz: fbc28b57823791c32fb8d544c1dcffd13bb6f34378de1a3076ffe01bcd99ed4c
4
+ data.tar.gz: 17adcc1cbcc70332b177a4e0b954e8f9f12a6e089ddbb57151a1444e06f4ae4e
5
5
  SHA512:
6
- metadata.gz: 1f2a8f97b6870cbf4c9e9c0c9ae36c0401888406db29c89ff9f5ab7bee082cdd0be67027ae17312e889806f6015dde11aaf7c5ac81f62a01d7449a7d4092c963
7
- data.tar.gz: 8be3d636a03ab8eb64b6e3da44850c873dbeda9219c0e3a044e0bce6b17b32f9c021360d482a9bfac4819e723abaaa006893baf1a452a5fb2521a85f8be08924
6
+ metadata.gz: 726ad96b3ab0602eb51f1969047c93f1e8a1eed9e6ef7060be5ea12edfdf54a3074955d451838d3c8055bcae5aa383867ac757ebbf09bd58764edeb7f1c832a1
7
+ data.tar.gz: b80b09535f11cc5526f6204a4b63e85ff0a14d54f0c4ce0a1d8a1a1abceb61c693f57b4cead2fd226e411f4703ca68497b4c25aa39fdd48b2c9a0e3706be59ec
@@ -5,6 +5,10 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [4.1.0]- 2019-05-16
9
+ ### Added
10
+ - `handler-slack`: added `webhook_retries` (default: 5), `webhook_timeout` (default: 10), and `webhook_retry_sleep` configuration properties to harden against failures due to networking, rate limits, etc. (@kali-brandwatch)
11
+
8
12
  ## [4.0.0] - 2019-04-02
9
13
  ### Breaking Changes
10
14
  - Bump sensu-plugin version from `~> 2.0` to `~> 4.0` for Sensu 1.x to Sensu Go event conversion you can read the changelog entries for [4.0](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#400---2018-02-17) and [3.0](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#300---2018-12-04)
@@ -134,7 +138,8 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
134
138
  ### Added
135
139
  - initial release
136
140
 
137
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-slack/compare/4.0.0...HEAD
141
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-slack/compare/4.1.0...HEAD
142
+ [4.1.0]: https://github.com/sensu-plugins/sensu-plugins-slack/compare/4.0.0..4.1.0
138
143
  [4.0.0]: https://github.com/sensu-plugins/sensu-plugins-slack/compare/3.1.1...4.0.0
139
144
  [3.1.1]: https://github.com/sensu-plugins/sensu-plugins-slack/compare/3.1.0...3.1.1
140
145
  [3.1.0]: https://github.com/sensu-plugins/sensu-plugins-slack/compare/3.0.0...3.1.0
@@ -30,6 +30,21 @@ class Slack < Sensu::Handler
30
30
  get_setting('webhook_url')
31
31
  end
32
32
 
33
+ def slack_webhook_retries
34
+ # The number of retries to deliver the payload to the slack webhook
35
+ get_setting('webhook_retries') || 5
36
+ end
37
+
38
+ def slack_webhook_timeout
39
+ # The amount of time (in seconds) to give for the webhook request to complete before failing it
40
+ get_setting('webhook_timeout') || 10
41
+ end
42
+
43
+ def slack_webhook_retry_sleep
44
+ # The amount of time (in seconds) to wait in between webhook retries
45
+ get_setting('webhook_retry_sleep') || 5
46
+ end
47
+
33
48
  def slack_icon_emoji
34
49
  get_setting('icon_emoji')
35
50
  end
@@ -149,27 +164,47 @@ class Slack < Sensu::Handler
149
164
  end
150
165
  http.use_ssl = true
151
166
 
152
- req = Net::HTTP::Post.new("#{uri.path}?#{uri.query}", 'Content-Type' => 'application/json')
153
-
154
- if payload_template.nil?
155
- text = slack_surround ? slack_surround + body + slack_surround : body
156
- req.body = payload(text).to_json
157
- else
158
- req.body = body
159
- end
160
-
161
- response = http.request(req)
162
- verify_response(response)
163
- end
164
-
165
- def verify_response(response)
166
- case response
167
- when Net::HTTPSuccess
168
- true
169
- else
170
- raise response.error!
171
- end
172
- end
167
+ # Implement a retry-timeout strategy to handle slack api issues like network. Should solve #15
168
+ begin # retries loop
169
+ tries = slack_webhook_retries
170
+ Timeout.timeout(slack_webhook_timeout) do
171
+ begin # main loop for trying to deliver the message to slack webhook
172
+ req = Net::HTTP::Post.new("#{uri.path}?#{uri.query}", 'Content-Type' => 'application/json')
173
+
174
+ if payload_template.nil?
175
+ text = slack_surround ? slack_surround + body + slack_surround : body
176
+ req.body = payload(text).to_json
177
+ else
178
+ req.body = body
179
+ end
180
+
181
+ http.request(req)
182
+
183
+ # replace verify_response with a rescue within the loop
184
+ rescue Net::HTTPServerException => error
185
+ if (tries -= 1) > 0
186
+ sleep slack_webhook_retry_sleep
187
+ puts "retrying incident #{incident_key}... #{tries} left"
188
+ retry
189
+ else
190
+ # raise error for sensu-server to catch and log
191
+ puts "slack api failed (retries) #{incident_key}: #{error.response.code} #{error.response.message}: channel '#{slack_channel}', message: #{body}"
192
+ exit 1
193
+ end
194
+ end # of main loop for trying to deliver the message to slack webhook
195
+ end # of timeout:do loop
196
+ # if the timeout is exceeded, consider this try failed
197
+ rescue Timeout::Error
198
+ if (tries -= 1) > 0
199
+ puts "timeout hit, retrying... #{tries} left"
200
+ retry
201
+ else
202
+ # raise error for sensu-server to catch and log
203
+ puts "slack webhook failed (timeout) #{incident_key}: channel '#{slack_channel}', message: #{body}"
204
+ exit 1
205
+ end
206
+ end # of retries loop
207
+ end # of post_data
173
208
 
174
209
  def payload(notice)
175
210
  client_fields = []
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsSlack
2
2
  module Version
3
3
  MAJOR = 4
4
- MINOR = 0
4
+ MINOR = 1
5
5
  PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-slack
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-03 00:00:00.000000000 Z
11
+ date: 2019-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis