1. Overview
The default alerts notification of Nagios network monitoring program are not really that great. They are not provide much information and the interface looks not good. Since we would read many Email alert from Nagios network monitoring program, it should be user-friendly interface and provide more information.
In this article will introduces you two php built scripts, one for sending Host Notifications and another one for sending Service Notifications in an HTML format for the Email message alerts from your Nagios network monitoring program.
2. Prerequisites
In this tutorial of installing Nagios network monitoring program, it is supposed that:
a. You have already installed Nagios network monitoring program. Please refer to this link. Installing Nagios Core For IT Infrastructure Monitoring on RHEL/CentOS 7
b. You have already configure VHhost and HTTPS protocol for Nagios network monitoring program. Please refer to this link Configuring Nagios VHost and Active Directory Integration.
c. You have already added hosts/devices to be monitored by Nagios network monitoring program. Please refer to below links to add hosts/devices to Nagios network monitoring program.
1. Monitoring Cisco ASA Firewall With Nagios Core Web Application
2. Monitoring Huawei Switch S5700 With Nagios Core Web Application
3. Monitoring Cisco Switch With Nagios Core Web Application
4. Monitoring CentOS/RHEL 7 Linux Server With Nagios Core Web Application
3. Download HTML Email Alert Scripts
Nagios network monitoring program host and service notifications are handled through a dedicated script for each case, resulting in two scripts to download and install. You can download them from Nagios Exchange web site or or you can download it directly here, nagios_host_mail, for host notifications alert, and nagios_service_mail, for service notifications alert.
After finished downloading the scripts, we need to move them into Nagios network monitoring program plugins directly in our case is “/usr/local/nagios/libexec/“.
# cd /home/vannath # ll -rw-rw-r-- 1 vannath vannath 1666 Dec 20 14:48 nagios_host_mail -rw-rw-r-- 1 vannath vannath 4909 Dec 20 14:48 nagios_service_mail # cp nagios_host_mail /usr/local/nagios/libexec/ # cp nagios_service_mail /usr/local/nagios/libexec/
Then, we need to make these two scripts to be the executable files.
# cd /usr/local/nagios/libexec/ # chmod +x nagios_host_mail # chmod +x nagios_service_mail
4. Define Nagios Notifications Commands
To use two HTML Email alert scripts above, we need to define commands and call those scripts to use. Let define the following notification commands so we can have a better interface with more information in the Email alert of Nagios network monitoring program.
To define the host notification commands, we need to edit Nagios network monitoring program configuration file “/usr/local/nagios/etc/objects/commands.cfg” as the following.
# vim /usr/local/nagios/etc/objects/commands.cfg define command{ command_name notify-host-by-html-email command_line /usr/local/nagios/libexec/nagios_host_mail "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTALIAS$" "$HOSTSTATE$" "$HOSTADDRESS$" "$HOSTOUTPUT$" "$SHORTDATETIME$" "$SERVICEDESC$" "$SERVICESTATE$" "$CONTAC TEMAIL$" "$TOTALHOSTSUP$" "$TOTALHOSTSDOWN$" "$HOSTNOTES$" }
To define the service notification commands, we need to edit Nagios network monitoring program configuration file “/usr/local/nagios/etc/objects/commands.cfg” as the following.
# vim /usr/local/nagios/etc/objects/commands.cf define command{ command_name notify-service-by-html-email command_line /usr/local/nagios/libexec/nagios_service_mail "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTALIAS$" "$HOSTSTATE$" "$HOSTADDRESS$" "$SERVICEOUTPUT$" "$SHORTDATETIME$" "$SERVICEDESC$" "$SERVICESTATE$" "$ CONTACTEMAIL$" "$SERVICEDURATIONSEC$" "$SERVICEEXECUTIONTIME$" "$TOTALSERVICESWARNING$" "$TOTALSERVICESCRITICAL$" "$TOTALSERVICESUNKNOWN$" "$LASTSERVICEOK$" "$LASTSERVICEWARNING$" "$SERVICENOTIFICATIONNUMBER$" "$HOSTNOTES $" }
Now the notification command definitions for host and service HTML Email alert of Nagios network monitoring program has been configured. Next need to configure the generic contacts definition of every hosts and services to use these two new notification commands. In case now, all hosts and services use the default a generic-contact template, so we only have to update the template to use the new command as below below:
# vim /usr/local/nagios/etc/objects/templates.cfg define contact{ name generic-contact ; The name of this contact template service_notification_period 24x7 ; service notifications can be sent anytime host_notification_period 24x7 ; host notifications can be sent anytime service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime events host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events #service_notification_commands notify-service-by-email ; send service notifications via email service_notification_commands notify-service-by-html-email #host_notification_commands notify-host-by-email ; send host notifications via email host_notification_commands notify-host-by-html-email register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE! }
Finally, we need to restart Nagios network monitoring program for changed to take affect.
# systemctl restart nagios # systemctl status nagios
5. Testing and Verify The HTML Email Alert
After making the configuration change on Nagios network monitoring program for the new alert notification, we need to check if Nagios network monitoring program still keep send the Email alert or not.
To check this, from Nagios network monitoring program web interface go to “Report” section and click on “Notifications” option.
We also need to verify Email log on Nagios network monitoring program to make sure that Nagios still keeping sending the Email notification.
# tailf /var/log/maillog Dec 27 23:27:14 tscent-mns01 postfix/qmgr[2915]: 08682634D2E: from=<nagios@techspacekh.local>, size=2584, nrcpt=1 (queue active) Dec 27 23:27:14 tscent-mns01 postfix/pickup[3986]: 0A336634D2F: uid=1002 from=<nagios> Dec 27 23:27:14 tscent-mns01 postfix/cleanup[100701]: 0A336634D2F: message-id=<20171227162714.0A336634D2F@tscent-mns01.techpacekh.local> Dec 27 23:27:14 tscent-mns01 postfix/qmgr[2915]: 0A336634D2F: from=<nagios@techspacekh.local>, size=2587, nrcpt=1 (queue active) Dec 27 23:27:14 tscent-mns01 postfix/smtp[100707]: 0A336634D2F: to=<netadmin@techspacekh.com>, relay=10.0.0.10[10.0.0.10]:25, delay=0.29, delays=0.03/0.01/0/0.25, dsn=2.6.0, status=sent (250 2.6.0 <20171227162714.0A336634D2F@tscent-mns01.techpacekh.local> [InternalId=10548439679087, Hostname=tscent-emx01.techpacekh.local] 5380 bytes in 0.228, 22.952 KB/sec Queued mail for delivery) Dec 27 23:27:14 tscent-mns01 postfix/qmgr[2915]: 0A336634D2F: removed
Next, let start to check our Email Inbox whether we receive the Email notification from Nagios network monitoring program or not. If every thing work find, we should get the following HTML Email alert from our Nagios network monitoring program.
- Host Down/Problem alert
- Host Up/Recovery alert
In the Host Alerts notification from Nagios network monitoring program, it contents following useful information.
- Notification: it could be PROBLEM or RECOVERY
- Host: Host name of the device
- Address: IP address of the device
- Noted: User friendly name of the devices.
- Date/Time: Date and time of the alert
- More Info: Provide the link to that particular host. So, we can check more information about this host. It help us to host with problem fast on Nagios network monitoring program web interface.
- Additional Info: Host problem detail.
- Total Host UP: It provides whole view of the network infrastructure. We can see all hosts up Up/OK now.
- Total Host Down: It provides whole view of the network infrastructure. We can see all hosts Down/Problem now.
- Action: We will get notification every one hour. If the problem still not yet fixed, Nagios network monitoring program will send another notification alert in another next one hour. Nagios network monitoring program will keep sending this alert every one hour until the problem is fixed. If we already aware of the problem and no need more alert notification from Nagios network monitoring program, we can stop the notification directly from the Email.
- Service critical alert
- Service warning alert
- Service recovery alert
In the Service Alerts notification from Nagios network monitoring program, it contents following useful information.
- Notification: it could be PROBLEM or RECOVERY, Critical with red color, Warning with yellow color, and OK with green color.
- Service: The description of the service
- Host: Hostn ame of the device
- Address: IP address of the device
- Noted: User friendly name of the devices.
- Date/Time: Date and time of the alert
- More Info: Provide the link to that particular service. So, we can check more information about this service. It help us to service with problem fast on Nagios network monitoring program web interface.
- Additional Info: service problem detail.
- State Duration: How have the service been in problem.
- Action: We will get notification every one hour. If the problem still not yet fixed, Nagios network monitoring program will send another notification alert in another next one hour. Nagios network monitoring program will keep sending this alert every one hour until the problem is fixed. If we already aware of the problem and no need more alert notification from Nagios network monitoring program, we can stop the notification directly from the Email.
In the Service Alert notification from Nagios network monitoring program, it also provides whole view of the network infrastructure a summery table of all services in our network infrastructure as the following.
- Total Service Warning: We can see all current warning services.
- Total Service Critical: We can see all current critical services.
- Total Service Unknown: We can see all current unknown services.
- Service Down for: How have the service been in problem.
5. Conclusion
Now we have come to end about configuring Nagios network monitoring program with HTML Email alert from Tech Space KH. This alert notification is very import for network and application performance monitoring. Hopefully, you can find this guide informative. If you have any questions or suggestions you can always leave your comments below. I will try all of my best to review and reply them.