====== HTML Mail Alert ======
^ Author | [[wardmw@gmail.com|Martin Ward]] |
^ Compatibility | Xymon 4.2 |
^ Requirements | Perl, MIME::Lite |
^ Download | None |
^ Last Update | 2008-07-08 |
===== Description =====
===== Installation =====
- Place html_mail.pl in the ext/ directory in your xymon sever installation.
-Make the script executable:
chmod 755 html_mail.pl
- Add the following line in whichever alert for which you want messages
SCRIPT [XYMON_SERVER_ROOT]/ext/html_mail.pl [RECIPIENT] FORMAT=PLAIN
- And of course you replaced [XYMON_SERVER_ROOT] with the full path to your xymon server directory.
===== Source =====
=== html_mail.pl ===
#!/usr/bin/perl -w
# This perl script was taken from a shell/perl script combo that was originally
# authored by Andy France.
# I have modified it so that the workings of the shell script are done inside
# the perl script, thus removing one file and speeding up to processing.
#
# This script require the MIME::Lite Perl module, availablde from CPAN here:
# http://search.cpan.org/~rjbs/MIME-Lite-3.021/lib/MIME/Lite.pm
#
# Don't forget to update the first line in this script to point to the
# correct location for your Perl executable.
#
# This script should be installed in a known location and the following line
# added to the hobbit-alerts.cfg file:
# SCRIPT /opt/hobbit/server/ext/html_mail support@email.com FORMAT=PLAIN
#
# Version Author Details
# ------- ------ -------
# 1.0 Martin Ward Initial version. See code for details.
###############################################################################
# Uses and requires
use strict;
use MIME::Lite;
###############################################################################
# Global variables
my $RCPT; # The recipient's email address.
my $BBHOSTSVC; # HOSTNAME.SERVICE that the alert is about.
my $BBCOLORLEVEL; # The current color of the status.
my $HTML_BODY; # Holds the text for the BODY tag.
my $BBALPHAMSG; # The full text of the status log triggering the alert
my $BBHTMLMSG; # The full HTML text of the status log triggering the alert
my $ACKCODE; # The "cookie" that can be used to acknowledge the alert
my $BBHOSTNAME; # The name of the host that the alert is about
my $MACHIP; # The IP-address of the host that has a problem
my $BBSVCNAME; # The name of the service that the alert is about
my $BBSVCNUM; # The numeric code for the service. From SVCCODES definition.
my $BBHOSTSVCCOMMAS; # As BBHOSTSVC, but dots in the hostname replaced
# with commas.
my $BBNUMERIC; # A 22-digit number made by BBSVCNUM, MACHIP and ACKCODE.
my $RECOVERED; # Is "1" if the service has recovered.
my $EVENTSTART; # Timestamp when the current status (color) began
my $DOWNSECS; # Number of seconds the service has been down.
my $DOWNSECSMSG; # When recovered, holds the text "Event duration : N"
# where N is the DOWNSECS value.
my $CFID; # Line-number in the hobbit-alerts.cfg file that caused the
# script to be invoked. Can be useful when troubleshooting
# alert configuration rules.
###############################################################################
# send_email - Creates a MIME-compatible email using $HTML_BODY, which we
# created in another subroutine, and $BBALPHAMSG, which is the plain text
# version. It then adds in any icons required to display the MIME email
# and sends it off.
sub send_email {
my $subject = $BBHOSTSVC . " " . $BBCOLORLEVEL;
my $htmldata = join("",
"$HTML_BODY\n",
"\n",
"
\n",
$BBHTMLMSG,
"\n",
"
\n",
"\n",
"