How to run resource on chef-clief fail

Hi guys, I have a resource file:

resource_name :send_email

property :text, String, default: 'Unknown’
property :node_name, String, default: 'Unknown’
property :subject, String, default: ‘Chef run’

action :send do
require 'net/smtp’
def_emails = data_bag_item(‘def_settings’, ‘emails’)
message = "From: #{def_emails[‘from’]}>\n"
message << "To: #{def_emails[‘to’]}\n"
message << "Subject: #{subject}\n"
message << "Date: #{}\n\n"
message << "#{text}\n"
Net::SMTP.start(‘mailhost’, 25) do |smtp|
smtp.send_message message, “#{def_emails[‘from’]}”, "#{def_emails[‘to’]}"

Is it possible to run this resource in

Chef.event_handler do
on :run_failed do


It fails when I ran it

I’m sorry, but the event handler will not execute chef resources. The best bet is to create a library helper that takes in three parameters (text, node name, and subject) and call that from within the :run_failed do block.