You are here

Hipchat - Notification script

6 posts / 0 new
Last post
pcmerc's picture
Hipchat - Notification script

Created this today on request. Enjoy :D

# Mangle by John Gisler <>
my $usage = qq{
Copyright (C) 2003-2014 Opsview Limited. All rights reserved

Usage: submit_hipchat_script [-h] [-n]

-h - this help test
-n - do not send acknowledgements

Uses Nagios environment variables to construct the message to send and calls hipsaint

# Wrapper for hipsaint enabling you to send messages using the Hipchat API
# This script requires the 'hipsaint' utility -
# Eg:
# python install
# Copyright (C) 2003-2013 Opsview Limited. All rights reserved
# This file is part of Opsview
# Opsview is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# Opsview is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with Opsview; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

sub usage {
if ( $_ = shift ) { print "Error: $_\n" }
print $usage;
exit 1;

use strict;
use lib '/usr/local/nagios/perl/lib';
use strict;
use Getopt::Std;

my $command;
if ( -x '/usr/bin/hipsaint' ) {
$command = '/usr/bin/hipsaint';
else {
$command = '/usr/local/bin/hipsaint';
my $opts = {};

getopts( 'hn', $opts );

if ( $opts->{h} ) {

print 'Not sending acknowledgement', $/;
exit 0;

my $text;


else {



my $pagetype;
$pagetype = "service";
else {
$pagetype = "host";

my $token = "APIKEY";

my $room = "ROOMNAME";

# || die "Must have CONTACTPAGER for this notification script\n";

#my $command = "/bin/echo '$text' | $command -t $token -r $room -T $pagetype -i $text";
my $command = "$command -t $token -r $room -T $pagetype -i '$text' -n";
print "Running $command\n";
system($command) == 0 || die( 'Failed to run command: ', $!, $/ );

smarsh's picture
What does your notification

What does your notification method look like for this? Im guessing you need to replace APIKEY and ROOMNAME within the notification script, and not in the notification method via the GUI?

ive tested it out on my system here but cant seem to get it to work - wondering if its a hipsaint bin issue!

Cool stuff though :)


pcmerc's picture
Hi Sam. The notification

Hi Sam. The notification method is pretty plain.

Name: Hipchat Notification
Command: submit_hipchat_script - as this is the name of the script.

Yes, the ROOM & APIKEY are to be set in the script.

I do believe one could create new attributes to use for ROOM / APIKEY & add those variables to the script instead.

I'll have to test that.

What kind of errors are you seeing, if any?

I have hipsaint installed in /usr/local/bin


smarsh's picture
I have no idea why its not

I have no idea why its not working on my personal system, very odd! No notifications are being shown at all in nagios.log when i submit a check result - however when i run it via the command line it works:

root@opsview:/usr/local/nagios/libexec/notifications# ./notify_by_hipchat
Running /usr/local/bin/hipsaint -t apikeyhere -r Opsview -T host -i '|||||' -n


One thing I noticed, which may be due to my lack of CLI fu, is that when i have a room with a space, i.e. "All users", it threw an error:

Running /usr/local/bin/hipsaint -t apikeyhere -r All members -T host -i '|||||' -n
Traceback (most recent call last):
  File "/usr/local/bin/hipsaint", line 9, in <module>
    load_entry_point('hipsaint==0.4.7', 'console_scripts', 'hipsaint')()
  File "/usr/local/lib/python2.7/dist-packages/hipsaint-0.4.7-py2.7.egg/hipsaint/bin/", line 62, in main
  File "/usr/local/lib/python2.7/dist-packages/hipsaint-0.4.7-py2.7.egg/hipsaint/", line 49, in deliver_payload
    raw_response = urlopen(self.url, message_params)
  File "/usr/lib/python2.7/", line 126, in urlopen
    return, data, timeout)
  File "/usr/lib/python2.7/", line 406, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/", line 519, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/", line 444, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.7/", line 378, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/", line 527, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found
Failed to run command: No such file or directory


Even though I put the room name in double quotes in the script:

my $room = "All members";

But yeah, the script works it appears - its just that my Opsview doesnt want to use it :) Will try on a few other systems!



pcmerc's picture
Try escaping the spaces,

Try escaping the spaces, example: my $room = "All\ members";

pcmerc's picture
Or use underscores instead of

Or use underscores instead of spaces in the channel name.

Spaces are generally bad, I use underscore instead of spaces as code tends to not translate the usage of spaces easily, sometimes.