Created
August 14, 2014 16:29
-
-
Save eddanger/e1ee3db849c9f5f9b389 to your computer and use it in GitHub Desktop.
Slack and Campfire Rails Exception notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Docs: http://smartinez87.github.io/exception_notification/ | |
module ExceptionNotifier | |
class SlackNotifier | |
def initialize(options) | |
# do something with the options... | |
@channel = options[:channel] || '#somechannel' | |
@team = options[:team] || 'someteam' | |
@token = options[:token] || '__top_secret_token__' | |
@username = options[:username] || 'somename' | |
@emoji = options[:emoji] || ':exclamation:' | |
end | |
def call(exception, options={}) | |
# send the notification | |
notifier = Slack::Notifier.new @team, @token, channel: @channel, username: @username, icon_emoji: @emoji | |
notifier.ping "A new exception occurred: '#{exception.message}' on '#{exception.backtrace.first}'" | |
end | |
end | |
end | |
if [ 'production', 'staging' ].include?( Rails.env ) | |
email = { | |
:email_prefix => "[Some Prefix] ", | |
:sender_address => %{"Exception Notifier" <[email protected]>}, | |
:exception_recipients => Rails.configuration.exception_recipients | |
} | |
campfire = { | |
:subdomain => 'subdomain', | |
:token => '__top_secret_token__', | |
:room_name => 'Room name' | |
} | |
options = {} | |
options[:email] = email | |
options[:slack] = {} | |
if Rails.env.production? | |
options[:campfire] = campfire | |
end | |
Rails.configuration.middleware.use ExceptionNotification::Rack, options | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment