]> git.openstreetmap.org Git - chef.git/blob - cookbooks/chef/templates/default/report.rb.erb
Upgrade to chef 16
[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
5 class Chef
6   class Handler
7     class Email < Chef::Handler
8       attr_reader :config
9
10       def initialize(config = {})
11         @config = config
12         @config[:from] ||= "root@openstreetmap.org"
13         @config
14       end
15
16       def report
17         from_address = @config[:from]
18         to_address = @config[:to]
19
20         if failed? && !exception.is_a?(SystemExit)
21           message_subject = "Chef run failed on #{node.name}"
22           message_body = "#{run_status.formatted_exception}\n"
23         elsif elapsed_time > 600
24           message_subject = "Chef run took #{elapsed_time} on #{node.name}"
25           message_body = ""
26         end
27
28         return unless message_subject
29
30         message_body << Array(backtrace).join("\n")
31
32         require "mail"
33
34         Mail.defaults do
35           delivery_method :exim, :location => "/usr/sbin/exim"
36         end
37
38         Mail.deliver do
39           to to_address
40           from from_address
41           subject message_subject
42           body message_body
43         end
44       end
45     end
46   end
47 end