diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-11-24 19:38:54 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-11-24 19:38:54 +0000 |
commit | 7b22a2bd29be916cdd4a054962c985f5e6100a39 (patch) | |
tree | 34ea76b66352e383c6b3a81d0f8781ce9ac41c6d /lib/custodian | |
parent | 385b8a569760fcab6199d074a9ffcdd68e7f08c3 (diff) |
Implemented outgoing mail sending.
Diffstat (limited to 'lib/custodian')
-rw-r--r-- | lib/custodian/alerts/smtp.rb | 44 |
1 files changed, 34 insertions, 10 deletions
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 = <<END_OF_MESSAGE +From: #{to} +To: #{to} +Subject: #{subject} + +#{body} +END_OF_MESSAGE + + Net::SMTP.start("127.0.0.1") do |smtp| + smtp.send_message( msg, to, to) + end + + end + register_alert_type "smtp" |