Class: Nines::Notifier
- Inherits:
-
Object
- Object
- Nines::Notifier
- Defined in:
- lib/nines/notifier.rb
Instance Method Summary collapse
- #human_duration(seconds) ⇒ Object
-
#initialize(contacts) ⇒ Notifier
constructor
A new instance of Notifier.
- #notify!(contact_name, check, details = '') ⇒ Object
Constructor Details
#initialize(contacts) ⇒ Notifier
Returns a new instance of Notifier.
6 7 8 |
# File 'lib/nines/notifier.rb', line 6 def initialize(contacts) @contacts = contacts end |
Instance Method Details
#human_duration(seconds) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/nines/notifier.rb', line 22 def human_duration(seconds) case when seconds < 60 then "#{seconds} sec" when seconds < 3600 then "#{seconds/60} min #{seconds%60} sec" when seconds < 86400 then "#{seconds/3600} hr #{seconds%3600/60} min #{seconds%60} sec" else "#{seconds/86400} day #{seconds%86400/3600} hr #{seconds%3600/60} min #{seconds%60} sec" end end |
#notify!(contact_name, check, details = '') ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/nines/notifier.rb', line 10 def notify!(contact_name, check, details = '') contact = @contacts[contact_name] email_body = ERB.new(File.open(Nines::App.root + '/lib/nines/email_templates/notification.text.erb').read).result(binding) Mail.deliver do from Nines::App.email_from to contact['email'] subject "#{Nines::App.email_subject_prefix}#{check.name} is #{check.up ? 'UP' : 'DOWN'}" body email_body end end |