- From: Daniel DeLeo <
>
- To:
- Subject: [chef] Re: Re: Re: Re: Re: Re: Exception Handlers with ignore_failure
- Date: Tue, 4 Dec 2012 08:31:55 -0800
On Tuesday, December 4, 2012 at 7:57 AM, jfotop wrote:
From what I saw and understood, run_status.events could be one of:
node:
exception:
end_time:
elapsed_time:
all_resources:
backtrace:
success: true
updated_resources:
start_time:
I could of misunderstood, but when trying to add run_status.events to the
report handler method into the message of the email i send, I get a method
error saying:
raised #<ArgumentError: wrong number of arguments (0 for 3)>
My handler code is:
def report
# The Node is available as +node+
subject = "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
#{run_status.events.resource_failed}"
# Join the backtrace lines. Coerce to an array just in case.
message << Array(backtrace).join("\n")
Pony.mail(:to => @to_address, :from => @from_address, :subject =>
subject, :body => message)
end
Any ideas?
Two things here:
# Event Dispatch:
The events stuff is part of the new event dispatch system that was added to Chef in 10.14, and is used by the output formatters also introduced in 10.14. The object that gets passed around as "events" is just a forwarder that sends the event messages to zero or more event handlers, which are a new thing, distinct from the exception and report handlers. In presently released versions of Chef, there's unfortunately no way to define custom event handlers, due to an error on my part[1], though I've fixed that and you will be able to have custom ones in Chef 11.0.
For a variety of reasons, we're using the event dispatch stuff to implement server-side reporting of updated resources (this feature is in limited testing now, and will *not* be part of the open source Chef 11.0 server). You can see the client-side implementation here:
https://github.com/opscode/chef/blob/master/lib/chef/resource_reporter.rb
And the interface for an event handler is defined by the base class here:
https://github.com/opscode/chef/blob/master/lib/chef/event_dispatch/base.rb
And the output formatters are another example of how to write an event handler (they have some extra code for printing things to the screen, but that's about it):
https://github.com/opscode/chef/blob/master/lib/chef/formatters/doc.rb
# Original Question:
Back to the original question, it doesn't look like any status flag is set on a resource when it fails, so the event handlers are the only thing that get any indication when a resource fails but failure is ignored. It doesn't seem unreasonable to add a flag to resources to track this, so feel free to submit a patch.
1. I suppose you could add an event handler during a chef run by calling run_context.events.register(my_event_handler), but there's no way to have it configured at the very start of the run. In Chef 11, you add your event handlers via the `event_handlers` config setting:
https://github.com/opscode/chef/blob/master/lib/chef/client.rb#143
Archive powered by MHonArc 2.6.16.