Чудовий gem exception_notification який займається відсилкою повідомлень у разі винекнення помилок
Використання
/config/enviroments/production.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true config.action_mailer.raise_delivery_errors = true config.action_mailer.default_url_options = { host: 'my-host-name' } middleware.use ExceptionNotification::Rack, :email => { :email_prefix => "[PREFIX]", :sender_address => '"system-notifier" <from@mail>', :exception_recipients => %w{to@mail} } ExceptionNotifier::Rake.configure #example for gmail ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.smtp_settings = { :address => 'smtp.gmail.com', :port => 587, :domain => 'gmail.com', :user_name => ENV['email'], :password => ENV['email_password'], :authentication => 'plain' } |
Приклад виклику кастомної помилки
1 2 |
exception = StandardError.new('Error export to icinga') ExceptionNotifier.notify_exception(exception, data: { command: cmd }) |