# How to run resource on chef-clief fail

**URL:** <https://discourse.chef.io/t/how-to-run-resource-on-chef-clief-fail/10240>\
**Category:** Chef Infra (archive)\
**Created:** [January 18, 2017, 12:50am UTC](https://discourse.chef.io/t/how-to-run-resource-on-chef-clief-fail/10240 "2017-01-18T00:50:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chic\_cat](https://avatars.discourse-cdn.com/v4/letter/c/e99b99/32.png) [@chic\_cat](https://discourse.chef.io/u/chic_cat)\
**Post date:** [January 18, 2017, 12:50am UTC](https://discourse.chef.io/t/how-to-run-resource-on-chef-clief-fail/10240/1 "2017-01-18T00:50:15Z")

</div>

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: #{Time.now.rfc2822}\n\n"  
message \<\< "#{text}\n"  
Net::SMTP.start(‘mailhost’, 25) do |smtp|  
smtp.send\_message message, “#{def\_emails[‘from’]}”, "#{def\_emails[‘to’]}"  
end  
end

Is it possible to run this resource in

Chef.event\_handler do  
on :run\_failed do

end  
end

It fails when I ran it

---

<div class="post-metadata">

**Author:** ![tomduffield](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/tomduffield/32/950_2.png) [@tomduffield](https://discourse.chef.io/u/tomduffield)\
**Post date:** [January 19, 2017, 12:29am UTC](https://discourse.chef.io/t/how-to-run-resource-on-chef-clief-fail/10240/2 "2017-01-19T00:29:35Z")

</div>

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.

[https://docs.chef.io/libraries.html](https://docs.chef.io/libraries.html)
