Created
September 24, 2012 00:01
-
-
Save tekei/3773496 to your computer and use it in GitHub Desktop.
(Sinatra) エラー発生時にprowlに通知
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
# 事前に、環境変数 APP_NAME、PROWL_APIを設定しておく | |
# | |
# なお、下記ソースではエラーの重複排除を行っていないため | |
# 連続エラーで大量に送信されることになるので注意 | |
require 'prowler' | |
# prowlの困ったところとして、メッセージの終端がきちんと表示出来ないことがある。 | |
# そのため、メッセージに改行2つ付け加えてます。 | |
def notify_sys_error(msg) | |
# use : http://curl.haxx.se/docs/caextract.html | |
Prowler.root_certificates = "#{File.dirname(__FILE__)}/ca-bundle.crt" | |
prowler = Prowler.new(:application => ENV['APP_NAME'], :api_key => ENV['PROWL_API']) | |
prowler.notify "System Error", msg + "\n\n" | |
end | |
# 下記は、Sinatra::Applicationに。 | |
if settings.environment == :production then | |
error do | |
notify_sys_error("システムエラー発生 : #{env['sinatra.error']}") | |
$log.fatal "system error : #{env['sinatra.error'].inspect}" | |
# [追加要]出来ればstacktraceを出力した方が良い | |
# [追加要]エラー画面の表示 | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment