This is a Chef report handler that posts failures as JSON to a specified endpoint.
Only tested on Chef >= 11.0
There are two ways to use Chef Handlers.
Use the chef_handler cookbook by Opscode. Create a recipe with the following:
include_recipe "chef_handler"
# Install `chef-handler-error-post` gem during the compile phase
chef_gem "chef-handler-error-post"
# load the gem here so it gets added to the $LOAD_PATH, otherwise chef_handler
# will fail.
require 'chef/handler/error_post'
# Activate the handler immediately during compile phase
chef_handler "Chef::Handler::ErrorPost" do
source "chef/handler/error_post"
action :nothing
end.run_action(:enable)
Install the gem ahead of time, and configure Chef to use them:
gem install chef-handler-error-post
Then add to the configuration (/etc/chef/solo.rb for chef-solo or
/etc/chef/client.rb for chef-client):
require "chef/handler/error_post"
report_handlers << Chef::Handler::ErrorPost.new
exception_handlers << Chef::Handler::ErrorPost.new
See report_data.json.failure
Author:: Jake Pelletier https://github.com/Ghjnut