Class: ChefEmailReporter::Reporters::EmailReporter
- Inherits:
-
Chef::EventDispatch::Base
- Object
- Chef::EventDispatch::Base
- ChefEmailReporter::Reporters::EmailReporter
- Defined in:
- lib/chef-email-reporter/reporters/email_reporter.rb
Instance Method Summary collapse
- #cookbook_resolution_failed(expanded_run_list, exception) ⇒ Object
- #cookbook_sync_failed(cookbooks, exception) ⇒ Object
-
#initialize ⇒ EmailReporter
constructor
A new instance of EmailReporter.
- #resource_failed(new_resource, action, exception) ⇒ Object
- #run_failed(exception) ⇒ Object
- #run_list_expand_failed(node, exception) ⇒ Object
- #run_started(run_status) ⇒ Object
Constructor Details
#initialize ⇒ EmailReporter
Returns a new instance of EmailReporter.
27 28 29 |
# File 'lib/chef-email-reporter/reporters/email_reporter.rb', line 27 def initialize @errors = [] end |
Instance Method Details
#cookbook_resolution_failed(expanded_run_list, exception) ⇒ Object
88 89 90 91 |
# File 'lib/chef-email-reporter/reporters/email_reporter.rb', line 88 def cookbook_resolution_failed(, exception) description = ::Chef::Formatters::ErrorMapper.cookbook_resolution_failed(, exception) @errors << description end |
#cookbook_sync_failed(cookbooks, exception) ⇒ Object
93 94 95 96 |
# File 'lib/chef-email-reporter/reporters/email_reporter.rb', line 93 def cookbook_sync_failed(cookbooks, exception) description = ::Chef::Formatters::ErrorMapper.cookbook_sync_failed(cookbooks, exception) @errors << description end |
#resource_failed(new_resource, action, exception) ⇒ Object
78 79 80 81 |
# File 'lib/chef-email-reporter/reporters/email_reporter.rb', line 78 def resource_failed(new_resource, action, exception) description = ::Chef::Formatters::ErrorMapper.resource_failed(new_resource, action, exception) @errors << description end |
#run_failed(exception) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/chef-email-reporter/reporters/email_reporter.rb', line 35 def run_failed(exception) error_description = ::ChefEmailReporter::Formatters::MultipartOutputStream.new @errors.each do |desc| desc.display(error_description) end namespace = OpenStruct.new({ node_name: @run_status.node[:name], node_fqdn: @run_status.node[:fqdn], run_id: @run_status.run_id, start_time: @run_status.start_time }) namespace.error = error_description.text_part text_template = File.read(File.("../../templates/email.text.erb", __FILE__)) text_body = ERB.new(text_template).result(namespace.instance_eval { binding }) namespace.error = error_description.html_part html_template = File.read(File.("../../templates/email.html.erb", __FILE__)) html_body = ERB.new(html_template).result(namespace.instance_eval { binding }) subject_line = "chef-client run failed (#{@run_status.node[:fqdn]})" Mail.deliver do from ::Chef::Config[:email_sender] to ::Chef::Config[:email_recipient] subject subject_line text_part do body text_body end html_part do body html_body end end end |
#run_list_expand_failed(node, exception) ⇒ Object
83 84 85 86 |
# File 'lib/chef-email-reporter/reporters/email_reporter.rb', line 83 def (node, exception) description = ::Chef::Formatters::ErrorMapper.(node, exception) @errors << description end |
#run_started(run_status) ⇒ Object
31 32 33 |
# File 'lib/chef-email-reporter/reporters/email_reporter.rb', line 31 def run_started(run_status) @run_status = run_status end |