Class: Checkups::SlackNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/checkups/slack_notifier.rb

Instance Method Summary collapse

Instance Method Details

#build_attachments(status, message, title = nil, title_link = nil) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/checkups/slack_notifier.rb', line 18

def build_attachments(status, message, title = nil, title_link = nil)
  attachment = {"color": status_to_slack_color(status),
                "text": message}
  attachment[:title] = title if title
  attachment[:title_link] = title_link if title_link
  [attachment]
end

#notify(checkup) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/checkups/slack_notifier.rb', line 5

def notify(checkup)
  attachments = build_attachments(checkup.status,
                                  checkup.notify_message,
                                  checkup.name,
                                  checkup.url)
  send_attachments(attachments)
end

#send_attachments(_attachments) ⇒ Object



13
14
15
# File 'lib/checkups/slack_notifier.rb', line 13

def send_attachments(_attachments)
  raise "Must subclass Checkups::SlackNotifier#send_attachments"
end

#status_to_slack_color(status) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/checkups/slack_notifier.rb', line 26

def status_to_slack_color(status)
  case status
  when :ok, :info
    "good"
  when :warning
    "warning"
  when :error, :fatal
    "danger"
  end
end