This is a multi-part series of Nagios articles all focused on configuring a complete Nagios monitored network. Find all related articles here.
Nagios has the ability to send emails to contacts (email addresses) and groups of contacts when events occur. This article demonstrates how contacts get notified.
The file we’re going to focus on is the “/etc/nagios/objects/contacts.cfg” file. The default contacts file looks like this:
define contact{ contact_name nagiosadmin ; Short name of user use generic-contact ; Inherit default values from generic-contact template (defined above) alias Nagios Admin ; Full name of user email nagios@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** } define contactgroup{ contactgroup_name admins alias Nagios Administrators members nagiosadmin }
Here’s my Nagios “contacts” file:
define contactgroup{ contactgroup_name admins alias Nagios Administrators members webadmin,mailadmin } define contact{ contact_name webadmin use generic-contact alias Web Admin email [email protected] service_notification_commands notify-service-by-email host_notification_commands notify-host-by-email } define contact{ contact_name mailadmin use generic-contact alias Mail Admin email [email protected] service_notification_commands notify-service-by-email host_notification_commands notify-host-by-email }
We need to make a change to our “/etc/nagios/servers/clients.cfg” file to specify who (or what groups of contacts) should be notified when events occur. Here’s a sample of how we modify a “service”:
define service{ use generic-service hostgroup_name snmp-servers service_description CPU 5 Minute Load check_command check_snmp!-C public -o 1.3.6.1.4.1.2021.10.1.3.2 -P 2c contact_groups admins }
Notice the “contact_groups admins” section.
The above shows that the “admins” group will get notified if there is an event effecting the service “CPU 5 Minute Load”. Do the same for each service that you want to monitor.
Still in the “/etc/nagios/servers/clients.cfg” file, we need to add contacts to “host” entries too. Here’s a sample of how we do that. The only difference here is that i don’t want a group to be contacted if there is a problem with a specific host, i want to notify a specific person (via email).
define host{ use linux-server host_name www.example.com alias www.example.com address www.example.com max_check_attempts 5 check_period 24x7 notification_interval 30 notification_period 24x7 contacts webadmin }
Notice the “contacts webadmin” section.
The above shows that the contact (not a group but a specific contact) “webadmin” will be notified if there is an event effecting this host. Do the same with the other hosts and specify the host or hostgroup that should be notified of an event.
Once your changes have been made, restart Nagios. You can test notifications via the Nagios web portal. Follows these steps:
- Click “Services” in the left menu. Click on any failed service (yellow) in the main area.
- Click “Send custom service notification” in the right menu.
- Enter a custom “comment” and click the “Commit” button.
Check your inbox for your notification email. If you don’t get it, check your server logs to see if there is a system issue on the Nagios server.
References:
Hello Dear,
I want to configure or start email notification on My Nagios server (version 4.4.3).
I want that an email should be send on every night or in next morning on a particular mail id. and also all the service’s and host health report should be generated in a excel or csv sheet. And mail should be send with an attachment on a specific or register mail id.
How can i do this, please let me know the procedure.
Urgent Reply.