View Source

The the host-notify-by-sendemail & service-notify-by-sendemail commands use the sendEmail perl script to send email notifications. sendEmail has many options that can be used to configure sending email for more complex mail system requirements, including using an external smtp server to send email.

To use an external smtp server you will need to add the \-xu, and \-xp flags to the sendEmail command. We will also need to set user macros to represent the parameters we need to pass to sendEmail. In this example we will use USER13 for the smtp server, USER14 for the SMTP username & USER15 as the SMTP password.

# Update the resource macros
## Navigate to Configuration > Control > Nagios Resource Macros
## Enter the fqdn hostname or ip address of the smtp server you wish to use into USER13. Using an IP address tends to be more resilient to local DNS failures.
## Enter the SMTP username you will use to send email with into USER14
## Enter the SMTP password you will use to send email with into USER15
# Update the \*-notify-by-sendemail commands to use the new parameters
## Navigate to Configuration > Commands > Copy
## Select 'host-notify-by-sendemail'
### Set the new command name to 'host-notify-by-sendemail-smtp'
### type should be left as 'notify'
### Change the new command definition to:
{code}
/usr/bin/printf "%b" "<html><b>+++++ HOST $NOTIFICATIONTYPE$ : $HOSTSTATE$
+++++<br>$LONGDATETIME$</b><br>Host: <b>$HOSTALIAS$ ($HOSTADDRESS$)</b></b><br>Message:
<b>$HOSTOUTPUT$</b></html>" | /usr/local/groundwork/common/bin/sendEmail -s $USER13$
-xu $USER14$ -xp $USER15$ -q -f $ADMINEMAIL$ -t $CONTACTEMAIL$ -u "[GW] ++ $HOSTNAME$ :
$HOSTSTATE$ ++"
{code}
### Click 'Add'
## Now do the same to copy the 'service-notify-sendemail' to 'service-notify-by-sendemail-smtp'
### Use the following new command definition
{code}
/usr/bin/printf "%b" "<html><b>+++++ SERVICE $NOTIFICATIONTYPE$ : $SERVICESTATE$
+++++<br>$LONGDATETIME$</b><br>Host: <b>$HOSTALIAS$ ($HOSTADDRESS$)</b></b><br>Message:
<b>$SERVICEOUTPUT$</b></html>" | /usr/local/groundwork/common/bin/sendEmail -s $USER13$
-xu $USER14$ -xp $USER15$ -q -f $ADMINEMAIL$ -t $CONTACTEMAIL$ -u "[GW] ++ $HOSTNAME$ :
$SERVICEDESC$ : $SERVICESTATE$ ++"
{code}
### Click 'Add'

Now you should be able to use the *host-notify-by-sendemail* and *service-notify-by-sendemail* commands in your contact templates for notifications.

{{Configuration \-> Contacts \-> Contact templates \-> modify \-> NameOfTemplate}}

Or for individual contacts:

{{Configuration \-> Contacts \-> Contacts \-> modify \-> NameOfContact}}

The full list of settings for sendEmail are as follows:
{code}
/usr/local/groundwork/common/bin/sendEmail --help

sendEmail-1.52 by Brandon Zehm <caspian@dotconf.net>

Synopsis: sendEmail -f ADDRESS [options]

Required:
-f ADDRESS from (sender) email address
* At least one recipient required via -t, -cc, or -bcc
* Message body required via -m, STDIN, or -o message-file=FILE

Common:
-t ADDRESS [ADDR ...] to email address(es)
-u SUBJECT message subject
-m MESSAGE message body
-s SERVER[:PORT] smtp mail relay, default is localhost:25

Optional:
-a FILE [FILE ...] file attachment(s)
-cc ADDRESS [ADDR ...] cc email address(es)
-bcc ADDRESS [ADDR ...] bcc email address(es)

Paranormal:
-xu USERNAME authentication user (for SMTP authentication)
-xp PASSWORD authentication password (for SMTP authentication)
-l LOGFILE log to the specified file
-v verbosity, use multiple times for greater effect
-q be quiet (no stdout output)
-o NAME=VALUE see extended help topic "misc" for details

Help:
--help TOPIC The following extended help topics are available:
addressing explain addressing and related options
message explain message body input and related options
misc explain -xu, -xp, and others
networking explain -s, etc
output explain logging and other output options
{code}