Nagios notify-by-campfire Plugin

By eric

Since one of the core communication methods for my company amongst engineers is 37Signals Campfire and Nagios is one of our main monitoring tools for all of our applications and services, I thought it would be a good idea to combine the two. So with a few simple additions to the Nagios configuration and a Ruby Campfire script, you can get this up and running.

On the Campfire side, I will leave the exercise of adding a Campfire user up to you. You may need to go through your Campfire administrator for that.

On the Nagios side, the first thing that needs to happen is that you need to add the following commands to your command.cfg file in your Nagios configuration. Make sure that you specify the proper location of your notify-by-campfire.rb file.

1
2
3
4
5
6
7
8
9
10
11
# 'notify-host-by-campfire' command definition
define command{
    command_name    notify-host-by-campfire
    command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/local/bin/ruby /usr/local/bin/notify-by-campfire.rb -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **"
    }

# 'notify-service-by-campfire' command definition
define command{
    command_name    notify-service-by-campfire
    command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/local/bin/ruby /usr/local/bin/notify-by-campfire.rb -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **"
    }

Add this contact template definition for the Campfire contact to your contacts.cfg. Don’t forget to add it to a contactgroup.

1
2
3
4
5
6
7
8
9
10
define contact{
        name                            campfire-contact
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r,f,s
        host_notification_options       d,u,r,f,s
        service_notification_commands   notify-service-by-campfire
        host_notification_commands      notify-host-by-campfire
        register                        0
        }

The Ruby code for notify-by-campfire.rb is here. Just install it wherever you’d like and as I said above, make sure its specified properly in your commands.cfg.

Note: I am aware that I could have made this script much shorter, but my goal is to make this extensible should I want to provide more information or change the format. Feel free to modify for your own usage.

Update (2010-05-17): To make it a little easier to read in the context of a smaller Campfire window, I have amended the notify-host-by-campfire and notify-service-by-campfire entries to be shorter:

1
2
3
4
5
6
7
8
9
10
11
# 'notify-host-by-campfire' command definition
define command{
    command_name    notify-host-by-campfire
    command_line    /usr/bin/printf "%b" "Date/Time: $LONGDATETIME$\n\nHost: $HOSTNAME$\nType/State: $NOTIFICATIONTYPE$/$HOSTSTATE$\n\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/local/bin/ruby /usr/local/bin/notify-by-campfire.rb -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ ($HOSTADDRESS$) is $HOSTSTATE$ **"
    }

# 'notify-service-by-campfire' command definition
define command{
    command_name    notify-service-by-campfire
    command_line    /usr/bin/printf "%b" "Date/Time: $LONGDATETIME$\nType/State: $NOTIFICATIONTYPE$/$SERVICESTATE$\n\n$SERVICEOUTPUT$" | /usr/local/bin/ruby /usr/local/bin/notify-by-campfire.rb -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ ($HOSTADDRESS$) is $SERVICESTATE$ **"
    }

Follow My Travels

Buy My Book

Archives

  • 2020
  • 2019
  • 2017
  • 2014
  • 2013
  • 2012
  • 2011
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006

New Posts By Email

writing