Adoptable Cookbooks List

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 Chef Mailing List.

sensu_spec cookbook

sensu_spec attempts to blur the line between TDD and monitoring.

One way to achieve this is to use something like serverspec to write test, then to send the results to Sensu. This is great, but seems to be a limited approach. I think you'd have to jump through a number of hoops to be able to reuse existing monitoring plugins, and getting metrics out would probably be a bit painful.

This cookbook is an experiment that starts with standard monitoring tools and attempts to turn them into specs.

A quick overview

If you want something basic, you can use the definitions that come with this cookbook. But first, you need to use the cookbook.

Edit metadata.rb in your cookbook and add

depends 'sensu_spec'

Then install using berkshelf

$ berks update

Now, lets say your cookbook is going to install and configure a logstash server. You'll probably want to start off by writing a recipe called spec.rb:

include_recipe 'sensu_spec'
describe 'logstash' do
describe 'java' do
it 'must have command java'
end
describe 'java version' do
it 'must match "1\.7.*(\n|.)*HotSpot" when I run "java -version"'
end
end
describe 'logstash agent' do
describe 'directory' do
it 'must have directory /opt/logstash/agent'
end
describe 'jar' do
it "must have readable file /opt/logstash/agent/lib/logstash-#{node.logstash.agent.version}.jar"
end
describe 'process' do
it 'must have 1 java process with args logstash/agent'
end
end
describe 'logstash server' do
describe 'directory' do
it 'must have directory /opt/logstash/server'
end
describe 'jar' do
it "must have readable file /opt/logstash/server/lib/logstash-#{node.logstash.server.version}.jar"
end
describe 'process' do
it 'must have 1 java process with args logstash/server'
end
end

The command should look familiar, it will be mapped to a Sensu check command. The code attribute is optional, but if provided it will create the command specified with that code. In this case we're using bash to write a little check to monitor processes.

When a specification matches a definition, some magic happens to combine the two to turn them into standalone checks that can be run during tests, and Sensu client and server configuration

Foodcritic Metric

0.10.4 failed this metric

FC001: Use strings in preference to symbols to access node attributes: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/providers/default.rb:22FC001: Use strings in preference to symbols to access node attributes: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/providers/default.rb:23FC001: Use strings in preference to symbols to access node attributes: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/providers/default.rb:24FC001: Use strings in preference to symbols to access node attributes: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/providers/default.rb:28FC001: Use strings in preference to symbols to access node attributes: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/providers/default.rb:38FC001: Use strings in preference to symbols to access node attributes: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/providers/default.rb:42FC001: Use strings in preference to symbols to access node attributes: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/providers/default.rb:62FC001: Use strings in preference to symbols to access node attributes: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/providers/definition.rb:12FC001: Use strings in preference to symbols to access node attributes: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/providers/definition.rb:21FC001: Use strings in preference to symbols to access node attributes: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/recipes/client.rb:34FC001: Use strings in preference to symbols to access node attributes: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/recipes/client.rb:35FC001: Use strings in preference to symbols to access node attributes: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/recipes/client.rb:42FC001: Use strings in preference to symbols to access node attributes: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/recipes/client.rb:48FC017: LWRP does not notify when updated: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/providers/default.rb:5FC019: Access node attributes in a consistent manner: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/attributes/default.rb:9FC019: Access node attributes in a consistent manner: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/attributes/default.rb:10FC019: Access node attributes in a consistent manner: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/attributes/default.rb:11FC019: Access node attributes in a consistent manner: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/providers/default.rb:50FC019: Access node attributes in a consistent manner: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/providers/definition.rb:27FC019: Access node attributes in a consistent manner: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/recipes/client.rb:30FC019: Access node attributes in a consistent manner: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/recipes/client.rb:31FC019: Access node attributes in a consistent manner: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/recipes/client.rb:32FC019: Access node attributes in a consistent manner: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/recipes/client.rb:37FC019: Access node attributes in a consistent manner: /tmp/cook/18c4aa7e84a3219ccf0e1773/sensu_spec/recipes/client.rb:49