Class: Findbug::Alerts::Channels::Slack

Inherits:
Base
  • Object
show all
Defined in:
lib/findbug/alerts/channels/slack.rb

Overview

Slack sends alerts via Slack incoming webhooks.

CONFIGURATION

config.alerts do |alerts|
  alerts.slack(
    enabled: true,
    webhook_url: ENV["SLACK_WEBHOOK_URL"],
    channel: "#errors",  # optional, overrides webhook default
    username: "Findbug", # optional
    icon_emoji: ":bug:"  # optional
  )
end

SETTING UP SLACK WEBHOOK

  1. Go to api.slack.com/apps

  2. Create a new app (or use existing)

  3. Add “Incoming Webhooks” feature

  4. Create a webhook for your channel

  5. Copy the webhook URL

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Findbug::Alerts::Channels::Base

Instance Method Details

#send_alert(error_event) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/findbug/alerts/channels/slack.rb', line 35

def send_alert(error_event)
  webhook_url = config[:webhook_url]
  return if webhook_url.blank?

  payload = build_payload(error_event)
  post_to_webhook(webhook_url, payload)
end