Chapter 6. Extending Chef Run Events

As we touched on briefly in Chapter 3 (see SetUp RunContext), Chef builds up a comprehensive collection of the events that occur during the course of a run that it exposes through a system called the event dispatcher. The event dispatcher works on what’s known as a publish/subscribe model. This means that classes that wish to be notified of events that occur during a Chef run can subscribe to the event dispatcher, and each time the event dispatcher receives an event it publishes it to all registered subscribers. In fact, the output you see displayed on your terminal when running chef-client or chef-solo manually is generated by a type of subscriber called a formatter, which we’ll be looking at later in this chapter.

Introduction to the Event Dispatcher

Out of the box, Chef leverages the event dispatcher system to power the terminal output produced by chef-client and send reporting data to Enterprise Chef (if it’s being used), but the detailed information it exposes to us about our Chef runs can be used for a variety of purposes. Say you want to augment or alter the output of chef-client to structure the information it presents in a different way. Or perhaps you’d like to integrate Chef run data into an internal event tracking system so that you can collect information on when a recipe change has been processed by all of your nodes. The event dispatcher allows us to quickly and easily tap into its event stream to access all of the information we ...

Get Customizing Chef now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.