Hi Jim Trocki!
First, this mon tool is great.
I have write an mailsrv.alert script because i have many dns domains and
many smtp server.
eg. palmers.de and palmers.at
Between this domain�s there is an isdn dialup connection, so i sould not
monitoring
remote site... costs !
Every domain has one mailserver and one mon server, but my problem was,
when the smtp daemon was dead, i never received e-mails.
So, in the mailsrv.alert script i have an smtp host, where to send mails.
# 192.168.190.10 florix.palmers.de
#
# 172.20.5.120 mailsweeper.palmers.at
hostgroup mailhost 192.168.190.10
watch mailhost
service smtp
interval 15s
monitor smtp.monitor
description simple mail transfer (florix.palmers.de)
period wd {Sun-Sat}
alertevery 2m
alert mailsrv.alert [EMAIL PROTECTED]
server=172.20.5.120
upalert mailsrv.alert [EMAIL PROTECTED]
server=172.20.5.120
period LOGFILE: wd {Sun-Sat}
alert file.alert -d /usr/local/mon/log.d smtp.log
upalert file.alert -d /usr/local/mon/log.d smtp.log
It seems to work for me, and the scripts mon.cgi and monshow give me
the right result. I hope the perl code is correct. I am a newbie in perl
programing.
Hier is the code:
mailsrv.alert
#!/usr/bin/perl
#
# mailsrv.alert - Mail alert for mon with an alternate smtp server
#
# The first line from STDIN is summary information, adequate to send
# to a pager or email subject line.
#
# Markus Lehmann, [EMAIL PROTECTED]
#
# $Id: mailsrv.alert 0.4 Di, 18 Dec 2001 14:00:11 -1430 le $
#
# Copyright (C) 2001, Markus Lehmann
#
# 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
#
use Getopt::Std;
use Mail::Sendmail;
use Sys::Hostname;
getopts ("s:g:h:t:l:u");
if ($#ARGV <=0) {
print STDERR "Problems with Options, e.g markus.lehmann\@palmers.at
nwbtr\@palmers.at server=172.20.5.57, sorry\n";
exit 1;
}
$summary=<STDIN>;
chomp $summary;
$t = localtime($opt_t);
($wday,$mon,$day,$tm) = split (/\s+/, $t);
$mailaddrs = join (',', @ARGV);
(@srv) = split (/\,/, $mailaddrs);
$i = 1;
$srvfind = "no";
$to = "";
foreach $entry (@srv) {
if ($entry =~ '=') {
($temp,$server) = split(/\=/, $entry);
if ($temp eq "server") { $srvfind = "yes"; }
} else {
if ($i < $#srv) {
$to = $to."$entry,";
} else {
$to = $to."$entry";
}
}
$i ++;
};
if ($srvfind eq "no") {
print STDERR "Problems with Options, e.g markus.lehmann\@palmers.at
nwbtr\@palmers.at server=172.20.5.57, sorry\n";
exit 1;
}
$ALERT = $opt_u ? "UPALERT" : "ALERT";
$whoami = $ENV{USER} || $ENV{LOGNAME} || $ENV{USERNAME};
unless ($whoami) { $whoami = getlogin || getpwuid($<) || 'unknown'; }
$host=`hostname`;
chop $host;
# if hostname has no dots then run it through gethostbyname to turn it
# into a fully-qualified name.
if ( $host =~ /^[^.]+$/ ) {
($host,$junk) = gethostbyname("$host");
}
$mail{From} = $whoami.'@'.$host;
$mail{To} = "$to";
$mail{Smtp} = $server;
$mail{Subject} = "$ALERT $opt_g/$opt_s: $summary ($wday $mon $day $tm)
$0";
$mail{Message} = "Summary output : $summary\n";
$mail{Message} .= "Group : $opt_g\n";
$mail{Message} .= "Service : $opt_s\n";
$mail{Message} .= "Time noticed : $t\n";
$mail{Message} .= "Secs until next alert : $opt_l\n";
$mail{Message} .= "Members : $opt_h\n\n";
$mail{Message} .= "This alert was sent because service was restored\n" if
($opt_u);
if (!$opt_u) {
while (<STDIN>) {
$mail{Message} .= $_;
}
}
if (sendmail %mail) {
# print STDOUT "content of $Mail::Sendmail::log:
$Mail::Sendmail::log\n";
if ($Mail::Sendmail::error) {
print STDERR "content of \$Mail::Sendmail::error:
$Mail::Sendmail::error";
}
exit 0;
} else {
print STDERR "!Error sending mail: $Mail::Sendmail::error";
exit -1;
}
Is there an mistake please inform me. Apologize my bad english.
Thanks
Markus Lehmann
Netzwerkmanagment
PALMERS TEXTIL AG
A-2351 Wiener Neudorf
Palmersstrasse 6-8
Tel.: +43 (2236) 63 500 244
Fax.: +43 (2236) 63 533 244
@mail: [EMAIL PROTECTED]
http://www.palmers-shop.com
PS: look at http://www.sins.com.au/nmis/.
Also a greate monitoring tool for routers and switches.
I do integrate the mon service tool into nmis.