How to use email id of Gmail for sending nagios email alerts
How to use email id of Gmail for sending nagios email alerts
In this tutorial we will learn about how to use email id of Gmail for sending nagios email alerts.
Requirement:
(1): Create one email id of gmail for sending emails from nagios server eg. nagiosalerts@gmail.com
(2): Using ssmtp package . As per man page of ssmtp, ssmtp is a send-only sendmail emulator for machines which normally pick their mail up from a centralized mailhub (via pop, imap, nfs mounts or other means). It provides the functionality required for humans and programs to send mail via the standard or /usr/bin/mail user agents
(3) sendmail package but service can be stopped.
Question: Why I am using gmail id here ?
Answer: Because the nagios server can send email directly from server also. But there is a possibilities that these email will go to spam box. Gmail,Yahoo,AOL,Hotmail etc. big boys , now a days tightened more security on spamming.
For non spam email, our mail server must follow dkim,spf,reverse dns etc requirement.
This task can also be achieved by relaying the email from MTS config file. But here I want to use free email service i.e gmail
Follow the given below steps to use gmail email id for nagios alerts
Step 1 : Create one gmail id from www.gmail.com ,here I am using nagiosalerts@gmail.com
Step 2: Login into Nagios Server and install ssmtp and sendmail
In CentOS and RedHat yum install ssmtp sendmail In Debian and Ubuntu sudo apt-get install ssmtp sendmail
Step 3: Now I am stoping the sendmail service as well as disabling from runlevel bootup
In CentOS and Red Hat /etc/init.d/sendmail stop ; chkconfig sendmail off In Debian and Ubuntu sudo /etc/init.d/sendmail stop ; sudo update-rc.d -f sendmail disable
Step 4: Now take the backup of ssmtp.conf file and configure it.
cp -p /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.orig.`date +%F` > /etc/ssmtp/ssmtp.conf (now edit the ssmtp.conf file with vi editor or any editor which you like) vi /etc/ssmtp/ssmtp.conf AuthUser=nagiosalerts@gmail.com AuthPass=password FromLineOverride=YES mailhub=smtp.gmail.com:587 UseSTARTTLS=YES
Step 5: Now take the backup of sendmail script. It is good to use which command to find exact path of sendmail script. In my case it is at /usr/sbin/sendmail .Hence I am changing directory to /usr/sbin . It might be different in your case.
(To get absolute path of sendmail script) which sendmail (To get absolute path of ssmtp script) which ssmtp (Take backup of sendmail script) cp -p /usr/sbin/sendmail /usr/sbin/sendmail.orig.`date +%F` rm /usr/sbin/sendmail cd /usr/sbin ln -s /usr/sbin/ssmtp sendmail
Below is reference from my system
[root@Nagios sbin]# ls -l sendmail
lrwxrwxrwx 1 root root 15 Jul 16 10:29 sendmail -> /usr/sbin/ssmtp
[root@Nagios sbin]#
Step 5: Send an test email , replace emailid@example.com with your email id
echo "testing for nagios alerts"|mail -s "test nagiosalerts" emailid@example.com
Check your inbox the email should come from nagiosalerts@gmail.com. You can also check the header of email.
Step 6: Now find the contacts.cfg file of nagios in /etc/nagios
Note: In Red Hat based and Debian Based linux OS, the path of contacts.cfg of nagios is different(If you have installed it with yum or apt-get),hence search the contacts.cfg file.
Now edit the contacts.cfg file of nagios
Replace YourName and youremailid@domain-name.com as per your information.
define contact{ contact_name YourName alias YourName service_notification_period 24x7 host_notification_period 24x7 service_notification_options c,r host_notification_options d,r service_notification_commands notify-by-email host_notification_commands host-notify-by-email email youremailid@domain-name.com }
Step 7: Restart the nagios
In CentOS and Red Hat /etc/init.d/nagios restart In Debian and Ubuntu (Nagios version 3.x) /etc/init.d/nagios3 restart
Step 8: The setup is completed. Now you will receive the email alerts from gmail id. (nagiosalerts@gmail.com)
Hi,
When I try to install ssmtp and sendmail I get following error:
————————————————————————————————————-
ubuntu@nagios-server:/etc/ssmtp$ sudo apt-get install ssmtp sendmail
Reading package lists… Done
Building dependency tree
Reading state information… Done
sendmail is already the newest version.
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
sendmail-bin : Conflicts: mail-transport-agent
ssmtp : Conflicts: mail-transport-agent
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
————————————————————————————————————–
I am using Ubuntu 14.04.4 server.
When I try to install ssmtp separatly it removes sendmail package.
Please suggest.
install both packages individually.
sudo apt-get install ssmtp
sudo apt-get install sendmail
it works.
Thanks Virendra!
Regards
Sharad
I encountered this error when I try to send email
echo “testing for nagios alerts”|mail -s “test nagiosalerts” testemail@test.com
mail: Cannot open mailer: No such file or directory
mail: cannot send message: No such file or directory
Anyone knows how to fix this?
Hello Jett,
Check if mail command is installed in system.
If it is not installed follow this tutorial and send once again the test email.
https://sharadchhetri.com/2013/02/13/mail-command-not-found-in-redhat-centos-or-ubuntu/
Regards
Sharad
I could not find ssmtp folder inside etc. Why???
Hi,
have you installed ssmtp and how ?
Regards
Sharad
i have “can’t send mail : sendmail process failed with error code 1”
what i must do?
Just check, which service are you running in your system, Postfix or sendmail. Only one service should be used, hence stop anyone mail service.
If issue still exist, check the mail log
Regards
Sharad
what command to stop the mail service?
Depending upon your Operating system and mail software you are using.
This will work in RHEL7/CentOS7
Regards
Sharad
I have configured nagios to my EMail ID prashantha.c@optit.in. Its my gmail ID.
But I’m not getting any email alert from nagios.
Only Im getting mail when I execute the below command
echo “testing for nagios alerts”|mail -s “test nagiosalerts” prashantha.c@optit.in
Please guide me I’m struggling to configure email alert.
Hi ,
everything goes fine till step 5, while trying step 5 i get message saying that
echo “testing for nagios alerts”|mail -s “test nagiosalerts” someid@gmail.com
The program ‘mail’ is currently not installed. You can install it by typing:
apt-get install mailutils
Am i missing something ? could some one guide me to proceed further ?
Hello Rashmi,
Yes, you have to install mailutils to get mail command in Debian/Ubuntu system.
In Ubuntu/Debian
Or if you are using RHEL / CentOS
Regards
Sharad
Hi,
I am facing same problem. Please help me:
root@xx-DE-NMS-1:/usr/sbin# echo “testing for nagios alerts”|mail -s “test nagiosalerts” sazzad.hussein@de.rr-xxx.eu
mail: Cannot open mailer: No such file or directory
mail: cannot send message: No such file or directory
Very useful!! Thank you very much!!
Just to make my contribution,..
In my case was necessary to change Nagio´s command notify-host-by-email and notify-service-by-email, those were hardcoded as /bin/mail, in my ubuntu/debian mail engine lives in /usr/bin/mail.
Regards folks.!!
Thankyou Manuk,
Your suggestion will help other readers too.
Regards
Sharad
Hello Friend,
Kindly put your correct email when you comment here.So that you will receive our reply on your inbox.
Apart of this,
Can you share your configuration with us.
Also recheck your password
I hope on your server, you are able to connect with internet.
Regards
Sharad
after do this settings i have not reciving email notification from nagios,please help
Thanks so much.This was perfect to every detail
Welcome Prav