Class: MailHandler
- Inherits:
-
Chef::Handler
- Object
- Chef::Handler
- MailHandler
- Defined in:
- lib/chef/handler/mail.rb,
lib/chef/handler/mail/version.rb
Constant Summary collapse
- VERSION =
"0.1.2"
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ MailHandler
constructor
A new instance of MailHandler.
- #report ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ MailHandler
Returns a new instance of MailHandler.
23 24 25 26 27 28 29 |
# File 'lib/chef/handler/mail.rb', line 23 def initialize(opts = {}) @options = { :to_address => "root", :template_path => File.join(File.dirname(__FILE__), "mail.erb") } @options.merge! opts end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
22 23 24 |
# File 'lib/chef/handler/mail.rb', line 22 def @options end |
Instance Method Details
#report ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/chef/handler/mail.rb', line 31 def report status = success? ? "Successful" : "Failed" subject = "#{status} Chef run on node #{node.fqdn}" Chef::Log.debug("mail handler template path: #{[:template_path]}") if File.exists? [:template_path] template = IO.read([:template_path]).chomp else Chef::Log.error("mail handler template not found: #{[:template_path]}") raise Errno::ENOENT end context = { :status => status, :run_status => run_status } body = Erubis::Eruby.new(template).evaluate(context) Pony.mail( :to => [:to_address], :from => "chef-client@#{node.fqdn}", :subject => subject, :body => body ) end |