• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

How to use email id of Gmail for sending nagios email alerts

July 16, 2013 by Sharad Chhetri 29 Comments

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)

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. Send nagios report as pdf file via email
  2. Error: Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’ for update!
  3. send email after mysql backup through bash script in simple way
  4. create noreply email id in postfixadmin mysql database
  5. Installing Nagios-3.4 in CentOS 6.3
  6. Installing Nagios-3.5.0 in CentOS 6.4 using yum
  7. Error: Could not stat() command file ‘/var/lib/nagios3/rw/nagios.cmd’!
  8. NOTICE: nagios.cmd file not found. Please specify the location of this file in your /etc/vshell.conf file
  9. How to install Nagios 4 from source on Ubuntu 14.04 LTS
  10. How to install Nagios on CentOS 7 / RHEL 7

Filed Under: Linux, Monitoring Server Tagged With: Nagios

Reader Interactions

Comments

  1. Noobies says

    March 12, 2020 at 9:44 am

    Thank you, your tutorial achieved for me to get until sending email into my inbox.But, I dont know how to check either the last step is success or not.

    P/s: I got error “send-mail: Cannot open smtp.gmail.com:587” and fix with “TLS_CA_File=/etc/pki/tls/certs/ca-bundle.crt ” inside the ssmtp.conf” and success to received email in gmail inbox.

    Reply
    • Sharad Chhetri says

      May 9, 2020 at 3:05 am

      Hi Noobies,

      Now a days Gmail has increased the SMTP Auth security. Address may have been changed or port number.
      I would recommend you to use some good mail service like Sendgrid.
      This post I have written as a workaround by using gmail account and thought to share.

      If in your organisation you have SMTP server, take help from Mail Admin to provide SMTP address and Credentials.

      Regards
      Sharad

      Reply
  2. rahul says

    September 10, 2018 at 11:12 am

    Hello Sir,

    How can i send mails using two different mail IDs.

    I.e nagiosalerts@gmail.com
    alerts@gmail.com
    in this way we can send mail to different departments or different domains.

    Please suggest what can be done in this situation.

    Reply
    • Sharad Chhetri says

      September 19, 2018 at 6:29 pm

      Hi Rahul,

      There is another approach. You can install postfix and alter the mail_from.
      But remember the server should be in whitelisted state otherwise all email will go in spam. Now a days all Mail Provider has increased the security level as per types of attacks happening in internet.

      Now a days , I use AWS SES service which is quite useful.

      Regards
      Sharad

      Reply
  3. Shashikant says

    April 20, 2018 at 5:45 am

    Hi,

    I did the configurations as you mentions and it’s working fine. Only problem which i am facing is – I am getting notification mails in spam folder instead of inbox folder.

    Please suggest what changes I have to made to receive the notifications in inbox ( I am using gmail id’s ).

    Reply
    • Sharad Chhetri says

      April 24, 2018 at 3:42 am

      Hi Shashikant,

      Mail security standards are increased now a days due to lots of spam and malicious activity. It could be various reason your email is dropping in spam inbox.

      1. The sender’s email id is not recognised by receiving MTA i.e gmail, yahoo, hotmail etc.
      2. Sender’s email id do not exist.
      3. email id suffix with domain name is blacklisted one.
      4. Source server may be blacklisted or compromised.
      5. No SPF record for domain name which is used in your email eg. email@example.com
      6. No subject line or blank email is also reason for spam.
      7. Frequency of sending email like Marketing emails also a reason for spamming.

      … .. Any many more reason.

      The Mail topic is vast and require mail standard to follow.

      Regards
      Sharad

      Reply
  4. henry says

    April 10, 2018 at 11:25 am

    Hi Im having this error below

    root@gwc-serv:/usr/sbin# echo “testing for nagios alerts”|mail -s “test nagiosalerts” henry@gulfwc.com
    Cannot start “/usr/sbin/sendmail”: executable not found (adjust *sendmail* variable)
    “/root/dead.letter” 6/140
    … message not sent

    Reply
    • Sharad Chhetri says

      April 11, 2018 at 4:56 pm

      Hi Henry,

      Can you send the alias command output.

      Regards
      Sharad

      Reply
« Older Comments

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

Agent admitted failure to sign using the key ssh

How to protect from port scanning and smurf attack in Linux Server by iptables

Convert video file into gif file through command line in linux

How to encode and decode the strings with base64

Protect from w00tw00t.at.blackhats.romanian.anti-sec

Password prompt in single user mode is not secure : CentOS/Red Hat

GNU Screen

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy