Class | Chef::Handler |
In: |
lib/chef/handler.rb
lib/chef/handler/json_file.rb lib/chef/handler/error_report.rb |
Parent: | Object |
The base class for an Exception or Notification Handler. Create your own handler by subclassing Chef::Handler. When a Chef run fails with an uncaught Exception, Chef will set the run_status on your handler and call report
require 'net/smtp' module MyOrg class OhNoes < Chef::Handler def report # Create the email message message = "From: Your Name <your@mail.address>\n" message << "To: Destination Address <someone@example.com>\n" message << "Subject: Chef Run Failure\n" message << "Date: #{Time.now.rfc2822}\n\n" # The Node is available as +node+ message << "Chef run failed on #{node.name}\n" # +run_status+ is a value object with all of the run status data message << "#{run_status.formatted_exception}\n" # Join the backtrace lines. Coerce to an array just in case. message << Array(backtrace).join("\n") # Send the email Net::SMTP.start('your.smtp.server', 25) do |smtp| smtp.send_message message, 'from@address', 'to@address' end end end end
run_status | [R] | The Chef::RunStatus object containing data about the Chef run. |
Run the exception handlers. Usually will be called by a notification from Chef::Client when the run fails.
Run the report handlers. This will usually be called by a notification from Chef::Client
Run the start handlers. This will usually be called by a notification from Chef::Client
Runs the report handler, rescuing and logging any errors it may cause. This ensures that all handlers get a chance to run even if one fails. This method should not be overridden by subclasses unless you know what you‘re doing.
Runs the report handler without any error handling. This method should not be used directly except in testing.