Class: Ask::Monitoring::Channels::Slack
- Defined in:
- lib/ask/monitoring/channels/slack.rb
Overview
Slack alert channel.
Delivers alerts via Slack Incoming Webhooks.
Instance Method Summary collapse
-
#deliver(alert) ⇒ Boolean
Deliver an alert to Slack.
-
#initialize(webhook_url:) ⇒ Slack
constructor
A new instance of Slack.
Constructor Details
#initialize(webhook_url:) ⇒ Slack
Returns a new instance of Slack.
13 14 15 |
# File 'lib/ask/monitoring/channels/slack.rb', line 13 def initialize(webhook_url:) @webhook_url = webhook_url end |
Instance Method Details
#deliver(alert) ⇒ Boolean
Deliver an alert to Slack.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ask/monitoring/channels/slack.rb', line 21 def deliver(alert) require "net/http" require "uri" require "json" uri = URI.parse(@webhook_url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == "https" payload = { text: format_alert(alert), mrkdwn: true } request = Net::HTTP::Post.new(uri.request_uri, "Content-Type" => "application/json") request.body = JSON.generate(payload) response = http.request(request) response.code.to_i == 200 end |