Skip to content

Commit

Permalink
Fix rubocop complains
Browse files Browse the repository at this point in the history
  • Loading branch information
kali-brandwatch authored and majormoses committed May 17, 2019
1 parent 0885d27 commit ed63d05
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions bin/handler-slack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ def post_data(body)
begin # retries loop
tries = slack_webhook_retries
Timeout.timeout(slack_webhook_timeout) do

begin # main loop for trying to deliver the message to slack webhook
req = Net::HTTP::Post.new("#{uri.path}?#{uri.query}", 'Content-Type' => 'application/json')

Expand All @@ -179,7 +178,7 @@ def post_data(body)
req.body = body
end

response = http.request(req)
http.request(req)

# replace verify_response with a rescue within the loop
rescue Net::HTTPServerException => error
Expand All @@ -189,21 +188,19 @@ def post_data(body)
retry
else
# raise error for sensu-server to catch and log
puts 'slack api failed (retries) ' + incident_key + ' : ' + error.response.code + ' ' + error.response.message + ': sending to channel "' + slack_channel + '" the message: ' + body
puts "slack api failed (retries) #{incident_key}: #{error.response.code} #{error.response.message}: channel '#{slack_channel}', message: #{body}"
exit 1
end
end # of main loop for trying to deliver the message to slack webhook

end # of timeout:do loop

# if the timeout is exceeded, consider this try failed
rescue Timeout::Error
if (tries -= 1) > 0
puts "timeout hit, retrying... #{tries} left"
retry
else
# raise error for sensu-server to catch and log
puts 'slack webhook failed (timeout) ' + incident_key + ' : sending to channel "' + slack_channel + '" the message: ' + body
puts "slack webhook failed (timeout) #{incident_key}: channel '#{slack_channel}', message: #{body}"
exit 1
end
end # of retries loop
Expand Down

0 comments on commit ed63d05

Please sign in to comment.