Casey Bralla wrote:
I've just set up mon to eMail me alerts when one of my services goes down. However, the From line lists the mail as coming from "[EMAIL PROTECTED]". How can I customize this to say something meaningful?

I once received a much enhanced mail.alert version from someone on this list (see header of attached version). Even in the enhanced version there was no variable to set the from/reply-to fields. So I hard-coded it into the script. Have a look at the source and you will easily find the lines. With a little Perl knowledge it should be an easy exercise to make the fields optional and set by script options.

Kevin
--
   _             |  Kevin Ivory          |  Tel: +49-551-3700000
  |_     |\ |    |  Service Network GmbH |  Fax: +49-551-3700009
  ._|ER  | \|ET  |  Bahnhofsallee 1b     |  mailto:[EMAIL PROTECTED]
 Service Network |  37081 Goettingen     |    http://www.SerNet.de/
#!/usr/bin/perl
#
# mail2.alert - Improved Mail alert for mon
#
# The first line from STDIN is summary information, adequate to send
# to a pager or email subject line.
#
# Mark Lawrence, [EMAIL PROTECTED] - based on the original from:
# Jim Trocki, [EMAIL PROTECTED]
#
# $Id: mail.alert 1.1 Sat, 26 Aug 2000 15:22:34 -0400 trockij $
#
#    Copyright (C) 1998, Jim Trocki
#
#    This program 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.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
$RCSID='$Id: mail.alert 1.1 Sat, 26 Aug 2000 15:22:34 -0400 trockij $';


### Extra Perl packages ###

use Getopt::Std;
use Text::Wrap;
use Text::Tabs;


### A function to pretty-print statements of the form "Field: value" ###

$Text::Wrap::columns = 72;
$colwidth = 18;
$fillspec = "\%-${colwidth}s\ ";
$fill     = sprintf($fillspec, " ");

sub wprint {
        my($description, $string) = @_;
        $description = $description . ":";
        return expand wrap ("", $fill, sprintf("${fillspec}\%s",
                                $description, $string)), "\n";
}


### Evaluate command-line options and environment values ###

getopts ("S:s:g:h:t:l:u");

$summary=<STDIN>;
chomp $summary;
$summary = $opt_S if (defined $opt_S);
$mailaddrs = join (',', @ARGV);

$ALERT = $ENV{"MON_ALERTTYPE"};

$firstfailt = $ENV{"MON_FIRST_FAILURE"};
$firstfail  = localtime($firstfailt);

my $sec    = $opt_t - $firstfailt;

my $days   = int($sec/(24*60*60)); 
$days      = $days > 0 ? ($days . " day" . ($days > 1 ? "s " : " ")) : "";

my $hours  = ($sec/(60*60))%24;
$hours     = $hours > 0 ? ($hours . " hour" . ($hours > 1 ? "s " : " ")) : "";

my $mins   = ($sec/60)%60;
$mins      = $mins > 0 ? ($mins . " min" . ($mins > 1 ? "s " : " ")) : "";

my $secs   = $sec%60;
$secs      = $secs > 0 ? ($secs . " sec" . ($secs > 1 ? "s " : " ")) : "";

my $length = $days . $hours . $mins . $secs;

if ($sec == 0) {
        $length = "0";
}


$t = localtime($opt_t);
($wday,$mon,$day,$tm) = split (/\s+/, $t);

$subject = uc($ALERT) . ": $opt_g $opt_s: $summary";


### Create the email ###

open (MAIL, "| /usr/sbin/sendmail -oi -t") ||
    die "could not open pipe to mail: $!\n";

print MAIL <<EOF;
To: $mailaddrs
Subject: $subject
From: [EMAIL PROTECTED]
Reply-To: [EMAIL PROTECTED]
X-Mailer: $0
X-Precedence: list

EOF

# This is missing somewhere
# Next alert in : $opt_l

print MAIL wprint("Notice Summary", $summary);
print MAIL wprint("Notice Date", $t);

if ($opt_g ne $opt_h) {
        print MAIL wprint("Group", $opt_g);
} else {
        print MAIL wprint("Device", $opt_g);
}

if ($ENV{MON_DESCRIPTION} ne "") {
        print MAIL wprint("Description", $ENV{MON_DESCRIPTION});
}

print MAIL wprint("Service", $opt_s);

if ($opt_g ne $opt_h) {
        print MAIL wprint("Hostgroup Members", $opt_h);
}

print MAIL wprint("Failure detected", $firstfail);

if ($opt_u) {
        print MAIL wprint("Restore detected", $t);
        print MAIL wprint("Length of Failure", $length);
} else {
        print MAIL wprint("Current downtime", $length);
}

print MAIL "\n(Detailed output follows, if any)\n\n";

#
# The remaining lines normally contain more detailed information,
# but this is monitor-dependent.
#
while (<STDIN>) {
    print MAIL;
}

close (MAIL);
_______________________________________________
mon mailing list
[EMAIL PROTECTED]
http://linux.kernel.org/mailman/listinfo/mon

Reply via email to