Class: SolidEvents::Notifiers::SlackWebhookNotifier
- Inherits:
-
Object
- Object
- SolidEvents::Notifiers::SlackWebhookNotifier
- Defined in:
- lib/solid_events/notifiers/slack_webhook_notifier.rb
Instance Method Summary collapse
- #call(incident:, action:) ⇒ Object
-
#initialize(webhook_url:, channel: nil, username: "solid_events") ⇒ SlackWebhookNotifier
constructor
A new instance of SlackWebhookNotifier.
Constructor Details
#initialize(webhook_url:, channel: nil, username: "solid_events") ⇒ SlackWebhookNotifier
Returns a new instance of SlackWebhookNotifier.
9 10 11 12 13 |
# File 'lib/solid_events/notifiers/slack_webhook_notifier.rb', line 9 def initialize(webhook_url:, channel: nil, username: "solid_events") @webhook_uri = URI.parse(webhook_url) @channel = channel @username = username end |
Instance Method Details
#call(incident:, action:) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/solid_events/notifiers/slack_webhook_notifier.rb', line 15 def call(incident:, action:) = { username: @username, channel: @channel, text: "[solid_events] #{action.to_s.upcase} #{incident.kind} #{incident.severity} #{incident.source} #{incident.name}" }.compact request = Net::HTTP::Post.new(@webhook_uri) request["Content-Type"] = "application/json" request.body = JSON.generate() http = Net::HTTP.new(@webhook_uri.host, @webhook_uri.port) http.use_ssl = @webhook_uri.scheme == "https" http.read_timeout = 2 http.open_timeout = 2 http.request(request) rescue StandardError nil end |