Created
May 14, 2014 13:01
-
-
Save johnfitzpatrick/e5f27b666bc8ec1d9559 to your computer and use it in GitHub Desktop.
Handler for Chef Intermediate class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'pony' | |
module MyCompany | |
class EmailMe < Chef::Handler | |
def initialize(from_address, to_address) | |
@from_address = from_address | |
@to_address = to_address | |
end | |
def report | |
status = success? ? "Successful" : "Failed" | |
subject = "#{status} Chef run report from #{node.name}" | |
report_string = "" | |
# report on changed resources | |
if ! run_status.updated_resources.empty? | |
# get some info about all the changed resources! | |
run_status.updated_resources.each do |r| | |
report_string += "The resource #{r.name} was changed in cookbook #{r.cookbook_name} at #{r.source_line}\n" | |
end | |
else | |
report_string += "No resources changed by chef-client\n" | |
end | |
Pony.mail(:to => @to_address, | |
:from => @from_address, | |
:subject => subject, | |
:body => report_string) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment