title: Custom Chef handlers
body: <p>I am trying to understand the Chef documentation on <a href="https://docs.chef.io/handlers/#custom-handlers" rel="nofollow noreferrer">Custom Handlers</a>.</p>
  <p>The steps seem easy enough but I still don't understand how it works.</p>
  <ol>
  <li>Download the chef_handler cookbook</li>
  <li>Create a custom handler</li>
  <li>Write a recipe using the chef_handler resource</li>
  <li>Add that recipe to a node’s run-list, often as the first recipe in that run-list</li>
  </ol>
  <p>Step 1 is no longer necessary as <code>chef_handler</code> cookbook is now part of Chef.</p>
  <p>Step 2 creates a handler. The example given is</p>
  <pre class="lang-rb prettyprint-override"><code>require 'net/smtp'
  
  module OrgName
    class SendEmail &lt; Chef::Handler
      def report
        if run_status.failed? then
          message  = &quot;From: sender_name &lt;sender@example.com&gt;\n&quot;
          message &lt;&lt; &quot;To: recipient_address &lt;recipient@example.com&gt;\n&quot;
          message &lt;&lt; &quot;Subject: chef-client Run Failed\n&quot;
          message &lt;&lt; &quot;Date: #{Time.now.rfc2822}\n\n&quot;
          message &lt;&lt; &quot;Chef run failed on #{node.name}\n&quot;
          message &lt;&lt; &quot;#{run_status.formatted_exception}\n&quot;
          message &lt;&lt; Array(backtrace).join('\n')
          Net::SMTP.start('your.smtp.server', 25) do |smtp|
            smtp.send_message message, 'sender@example', 'recipient@example'
          end
        end
      end
    end
  end
  </code></pre>
  <p>Now comes step 3 which I don't understand, add the following to a recipe</p>
  <pre class="lang-rb prettyprint-override"><code>send_email 'blah' do
    # recipe code
  end
  </code></pre>
  <p>When I run my recipe it just produces the error message which I expected to begin with:</p>
  <pre><code>FATAL: NoMethodError: undefined method `send_email` for cookbook: test, recipe: default :Chef::Recipe
  </code></pre>
  <p>How is this supposed to work? Are there other simple but working examples of custom handlers?</p>
  <p>For Chef 15.0.300</p>