Cucumber

March 2nd, 2009 by kartar Leave a reply »

It’s well known that I am not a fan of Cucumber – tends to make me come out in hives.  However, I’ve come across a very cool Cucumber of the non-vegetable Ruby (and hence not edible) variety that has some awesome possibilities.

So what is Cucumber?  It’s a behaviour driven development and testing tool that uses plain English language to describe testing scenarios (a la RSpec) and do the resulting “story running”.

But the goodness isn’t limited to those rascally developers.  It’s an excellent tool for sys-admins to do systems testing.  And to prove it along comes cucumber-nagios.  Developed by Lindsay Holmwood (who is an open source guy in Australia and a Puppet person) it is designed to allow Cucumber to output using the Nagios plug-in API.

First, Lindsay has some cool stuff in this blog post but here’s another example I cooked up.  Hypothetically, we might have a web page created on our site and we need to ensure users can click through to a link on it.  We also want to be sure that linked page contains a section with some information we want to share with our customers:

Feature:
  It should be up
  And I should be able to reach the interest rates page
  And it should contain a "Daily Rates" section

  Scenario: Reaching the rates page
    When I visit "www.interbanking.com.au"
    And I click on "Rates"
    Then I should visit "www.interbanking.com.au/rates.html"
    And then I should see a section called "Daily Rates"

This would then be run:

$ cucumber-nagios features/interbanking.com.au/rates.feature
Critical: 0, Warning: 0, 4 okay | value=4.000000;;;;

You can see it would return an appropriate Nagios plug-in output.

And voila! Cheap and easy website script testing which plugs into our enterprise monitoring system.

Multiply this with all of the other things Cucumber can script and story board and you have a powerful engine to monitor complex elements of your environment.

P.S. Related to this that I stumbled across recently is Cucumber and Dash integration.  Dash is a mechanism for creating and measuring custom metrics and  Bradley (@ RailsMachine) has a couple of posts that show how to integrate Sensor, Cucumber, Dash and cucumber-nagios!


				
      	
			

5 comments

  1. Hey, neat – cool example.

    Bradley makes a really good point when talking about Dash and Cucumber that’s worth repeating here: “Instead of writing boring monitoring plugins from scratch, you can now do behavior driven ops!”

    This is pretty much exactly what I was trying to achieve with cucumber-nagios.

    I’m thinking of putting together some other examples testing LDAP and mail too. ;-)

    • kartar says:

      Yeah I’ve been thinking and talking about this a lot – systems testing should be about behaviour not about metrics. Who cares if the host is up and reports normal load if it doesn’t do the ACTUAL job it’s designed to: serve web pages, send and receive email, resolve hosts, authenticate, backup and restore, etc, etc.

  2. Damn right. It’s the way software developers have been doing testing for a while now. It’s something I think a lot of sysadmins implicitly know but don’t always recognise.

    Hopefully cucumber-nagios will help make it a bit more obvious. :-)

  3. kartar says:

    I could extend that example too I suspect:

    Feature:
      It should be up
      And I should be able to reach the interest rates page
      And it should contain a "Daily Rates" section
    
      Scenario: Reaching the rates page
        When I visit "www.interbanking.com.au"
        And I click on "Rates"
        Then I should visit "www.interbanking.com.au/rates.html"
        And then I should see a section called "Daily Rates"
    

    With another feature:

    Feature:
      The "Daily Rates" section should contain a DailyRate value
      The DailyRate value should match the value from production.db.rates.dailyrate
    
      Scenario: Checking the DailyRate value
        When I visit "www.interbanking.com.au/rates.html"
        Then I should see a section called "Daily Rates"
        In the "Daily Rates" I should see a value called DailyRate
        When I check the value of DailyRate it should match x value
    

Leave a Reply