class Checkups::SlackNotifier

Public Instance Methods

build_attachments(status, message, title = nil, title_link = nil) click to toggle source

api.slack.com/docs/message-attachments#attachment_structure

# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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