Created
July 4, 2011 16:42
-
-
Save jellybob/1063598 to your computer and use it in GitHub Desktop.
Broken notifier
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 'gelf' | |
class GELFHandler < Chef::Handler | |
attr_reader :notifier | |
def initialize(server, port, facility) | |
@notifier = GELF::Notifier.new(server, port, 'WAN', :facility => facility) | |
end | |
def report | |
if run_status.failed? | |
@notifier.notify!(:short_message => "Chef run failed on #{@notifier.host}", | |
:full_message => run_stats.formatted_exception + "\n" + Array(backtrace).join("\n"), | |
:level => GELF::Levels::ERROR, | |
:host => node.name) | |
else | |
short_message = "Chef run completed on #{node.name} in #{elapsed_time}. Updated #{run_status.updated_resources.size}." | |
message = "Updated Resources:\n\n" | |
run_status.updated_resources.collect do |resource| | |
"recipe[#{resource.cookbook_name}::#{resource.recipe_name}] ran '#{resource.action}' on #{resource.resource_name} '#{resource.name}'" | |
end.join("\n") | |
@notifier.notify!(:short_message => short_message, | |
:full_message => message, | |
:level => GELF::Levels::INFO, | |
:host => node.name) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment