Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Nagios notify by Google Chat (with HTTP proxy, and google apps domains)


Recommended Posts

Posted

As our mail system is google apps, and therefore includes the Google Talk system, I decided to have a play with getting this working with Nagios notifications. After reading the information here about using it with Jabber, I made some changes to get it to work within a typical school network. Namely, one with a proxy server and one with a custom domain.

 

The result is below.

 

Nagios command definitions remain the same as the above link:

 

[color=#000000]# 'host-notify-by-jabber' command definition[/color]
define command{        
command_name    host-notify-by-jabber        
command_line    /usr/local/bin/notify_via_jabber $CONTACTPAGER$ "Host '$HOSTALIAS$' is $HOSTSTATE$ - Info: $HOSTOUTPUT$"        
}

# 'notify-by-jabber' command definition
define command{        
command_name    notify-by-jabber        
command_line    /usr/local/bin/notify_via_jabber $CONTACTPAGER$ "$NOTIFICATIONTYPE$ $HOSTNAME$ $SERVICEDESC$ $SERVICESTATE$ $SERVICEOUTPUT$ $LONGDATETIME$"        
}

 

The below is the modified script. This needs putting into a file wherever you normally store your plugins for nagios (and the above editing to reflect this). This file needs execute permissions applying to it for the nagios user.

 

#!/usr/bin/perl -w
#
# script for nagios notify via Jabber / Google Talk Instant Messaging
#   using XMPP protocol and SASL PLAIN authentication.
#
# author: Andrew Elwell 
# based on work by Thus0  and  David Cox
#
# released under the terms of the GNU General Public License v2
# Copyright 2007 Andrew Elwell.

# Edits for Google Apps Domains and for use of a http proxy
# by Tony Ayre  Feb 2012


use strict;
use Net::XMPP;
$ENV{'https_proxy'} = 'http://proxy:8080';


## Configuration
my $username = "username";
my $password = "password";
my $componentname = 'customdomain.com';
my $resource = "nagios";
## End of configuration




my $len = scalar @ARGV;
if ($len ne 2) {
  die "Usage...\n $0 [jabberid] [message]\n";
}
my @Field=split(/,/,$ARGV[0]);
#------------------------------------


# Google Talk & Jabber parameters :


my $hostname = 'talk.google.com';
my $port = 443;
my $connectiontype = 'http';
my $tls = 0;
my $ssl = 1;


#------------------------------------


my $Connection = new Net::XMPP::Client();


# Connect to talk.google.com
my $status = $Connection->Connect(
      hostname => $hostname, port => $port,
      componentname => $componentname,
      connectiontype => $connectiontype,
      tls => $tls,
      ssl => $ssl);


if (!(defined($status))) {
  print "ERROR:  XMPP connection failed.\n";
  print "        ($!)\n";
  exit(0);
}


# Change hostname
my $sid = $Connection->{SESSION}->{id};
$Connection->{STREAM}->{SIDS}->{$sid}->{hostname} = $componentname;


# Authenticate
my @result = $Connection->AuthSend(
      username => $username, password => $password,
      resource => $resource);



if ($result[0] ne "ok") {
  print "ERROR: Authorization failed: $result[0] - $result[1]\n";
  exit(0);
}


# Send messages
foreach ( @Field ) {
$Connection->MessageSend(
       to       => "$_\@$componentname",
       resource => $resource,
       subject  => "Notification",
       type     => "chat",
       body     => $ARGV[1]);
}

 

To use it with your contacts in nagios, set the 'pager' value for any contacts to their google apps username (without the domain name). Also, you'll need to assign the 2 commands listed above to those users.

  • Thanks 3

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...