Class | Chef::Handler
In: | lib/chef/handler.rb lib/chef/handler/json_file.rb lib/chef/handler/error_report.rb
Parent: | Object

## Chef::Handler

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`

### Example:

      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

### Methods

data exception_handlers report report_handlers run_exception_handlers run_report_handlers run_report_safely run_report_unsafe run_start_handlers start_handlers

### Classes and Modules

Class Chef::Handler::ErrorReport
Class Chef::Handler::JsonFile

### Attributes

run_status | [R] | The Chef::RunStatus object containing data about the Chef run.

### Public Class methods

exception_handlers()

The list of currently configured exception handlers

report_handlers()

The list of currently configured report handlers

run_exception_handlers(run_status)

Run the exception handlers. Usually will be called by a notification from Chef::Client when the run fails.

run_report_handlers(run_status)

Run the report handlers. This will usually be called by a notification from Chef::Client

run_start_handlers(run_status)

Run the start handlers. This will usually be called by a notification from Chef::Client

start_handlers()

The list of currently configured start handlers

### Public Instance methods

data()

Return the Hash representation of the run_status

report()

The main entry point for report handling. Subclasses should override this method with their own report handling logic.

run_report_safely(run_status)

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.

run_report_unsafe(run_status)

Runs the report handler without any error handling. This method should not be used directly except in testing.

[Validate]