How to Configure Nagios Alerts with Gmail SMTP
Nagios is a powerful tool for monitoring systems and services, but receiving notifications through email is essential for better management. By default, Nagios uses the /bin/mail command for sending emails. However, in this guide, we will show you how to configure Nagios alerts to be sent through Gmail’s SMTP service, providing more reliable and secure notifications.

Step 1: Enable “Less Secure Apps” in Gmail
Before we begin configuring Nagios to use Gmail for sending alerts, you need to enable access for “less secure apps” in your Gmail account. This setting allows non-interactive applications like Nagios to send emails through Gmail’s SMTP server.
To do this, go to your Google account settings and enable the “Allow less secure apps” option. This is crucial for ensuring that Nagios can successfully authenticate and send emails using Gmail.
Step 2: Update the Contacts Configuration in Nagios
Next, we’ll update Nagios’ contact configuration file to specify the email address where alerts will be sent. You can do this by editing the contacts.cfg file.
- Open the
/usr/local/nagios/etc/objects/contacts.cfgfile. - Locate the contact block and add the email address where you want to receive Nagios alerts.
Here’s an example of the contact block:
define contact {
contact_name admin
alias Admin
service_notification_period 24x7
host_notification_period 24x7
email your-email@gmail.com
}
After saving the changes, exit the editor. You can now move on to setting up SMTP.
Step 3: Install SMTP Client on Ubuntu or CentOS
For sending emails through Gmail’s SMTP server, you need to install an SMTP client. On Ubuntu, you can install the required dependencies with the following command:
sudo apt install php php-cli php-gd php-curl php-zip php-intl php-mbstring php-xml
For CentOS, you’ll need to first upgrade your PHP version and then install the dependencies:
sudo yum install yum-utils http://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum-config-manager --enable remi-php70
sudo yum install php php-cli php-gd php-curl php-zip php-intl php-mbstring php-xml
Step 4: Download and Install the SMTP Client
Now, let’s download and install the SMTP client needed for sending emails. Run the following commands:
wget https://github.com/boolean-world/smtp-cli/archive/master.zip
unzip -d /opt master.zip
After extracting the files, navigate to the extracted directory:
cd /opt/smtp-cli-master
Next, install the required dependencies:
composer install
Step 5: Configure the SMTP Client
Create a config.json file in the /opt/smtp-cli-master directory. This file will contain the details for your Gmail SMTP server and sender’s email address.
Here’s an example of the config.json configuration for Gmail:
{
"host": "smtp.gmail.com",
"username": "your-email@gmail.com",
"password": "your-password",
"secure": "tls",
"port": 587
}
Step 6: Modify Nagios Commands for SMTP
To replace the default mail command with the SMTP client, you’ll need to edit the commands.cfg file.
- Open the
/usr/local/nagios/etc/objects/commands.cfgfile. - Locate the
notify-host-by-emailandnotify-service-by-emailblocks. These blocks contain the email commands for notifications. - Replace the
/bin/mailcommand with the path to the SMTP client script:
command_line /opt/smtp-cli-master/smtp-cli.php
Step 7: Test Your Nagios Alerts Configuration
After making the necessary configurations, it’s time to test the setup.
To simulate an issue, you can fill up disk space on a monitored host. For example, you can run the following command:
dd if=/dev/zero of=zero.bin bs=1M count=$((28*1024))
Wait for Nagios to perform the check, and the alert will be sent to the specified email address. Once the alert is received, remove the zero.bin file to restore the disk space.
Conclusion for Nagios Alerts Configuration
By following the steps above, you can configure Nagios to send alerts through Gmail’s SMTP service. This ensures that you receive timely notifications about any issues with your systems, making it easier to respond to problems promptly.
For organizations looking to enhance their DevOps, Cloud, or Security operations, ZippyOPS offers expert consulting, implementation, and managed services in areas like DevOps, DevSecOps, Cloud, AIOps, and more. ZippyOPS ensures that your infrastructure runs smoothly with cutting-edge solutions for MLOps, microservices, and automated operations. Explore our full range of services and solutions at ZippyOPS Services and ZippyOPS Solutions.
For more information or to get in touch, feel free to contact us at sales@zippyops.com.



