Skip to content

Instantly share code, notes, and snippets.

@eddanger
Created August 14, 2014 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eddanger/e1ee3db849c9f5f9b389 to your computer and use it in GitHub Desktop.
Save eddanger/e1ee3db849c9f5f9b389 to your computer and use it in GitHub Desktop.
Slack and Campfire Rails Exception notification
# 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" <notifier@somedomain.com>},
: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