New Supermarket Announcements!

The Chef Community Cookbooks Survey

We would love to know more about what you think about community cookbooks and are runnning a quick survey. This will help us understand the role they play in your use of Chef. As a community member, you are invited to participate. You have a unique understanding of the role community cookbooks have in your work, and we value your opinion. Most people take about 5 minutes to complete this survey. There are no right or wrong answers; we are interested in your opinions.
Chef Community Cookbooks Survey

Adoptable Cookbooks List

Looking for a cookbook to adopt? You can now see a list of cookbooks available for adoption!
List of Adoptable Cookbooks

Supermarket Belongs to the Community

Supermarket belongs to the community. While Chef has the responsibility to keep it running and be stewards of its functionality, what it does and how it works is driven by the community. The chef/supermarket repository will continue to be where development of the Supermarket application takes place. Come be part of shaping the direction of Supermarket by opening issues and pull requests or by joining us on the supermarket mailing list or in Gitter.

Select Supported Platforms

RSS

chef_handler (12) Versions 1.1.9

Distribute and enable Chef Exception and Report handlers

Berkshelf
Librarian
Knife
cookbook 'chef_handler', '~> 1.1.9'
cookbook 'chef_handler', '~> 1.1.9'
knife cookbook site install chef_handler
knife cookbook site download chef_handler
README
Dependencies
Changelog
Foodcritic

Description

Creates a configured handler path for distributing Chef report and exception handlers. Also exposes an LWRP for enabling Chef handlers from within recipe code (as opposed to hard coding in the client.rb file). This is useful for cookbook authors who may want to ship a product specific handler (see the cloudkick cookbook for an example) with their cookbook.

Requirements

  • Ruby >= 1.9

Attributes

node["chef_handler"]["handler_path"] - location to drop off handlers directory, default is /var/chef/handlers.

Resource/Provider

chef_handler

Requires, configures and enables handlers on the node for the current Chef run. Also has the ability to pass arguments to the handlers initializer. This allows initialization data to be pulled from a node's attribute data.

It is best to declare chef_handler resources early on in the compile phase so they are available to fire for any exceptions during the Chef run. If you have a base role you would want any recipes that register Chef handlers to come first in the run_list.

Actions

  • :enable: Enables the Chef handler for the current Chef run on the current node
  • :disable: Disables the Chef handler for the current Chef run on the current node

Attribute Parameters

  • class_name: name attribute. The name of the handler class (can be module name-spaced).
  • source: full path to the handler file. can also be a gem path if the handler ships as part of a Ruby gem.
  • arguments: an array of arguments to pass the handler's class initializer
  • supports: type of Chef Handler to register as, i.e. :report, :exception or both. default is :report => true, :exception => true

Example

    # register the Chef::Handler::JsonFile handler
    # that ships with the Chef gem
    chef_handler "Chef::Handler::JsonFile" do
      source "chef/handler/json_file"
      arguments :path => '/var/chef/reports'
      action :enable
    end

    # do the same but during the compile phase
    chef_handler "Chef::Handler::JsonFile" do
      source "chef/handler/json_file"
      arguments :path => '/var/chef/reports'
      action :nothing
    end.run_action(:enable)

    # handle exceptions only
    chef_handler "Chef::Handler::JsonFile" do
      source "chef/handler/json_file"
      arguments :path => '/var/chef/reports'
      supports :exception => true
      action :enable
    end


    # enable the CloudkickHandler which was
    # dropped off in the default handler path.
    # passes the oauth key/secret to the handler's
    # intializer.
    chef_handler "CloudkickHandler" do
      source "#{node['chef_handler']['handler_path']}/cloudkick_handler.rb"
      arguments [node['cloudkick']['oauth_key'], node['cloudkick']['oauth_secret']]
      action :enable
    end

Usage

default

Put the recipe chef_handler at the start of the node's run list to make sure that custom handlers are dropped off early on in the Chef run and available for later recipes.

For information on how to write report and exception handlers for Chef, please see the Chef wiki pages: http://wiki.chef.io/display/chef/Exception+and+Report+Handlers

json_file

Leverages the chef_handler LWRP to automatically register the Chef::Handler::JsonFile handler that ships as part of Chef. This handler serializes the run status data to a JSON file located at /var/chef/reports.

Unit Testing

chef_handler provides built in chefspec matchers for assisting unit tests. These matchers will only be loaded if chefspec is already loaded. Following is an example of asserting against the jsonfile handler:

  expect(runner).to enable_chef_handler("Chef::Handler::JsonFile").with(
    source: "chef/handler/json_file",
    arguments: { :path => '/var/chef/reports'},
    supports: {:exception => true}
    )
  end

License and Author

Author:: Seth Chisamore (schisamo@chef.io)

Copyright:: 2011, Chef Software, Inc

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Dependent cookbooks

This cookbook has no specified dependencies.

Contingent cookbooks

chef-sentry-handler Applicable Versions
chef_handler_sns Applicable Versions
cloudformation Applicable Versions
cookbook_versions_handler Applicable Versions
copperegg Applicable Versions
datadog Applicable Versions
diptables Applicable Versions
etckeeper Applicable Versions
eventlog Applicable Versions
gelf_handler Applicable Versions
graphite_handler Applicable Versions
graphite_reporting_handler Applicable Versions
hipchat Applicable Versions
il-base Applicable Versions
mcollective Applicable Versions
minitest Applicable Versions
minitest-handler Applicable Versions
motd Applicable Versions
powershell Applicable Versions
reboot Applicable Versions
reboot-handler Applicable Versions
reportchef Applicable Versions
slack_handler Applicable Versions
splunk_handler Applicable Versions
syslog_handler Applicable Versions
windows Applicable Versions
zookeeper_bridge Applicable Versions

chef_handler cookbook CHANGELOG

v1.1.9 (2015-05-26)

Bugfixes from 1.1.8 - loading without source is not allowed again. Class unloading is performed more carefully. Tests for resource providers.

v1.1.8 (2015-05-14)

Updated Contribution and Readme docs. Fix ChefSpec matchers. Allow handler to load classes when no source is provided.

v1.1.6 (2014-04-09)

[COOK-4494] - Add ChefSpec matchers

v1.1.5 (2014-02-25)

  • [COOK-4117] - use the correct scope when searching the children class name

v1.1.4

  • [COOK-2146] - style updates

v1.1.2

  • [COOK-1989] - fix scope for handler local variable to the enable block

v1.1.0

  • [COOK-1645] - properly delete old handlers
  • [COOK-1322] - support platforms that use 'wheel' as root group'

v1.0.8

  • [COOK-1177] - doesn't work on windows due to use of unix specific attributes

v1.0.6

  • [COOK-1069] - typo in chef_handler readme

v1.0.4

  • [COOK-654] dont try and access a class before it has been loaded
  • fix bad boolean check (if vs unless)

v1.0.2

  • [COOK-620] ensure handler code is reloaded during daemonized chef runs
FC031: Cookbook without metadata file: /tmp/cook/52a9a279c90d850d44d632c7/chef_handler/metadata.rb:1
FC045: Consider setting cookbook name in metadata: /tmp/cook/52a9a279c90d850d44d632c7/chef_handler/metadata.rb:1