We needed to setup Nagios to utilize our internet service provider’s SMTP Email server for notification emails. The biggest problem was that the ISP’s outgoing email server requires authentication.Nagios setup with SMTP outgoing authentications.
These are instructions and examples on how we got this setup working. I hope this helps others in the Nagios community.
This process utilizes a perl script called “sendEmail”.
1) Download from http://caspian.dotconf.net/menu/Software/SendEmail/#download.
2) Extract the file and copy the sendEmail into /usr/local/bin.
3) chmod +x /usr/local/bin/sendEmail.
Now the setup and customization of Nagios.
1) Edit /usr/local/nagios/etc/resource.cfg – add (3) new entries.
$USER5$=”your_isp_email_address”
$USER6$=”your_isp_email_password”
$USER7$=”your_isp_outgoing_mail_server”
2) Edit /usr/local/nagios/etc/objects/commands.cfg
Change command_line for command_name notify-host-by-email:
command_line /usr/bin/printf “%b” “***** Nagios *****nnNotification Type: $NOTIFICATIONTYPE$nHost: $HOSTNAME$nState: $HOSTSTATE$nAddress: $HOSTADDRESS$nInfo: $HOSTOUTPUT$nnDate/Time: $LONGDATETIME$n” | /usr/local/bin/sendEmail -o tls=no -s -s $USER7$ -xu $USER5$ -xp $USER6$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u “** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **” -m “***** Nagios *****nnNotification Type: $NOTIFICATIONTYPE$nHost: $HOSTNAME$nState: $HOSTSTATE$nAddress: $HOSTADDRESS$nInfo: $HOSTOUTPUT$nnDate/Time: $LONGDATETIME$n”
Change command_line for command_name notify-service-by-email:
command_line /usr/bin/printf “%b” “***** Nagios *****nnNotification Type: $NOTIFICATIONTYPE$nnService: $SERVICEDESC$nHost: $HOSTALIAS$nAddress: $HOSTADDRESS$nState: $SERVICESTATE$nnDate/Time: $LONGDATETIME$nnAdditional Info:nn$SERVICEOUTPUT$” | /usr/local/bin/sendEmail -o tls=no -s -s $USER7$ -xu $USER5$ -xp $USER6$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u “** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **” -m “***** Nagios *****nnNotification Type: $NOTIFICATIONTYPE$nnService: $SERVICEDESC$nHost: $HOSTALIAS$nAddress: $HOSTADDRESS$nState: $SERVICESTATE$nnDate/Time: $LONGDATETIME$nnAdditional Info:nn$SERVICEOUTPUT$”
3) Touch file /var/log/sendEmail
4) Chown nagios:nagios /var/log/sendEmail
5) Now restart Nagios service
Testing:
Go into Nagios and send an alert and check the /var/log/sendEmail log file. It should say “Email was sent successfully”.