How to Configure Nagios to Send Email Alerts on CentOS
This guide walks through setting up Nagios on CentOS 6.8 to send email notifications via SMTP, covering template, service, command, and contact configurations, testing the mail command, and summarizing Nagios' alert timing parameters.
Configuring Nagios Email Notifications
The previous article covered basic host and service monitoring with Nagios; this one explains how to enable email alerts using an SMTP service.
System environment
OS: CentOS 6.8 (Final) 2.6.32-642.el6.x86_64
Internet access for package installation
1. Nagios Service Configuration
Modify templates.cfg to define when and to whom Nagios should send email alerts. Example configuration is shown in the image below.
Modify services.cfg to adjust monitoring thresholds for services that use plugins directly (e.g., ping, ssh, http) and ensure command names match those in nrpe.cfg . Example shown below.
For services using check_nrpe , edit /usr/local/nagios/etc/nrpe.cfg to set warning and critical thresholds.
Modify commands.cfg to define the commands notify-host-by-email and notify-service-by-email referenced in templates.cfg . Example below.
Modify contacts.cfg (referred to as contracts.cfg in the original) to specify the email addresses of the recipients.
2. Email Service Configuration
Ensure the SMTP service (sendmail or postfix) is running on the Nagios server. Check port 25 with ss -tnl and start the service if needed: service sendmail start or service postfix start Configure the local sendmail account by editing mail.rc and adding the necessary credentials for a public mailbox (e.g., 163.com). Example configuration image:
Restart the SMTP service after changes.
Test sending mail with the mail command (provided by the mailx package). Ensure the path matches the one defined in commands.cfg ( /bin/mail ). Example test command shown in the image.
Trigger a Nagios alert (e.g., stop nginx on a test host) and verify that Nagios sends the notification email. Screenshots show the web UI alert, log entries, and the received email.
3. Nagios Alert Timing Summary
By default Nagios checks hosts/services every check_interval (5 minutes). The longest delay before detecting a failure equals one check interval.
The earliest a notification can reach personnel is after retry_interval multiplied by max_check_attempts.
Using the NSCA component can reduce reaction time by allowing monitored hosts to push data to the Nagios server. Additionally, notifications can be temporarily disabled or enabled from the Nagios web interface for maintenance.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
