Random thoughts of a warped mind…

December 19, 2011

Post messages from Ruby to Hipchat

Filed under: All,Development,Linux,Ruby — Srinivas @ 18:43

Hipchat is a hosted group chat and IM for teams. It allows you to create rooms (public/private) and use this for collaboration or notifications (thats really upto you!). You can have Git,Pivotal and several build systems log directly to Hipchat on rooms that you/your_team frequent. I find this pretty useful to post messages from my Nagios instance (so they dont clutter up my email!). Either way, if hipchat senses that you are not logged in or are away from your computer, the messages end up in your email so you are not going to lose any notifications.

If you have a Hipchat account, have your admin generate an API key for you (Keys can be of Notification or Admin type, Notification type will do for our purposes here. You can use Admin type keys to automate your hipchat setup, add users etc if you want to do that sorta thing). Assuming your HipChat key is “ABCDEFGH”…

Make sure to install the hipchat-api gem via

<br />gem install hipchat-api<br />

Modify the following code to suit your purposes…

Save the above as a program called hipchat_notify.rb and chmod it 555 on the box where you run Nagios.

Then add the following sections to commands.cfg on Nagios (assuming you use Nagios 3):

<br />define command{<br /><%%KEEPWHITESPACE%%>        command_name    notify-host-by-hipchat<br /><%%KEEPWHITESPACE%%>        command_line    /pathto/hipchat_notify.rb --type host --inputs "$HOSTNAME$|$LONGDATETIME$|$NOTIFICATIONTYPE$|$HOSTADDRESS$|$HOSTSTATE$|$HOSTOUTPUT$" -n<br /><%%KEEPWHITESPACE%%>        }<br /><br />define command{<br /><%%KEEPWHITESPACE%%>        command_name    notify-service-by-hipchat<br /><%%KEEPWHITESPACE%%>        command_line    /pathto/hipchat_notify.rb --type service --inputs "$SERVICEDESC$|$HOSTALIAS$|$LONGDATETIME$|$NOTIFICATIONTYPE$|$HOSTADDRESS$|$SERVICESTATE$|$SERVICEOUTPUT$" -n<br />}<br />

Now you can add a single user (or modify an existing one) by editing the Nagios contacts.cfg file and changing that users service and host notification commands to those we created above.

<br />define contact{<br /><%%KEEPWHITESPACE%%>        contact_name                    srinivas<br /><%%KEEPWHITESPACE%%>        alias                           Srinivas<br /><%%KEEPWHITESPACE%%>        ....<br /><%%KEEPWHITESPACE%%>        .....<br /><%%KEEPWHITESPACE%%>      service_notification_commands   notify-service-by-hipchat<br /><%%KEEPWHITESPACE%%>        host_notification_commands      notify-host-by-hipchat<br /><%%KEEPWHITESPACE%%>        email   /dev/null<br /><%%KEEPWHITESPACE%%>        }<br />

Bounce Nagios and expect to start seeing notification messages on Hipchat… No more inbox clutter or refreshing your Nagios pages repeatedly :-)

  • http://petey5king.github.com Petey5King

    This is a great post thanks a lot for this configuration!


  • Srinivas

    Glad you found it helpful Pete… :-)

  • Pingback: servinion()

  • http://www.fscity.de The most perfect Free Internetsite

    Heya i am for the primary time here. I found
    this board and I find It truly helpful & it helped me out
    much. I’m hoping to give one thing again and help others like you aided me.

Powered by WordPress