]> git.openstreetmap.org Git - chef.git/blob - cookbooks/chef/templates/default/report.rb.erb
Cope with gems needed for chef reporting not being installed
[chef.git] / cookbooks / chef / templates / default / report.rb.erb
1 # DO NOT EDIT - This file is being maintained by Chef
2
3 require "rubygems"
4 require "pony"
5  
6 class Chef
7   class Handler
8     class Email < Chef::Handler
9       attr_reader :config
10
11       def initialize(config={})
12         @config = config
13         @config[:from] ||= "root@openstreetmap.org"
14         @config
15       end
16  
17       def report
18         if failed? and not exception.is_a? SystemExit
19           subject = "Chef run failed on #{node.name}"
20           message = "#{run_status.formatted_exception}\n"
21         elsif elapsed_time > 300
22           subject = "Chef run took #{elapsed_time} on #{node.name}"
23           message = ""
24         end
25         
26         if subject
27           message << Array(backtrace).join("\n")
28
29           Pony.mail(:to => @config[:to], :from => @config[:from],
30                     :subject => subject, :body => message, :via => :smtp)
31         end
32       end
33     end
34   end
35 end