From 7b22a2bd29be916cdd4a054962c985f5e6100a39 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Sat, 24 Nov 2012 19:38:54 +0000 Subject: Implemented outgoing mail sending. --- lib/custodian/alerts/smtp.rb | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/custodian/alerts/smtp.rb b/lib/custodian/alerts/smtp.rb index 0803bb3..d170bbf 100644 --- a/lib/custodian/alerts/smtp.rb +++ b/lib/custodian/alerts/smtp.rb @@ -1,5 +1,5 @@ - +require 'net/smtp' # # The SMTP-alerter. @@ -8,7 +8,7 @@ module Custodian module Alerter - class SMTP < AlertFactory + class AlertSMTP < AlertFactory # # The test this alerter cares about @@ -26,24 +26,48 @@ module Custodian - + # + # Raise an alert by email. + # def raise - puts "Sould raise an alert via EMAIL" - puts "Subject: #{test.target} failed #{test.get_type}-test - #{test.error()}" - puts "TO: #{@target}" - end + subject = "#{test.target} failed #{test.get_type}-test - #{test.error()}" + body = "The alert has cleared\nRegards\n"; + _send_mail( @target, subject, body ) + end + # + # Clear an alert by email. + # def clear - puts "Should clear an alert via EMAIL" - puts "Subject: #{test.target} passed #{test.get_type}-test" - puts "TO: #{@target}" + subject = "#{test.target} failed #{test.get_type}-test" + body = "The alert has raised, with the following details:\n#{test.error()}\nRegards\n"; + + _send_mail( @target, subject, body ) end + # + # Send an email + # + def _send_mail( to, subject, body ) + msg = <