alerts:gtalk

My Alert (CHANGEME)

Author Justin Funk
Compatibility Xymon 4.2
Requirements Perl, Net::XMPP
Download None
Last Update 2009-09-29

Send Xymon Alerts to GTalk via XMPP.

This script requires Perl and Net::XMPP

  1. Install Net::XMPP via CPAN with:
    perl -MCPAN -e "install Net::XMPP"
  2. Place gtalk_alert.pl in the ext/ directory in your xymon sever installation.
  3. Replace USERNAME and PASSWORD in the gtalk_alert.pl script with the username and password of your alerting google account. (HINT: create a new account to just send alerts- that way you won't have to store your e-mail account password in plain test).
  4. Make the script executable:
    chmod 755 gtalk_alert.pl
  5. Add the following line in whichever alert for which you want messages
      SCRIPT [XYMON_SERVER_ROOT]ext/gtalk_alert.pl [RECIPIENT] FORMAT=SMS
  6. And of course you replaced [XYMON_SERVER_ROOT] with the full path to your xymon server directory and [RECIPENT] with the google account that you want to recieve messages.

Show Code ⇲

Hide Code ⇱

#!/usr/bin/perl -w
#
# A script to send BB alerts to a GTalk client
# @author Justin Funk
# @date   9/29/2009
#
#
# Based off of work by  Thus0 <Thus0@free.fr>
# <http://www.pervasive-network.org/SPIP/Google-Talk-with-perl-bis>
# Copyright (c) 2005, Thus0 <thus0@free.fr>. All rights reserved.
# released under the terms of the GNU General Public License v2
#
# The script get the following environment variables pre-defined so
# that they can send a meaningful alert:
#
#    BBCOLORLEVEL  - The color of the alert: "red", "yellow" or "purple"
#    BBALPHAMSG    - The full text of the status log triggering the alert
#    ACKCODE       - The "cookie" that can be used to acknowledge the alert
#    RCPT          - The recipient, from the SCRIPT entry
#    BBHOSTNAME    - The name of the host that the alert is about
#    MACHIP        - The IP-address of the host that has a problem
#    BBSVCNAME     - The name of the service that the alert is about
#    BBSVCNUM      - The numeric code for the service. From SVCCODES definition.
#    BBHOSTSVC     - HOSTNAME.SERVICE that the alert is about.
#    BBHOSTSVCCOMMAS - As BBHOSTSVC, but dots in the hostname replaced with commas
#    BBNUMERIC     - A 22-digit number made by BBSVCNUM, MACHIP and ACKCODE.
#    RECOVERED     - Is "1" if the service has recovered.
#    DOWNSECS      - Number of seconds the service has been down.
#    DOWNSECSMSG   - When recovered, holds the text "Event duration : N" where
#                    N is the DOWNSECS value.
 
 
use strict;
use Net::XMPP;
 
## Username and Password of Account
## an account specificlly for alerts can be made at
## https://www.google.com/accounts/NewAccount
my $username = "USERNAME";
my $password = "PASSWORD";
 
## Get recipent from hobbit-alerts.cfg
my $to = $ENV{'RCPT'};
 
 
my $resource = "PerlBot";
 
## Google Talk Configuration
my $hostname = 'talk.google.com';
my $port     = 5222;
my $componentname = 'gmail.com';
my $connectiontype = 'tcpip';
my $tls = 1;
 
## Setup and connect
my $Connection = new Net::XMPP::Client();
my $status = $Connection->Connect(
  hostname => $hostname, port => $port,
  componentname => $componentname,
  connectiontype => $connectiontype, tls => $tls);
 
## If connection failed- quit
if (!(defined($status))) {
  print "ERROR: XMPP connection failed.\n";
  print "       ($!)\n";
  exit(0);
}
 
 
my $sid = $Connection->{SESSION}->{id};
$Connection->{STREAM}->{SIDS}->{$sid}->{hostname} = $componentname;
 
## Authenticate with Google
my @result = $Connection->AuthSend(
  username => $username, password => $password,
  resource => $resource);
 
## If failure
if ($result[0] ne "ok") {
  print "ERROR: Authorization failed: $result[0] - $result[1]\n";
  exit(0);
}
 
## Send the message
$Connection->MessageSend(
  to => "$to\@$componentname", body => $ENV{'BBALPHAMSG'},
  resource => $resource);
  • 2009-09-29
    • Initial release
  • alerts/gtalk.txt
  • Last modified: 2009/11/23 06:48
  • by 127.0.0.1