Help - I am unable to send notifications

jonathan williams jonathan.williams at us.g4s.com
Tue Jul 22 18:56:22 CEST 2008


On Tue, 2008-07-22 at 09:08 -0700, Matthew Macdonald-Wallace wrote:
> On Mon, 21 Jul 2008 07:47:00 -0700
> "Jonathan Williams" <jonathan.williams at us.g4s.com> wrote:
> 
> > sed: can't read check_sendmail.pl: No such file or directory
> 
> Are you in the correct directory?
> 
> Try running the following:
> 
> locate check_sendmail.pl
> 
> then cd to the directory that it gives you and run the sed command
> provided earlier.
> 
> M.
> --
> Matthew Macdonald-Wallace
> matthew at truthisfreedom.org.uk
> http://www.truthisfreedom.org.uk
> 
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the
> world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Nagios-users mailing list
> Nagios-users at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nagios-users
> ::: Please include Nagios version, plugin version (-v) and OS when
> reporting any issue.
> ::: Messages without supporting info will risk being sent to /dev/null
> 
I am guessing (with all my vast linux experience...that's sarcasm) that
perhaps the send_mail.pl wrapper does not know how to find the actual
senmail file which is located in /usr/lib.  I don't see anything in the
send_mail.pl script that indicates it is looking for it though.  Here is
the send_mail.pl file contents:

#!/usr/bin/pearl -w
#
# Wriiten by Rob Moss, 2005-10-09
# coding at mossko.com
#
# A replacement for Nagios's basic mail system which relies
on /bin/mailx and local sendmail config
#
# To use this, just replace the entries in commands.cfg and update your
hosts and services from the default "notify-by-email" to use the
specific host-notify-by-email or service-notify-by-email
#
# I put this in the plugins directory /usr/local/nagios/libexec but you
can put it anywhere. Just update the path

# commands.cfg
#define command{
#	command_name	host-notify-by-email
#	command_line	$USER1$/send_mail.pl -n "HOST $NOTIFICATIONTYPE$" -h
"$HOSTNAME$"  -s "$HOSTSTATE$" -a "$HOSTADDRESS$" -i "$HOSTOUTPUT$" -d
"$LONGDATETIME$" -e "$CONTACTEMAIL$"
#}
#
#define command{
#	command_name	service-notify-by-email
#	command_line	$USER1$/send_mail.pl -n "SERVICE $NOTIFICATIONTYPE$" -h
"$HOSTNAME$" -s "$SERVICESTATE$" -a "$HOSTADDRESS$" -i "$SERVICEDESC$ -
$SERVICEOUTPUT$ - $SERVICECHECKCOMMAND$" -d "$LONGDATETIME$" -e
"$CONTACTEMAIL$"
#}

# contacts.cfg
#define contact{
#	contact_name					nagiosadmin
#	host_notification_commands		host-notify-by-email
#	service_notification_commands	service-notify-by-email
#	email							email at address.com
#}


use strict;
use Net::SMTP;
use Getopt::Std;

my $mailhost	=	192.168.1.9	;
my $maildomain	=	ems.securicor.com;
my $mailfrom	=	nagios_alerts at us.g4s.com;
my $mailto	=	jonathan.williams at us.g4s.com;
my $timeout		=	30;
my $mailsubject	=	'';	  						#	Leave blank
my $mailbody	=	'';							#	Leave blank
my $logfile		=	'/tmp/mail.log';		     		#	Put somewhere better
my $debug		=	1;						#	To enable SMTP session debugging to logfile


################################################################
# Email for nagios
#
# Subject: "Host $HOSTSTATE$ alert for $HOSTNAME$!" $CONTACTEMAIL$
#
# "***** Nagios  *****
# Notification Type: $NOTIFICATIONTYPE$
# Host: $HOSTNAME$
# State: $HOSTSTATE$
# Address: $HOSTADDRESS$
# Info: $HOSTOUTPUT$
# Date/Time: $LONGDATETIME$
#
#################################################################
#
# Commandline options
#
# -n	NOTIFICATIONTYPE
# -h	HOSTNAME
# -s	HOSTSTATE
# -a	HOSTADDRESS
# -i	HOSTOUTPUT
# -d	LONGDATETIME
# -e	CONTACTEMAIL
#
#################################################################


if (not open(LOG,">>$logfile") ) {
	$mailsubject = "Nagios Monitoring Alert: Can't open $logfile for
append: $!";
	print STDERR "Nagios Monitoring Alert: Can't open $logfile for append:
$!";
	sendmail();
	exit 1;
}


our ($opt_n, $opt_h, $opt_s , $opt_a , $opt_i , $opt_d , $opt_e);
# Get the cmdline options
getopt('nhsaide');
print LOG localtime() . " sending mail to $opt_e with host $opt_h state
$opt_s\n";

if (not defined $opt_n or $opt_n eq "") {
	print "option -n not defined!\n";
	$opt_n = "UNDEFINED";
}
elsif (not defined $opt_h or $opt_h eq "") {
	print "option -h not defined!\n";
	$opt_h = "UNDEFINED";
}
elsif (not defined $opt_s or $opt_s eq "") {
	print "option -s not defined!\n";
	$opt_s = "UNDEFINED";
}
elsif (not defined $opt_a or $opt_a eq "") {
	print "option -a not defined!\n";
	$opt_a = "UNDEFINED";
}
elsif (not defined $opt_i or $opt_i eq "") {
	print "option -i not defined!\n";
	$opt_i = "UNDEFINED";
}
elsif (not defined $opt_d or $opt_d eq "") {
	print "option -d not defined!\n";
	$opt_d = "UNDEFINED";
}
elsif (not defined $opt_e or $opt_e eq "") {
	die "CRITICAL: option -e not defined!.  Host $opt_h, Notification:
$opt_n, State: $opt_s, Info: $opt_i\n";
}

# You can change the subject here
$mailsubject	=	"Nagios Monitoring Alert: $opt_h is $opt_s";
$mailto			=	"$opt_e";



$mailbody = <<_END_;
***** Nagios  *****

Notification Type: $opt_n
Host: $opt_h
State: $opt_s
Address: $opt_a
Info: $opt_i
Date/Time: $opt_d
_END_


sendmail();
print LOG localtime() . " sent mail to $opt_e successfully\n";

exit 0;


#########################################################
sub sendmail {
	my $smtp = Net::SMTP->new(
								$mailhost,
								Hello => $maildomain,
								Timeout => $timeout,
								Debug   => $debug,
								);

	$smtp->mail($mailfrom);
	$smtp->to($mailto);

	$smtp->data();
	$smtp->datasend("To: $mailto\n");
	$smtp->datasend("From: $mailfrom\n");
	$smtp->datasend("Subject: $mailsubject\n");
	$smtp->datasend("\n");
	$smtp->datasend("$mailbody\n");
	$smtp->dataend();

	$smtp->quit;
}
> 

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list