• Stars
    star
    256
  • Rank 158,012 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 15 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Systems testing plugin for Nagios with Cucumber + Webrat + Mechanize + Net::SSH

cucumber-nagios

cucumber-nagios allows you to write high-level behavioural tests of web application, and plug the results into Nagios.

As Bradley Taylor put it:

“Instead of writing boring monitoring plugins from scratch,
you can now do behavior driven ops!

Transform from a grumpy, misanthropic sysadmin to a hipster,
agile developer instantly.”

Quickstart

  1. gem install cucumber-nagios
  2. cucumber-nagios-gen project bunch-o-tests
  3. cd bunch-o-tests
  4. bundle install
  5. cucumber-nagios-gen feature ebay.com.au bidding
  6. cucumber-nagios features/ebay.com.au/bidding.feature

Installing

Install the gem with:

gem install cucumber-nagios

This will add the cucumber-nagios-gen and cucumber-nagios commands to your path, and make the shipped cucumber-nagios steps available to other projects using Cucumber.

Windows users - you need to download and install the Ruby Installer and the development kit, otherwise gem install cucumber-nagios will fail.

Setting up a project

After installing the cucumer-nagios gem, set up a standalone project with:

cucumber-nagios-gen project <project-name>

This will spit out a bunch of files in the directory specified as <project-name>.

Check the README within this directory for specific instructions for managing the project.

Setting up Password-less SSH

To use Aruba's step definitions with SSH sessions we use passwordl-less authetication.

Once you have installed the Cucumber-Nagios gem it should 'just-work'. Of course you server needs to accept these connections. To test your localhost password-less access (bash):

ssh-forever `whoami`@`hostname` -p 22 -i ~/.ssh/test_id_rsa.pub -n testing -b
ssh testing "echo 'Hello there from here: `hostname`'"

If you want an interactive login after you set up a new SSH user/key/host:

ssh-forever `whoami`@`hostname` -p 22 -i ~/.ssh/test_id_rsa.pub -n testing2 -a -q

Finally if you need to enter you password to create a key, try this:

ssh-forever `whoami`@`hostname` -p 22 -i ~/.ssh/test_id_rsa.pub -n testing3

Once you have your SSH server accepting secure, but password-less, connections you can remove the test keys from ~/.ssh/, and you can remove the Host entry in ~/.ssh/config.

You are now good to use SSH-forever - which of course is the gem we use :)

For a full example see ssh-forever.

Bundling dependencies

Bundling cucumber-nagios's dependencies allows you to drop your cucumber-nagios project on any machine and have it run. This solves the case of developing your checks on your local machine, and deploying them on a production monitoring server.

First you need to make sure the following dependencies are installed:

  • RubyGems
  • bundler gem (automatically pulled in by the cucumber-nagios gem)

Then to bundle your dependencies, within your project directory run:

$ bundle install

Writing features

Once you've set up a project, you can use the cucumber-nagios-gen command to generate new features. It takes two arguments: the site you're testing, and feature you're testing:

cucumber-nagios-gen feature gnome.org navigation

This will spit out two files:

features/gnome.org/navigation.feature
features/gnome.org/steps/navigation_steps.rb

As for writing features, you'll want to have a read of the Cucumber documentation, however your tests will look something like this:

Feature: google.com.au
  To broaden their knowledge
  A user should be able
  To search for things

  Scenario: Searching for things
    When I go to "http://www.google.com"
    And I fill in "q" with "wikipedia"
    And I press "Google Search"
    Then I should see "www.wikipedia.org"

There's a collection of steps that will cover most of the things you'll be testing for in features/steps/webrat_steps.rb.

You can write custom steps for testing specific output and behaviour, e.g. in features/smh.com.au/smh.feature:

Feature: smh.com.au
  It should be up
  And provide links to content

  Scenario: Visiting home page
    When I go to http://smh.com.au/
    Then I should see site navigation
    And there should be a section named "Opinion"

There aren't steps for Then I should see site navigation, so you have to write one yourself. :-) In features/smh.com.au/steps/smh_steps.rb:

Then /^I should see site navigation$/ do
  doc = Nokogiri::HTML(response.body.to_s)
  doc.css("ul#nav li a").size.should > 5
end

You can use Nokogiri for testing responses with XPath matchers and CSS selectors.

I suggest you use bin/cucumber directly so you can get better feedback when writing your tests:

bin/cucumber --require features/ features/smh/smh.feature

This will output using the default 'pretty' formatter.

Running

Invoke the Cucumber feature with the cucumber-nagios script:

cucumber-nagios features/smh.com.au/smh.feature

cucumber-nagios can be run from anywhere:

/path/to/bin/cucumber-nagios /path/to/features/smh/smh.feature

It should return a standard Nagios-formatted response string:

Critical: 0, Warning: 0, 2 okay | passed=2, failed=0, total=2

Steps that fail will show up in the "Critical" total, and steps that pass show up in the "okay" total.

The value printed at the end is in Nagios's Performance Data format, so it can be graphed and the like.

Benchmarking

You can benchmark your features if you need to test response times for a set of site interactions:

Feature: slashdot.com
  To keep the geek masses satisfied
  Slashdot must be responsive

  Scenario: Visiting a responsive front page
    Given I am benchmarking
    When I go to http://slashdot.org/
    Then the elapsed time should be less than 5 seconds

The elapsed time step can be reused multiple times in the same scenario if you need fine grained testing:

Feature: slashdot.com
  To keep the geek masses satisfied
  Slashdot must be responsive

  Scenario: Visiting news articles
    Given I am benchmarking
    When I go to http://slashdot.org/
    Then the elapsed time should be less than 5 seconds
    When I follow "Login"
    Then the elapsed time should be less than 4 seconds
    When I follow "Contact"
    Then the elapsed time should be less than 7 seconds

AMQP Message Queues

You can test for various conditions on an AMQP message queue.

Feature: github.com
  To make sure the rest of the system is in order
  All our message queues must not be backed up

  Scenario: test queue 2
    Given I have a AMQP server on rabbit.github.com
    And I want to check on the fork queue
    Then it should have less than 400 messages
    Then it should have at least 5 consumers
    Then it should have less than 50 messages per consumer

This has been tested using RabbitMQ but uses the amqp gem which should support other backends. See features/amqp_steps.rb for all the available steps.

Deploying to production

As per the install instructions above, make sure you have RubyGems and the bundler gem installed.

Once you've copied your project to your monitoring server, just run bundler again:

$ bundle install

Quirks

Failure is an option (exceptions are good)

Exceptions raised within your tests will appear in the failed totals, so you don't need to worry about trying to catch them in your own custom steps.

i.e. if you try fetching a page on a server that is down, or the page returns a 404, the exception raised by Mechanize just gets treated by Cucumber as a test failure.

Using the Steps in another Cucumber suite

If you want to use the steps shipped with cucumber-nagios elsewhere, you can require them by adding the following line to features/support/env.rb like so:

require 'cucumber/nagios/steps'

Or just require the steps you care about:

require 'cucumber/nagios/steps/ssh'
require 'cucumber/nagios/steps/ping'

Using the Formatter in another Cucumber suite

Once installed as a gem, the cucumber-nagios formatter is available in any other Cucumber test suite:

cucumber --format Cucumber::Formatter::Nagios features/foo.feature

Version control

It's strongly recommend that you store your cucumber-nagios projects in a version control system!

To get up and running with git:

$ git init
$ git add .
$ git commit -m 'created cucumber-nagios project'

.gitignore is created when you generate a project.

Testing

The gem is thoroughly tested (with Cucumber, no less). The gem's Cucumber features live in $gemroot/features/, and can be run with:

$ cucumber features/installing.feature
$ cucumber features/creating.feature
$ cucumber features/using.feature

Contributing

See the HACKING file.

More Repositories

1

visage

Graph collectd metrics in the browser, backed by a JSON API
JavaScript
382
star
2

collectd-opentsdb

collectd writer plugin for OpenTSDB
Java
24
star
3

rails-puppet-quickstart

to kickstart getting your Rails app up and running ASAP
15
star
4

nswbushfires

Twitter bot for posting current incidents from the NSW bushfires website
Ruby
7
star
5

cucumber-scripting

6
star
6

junk

Tools that keep the world turning
Ruby
5
star
7

collectd-sidekiq-plugin

A collectd exec plugin to query Sidekiq general and queue statistics
Go
5
star
8

rump

Do Puppet runs locally from a Git checkout
Ruby
5
star
9

gotgastro.com

[DEPRECATED] source to Gastro, a mashup of the NSW Food Authority's name-and-shame lists
Ruby
3
star
10

dnsmanager

Ruby
3
star
11

cucumber-nagios-spork-experiment

Experiment to see how well cucumber-nagios works with Spork
Ruby
2
star
12

boxed-view

ABC iView app for Boxee
2
star
13

programmingc

Worked exercises from UTS Programming C course
C
2
star
14

unblockus-updater

Updates Unblock-Us with your current IP address
Go
2
star
15

gastro

Find out about food safety problems when eating out or buying food
Ruby
2
star
16

sa_health_food_prosecutions_register

South Australian Department of Health's food prosecution register
Ruby
2
star
17

flapjack-project.com

Flapjack website
Ruby
2
star
18

chef-torrents

config for my own VPS doing torrents
Ruby
1
star
19

docs.flapjack-project.com

autogeneration of docs for flapjack-project.com
Ruby
1
star
20

example-resume

An example resume built with GitHub Pages.
CSS
1
star
21

epilog

Epilog is a simple log viewing application and a log collector
JavaScript
1
star
22

okbye

Web interface for notmuch
Ruby
1
star
23

collectd-mikrotik

Minimal collectd just for fetching statistics from Mikrotik RouterOS and sending them elsewhere via the `network` plugin
Makefile
1
star
24

gem2deb

thought experiment on building a RubyGems to Debian package converter
Ruby
1
star
25

rump-demo

1
star
26

australian_federal_mp_property_interests

Property interests for Australian federal member of parliament, as curated by ABC
HTML
1
star
27

laptop-death-tally-dashboard

Ruby
1
star