Class: DataChecks::Notifiers::SlackNotifier
- Defined in:
- lib/data_checks/notifiers/slack_notifier.rb
Instance Attribute Summary
Attributes inherited from Notifier
Instance Method Summary collapse
-
#initialize(options) ⇒ SlackNotifier
constructor
A new instance of SlackNotifier.
- #notify(check_result) ⇒ Object
Constructor Details
#initialize(options) ⇒ SlackNotifier
Returns a new instance of SlackNotifier.
8 9 10 11 12 |
# File 'lib/data_checks/notifiers/slack_notifier.rb', line 8 def initialize() super @formatter_class = .delete(:formatter_class) || SlackDefaultFormatter @webhook_url = .fetch(:webhook_url) { raise ArgumentError, "webhook_url must be configured" } end |
Instance Method Details
#notify(check_result) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/data_checks/notifiers/slack_notifier.rb', line 14 def notify(check_result) formatter = @formatter_class.new(check_result) payload = { attachments: [ { title: formatter.title, text: formatter.text, color: formatter.color, }, ], } response = post(payload) unless response.is_a?(Net::HTTPSuccess) && response.body == "ok" raise "Failed to notify slack: #{response.body.inspect}" end end |