Вы находитесь на странице: 1из 3

Setting up Nagios to notify using Google Talk for Domains via a HTTP proxy

Nagios can be used to notify via Jabber servers using existing scripts, however Google Talk for Domains can be used as a notifier with a few changes to them. There are 2 parts to this script - the notification commands and the script itself. The script shown as source code should be stored in an executable file on the nagios server, and the commands here should be entered into a Nagios config file (with the path altered to reflect where you saved the main script). You will need to edit the proxy address, the username, password and your google domain name. Also, for this to run, you need the 'netxmpp' library (in Ubuntu this package is libnet-xmpp-perl). # 'host-notify-by-jabber' command definition 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$" }

#!/usr/bin/perl -w # # script for nagios notify via Jabber / Google Talk Instant Messaging # using XMPP protocol and SASL PLAIN authentication. # # author: Andrew Elwell <A.Elwell@physics.gla.ac.uk> # based on work by Thus0 <Thus0@free.fr> 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 <localzuk@gmail.com> 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]); }

Вам также может понравиться