Nagios Email Notification

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Mooash
Posts: 3
Joined: Tue Mar 19, 2013 11:59 pm

Nagios Email Notification

Post by Mooash »

Hi guys,

I'm trying to debug why Nagios only sends a notification to ONE person in a email group, it doesn't send it to the second? I really have no idea whats going on. I'll post my configs below

contacts.cfg:

Code: Select all

define contact{
        contact_name                    example1		; Short name of user
	use				generic-contact		; Inherit default values from generic-contact template (defined above)
        alias                           Example One		; Full name of user

        email                           [email protected]	; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
	contactgroups 		admins, examplegroup
        }

define contact{
        contact_name                    example2		; Short name of user
	use				generic-contact		; Inherit default values from generic-contact template (defined above)
        alias                           Example Two		; Full name of user

        email                           [email protected]	; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
	contactgroups			examplegroup
        }

define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 example1
        }

define contactgroup{
        contactgroup_name       examplegroup
        alias                   Notifications for Example VPS
        members                 example1, example2
        }
templates.cfg:

Code: Select all

# Linux host definition template - This is NOT a real host, just a template!

define host{
	name				linux-server	; The name of this host template
	use				generic-host	; This template inherits other values from the generic-host template
	check_period			24x7		; By default, Linux hosts are checked round the clock
	check_interval			5		; Actively check the host every 5 minutes
	retry_interval			1		; Schedule host check retries at 1 minute intervals
	max_check_attempts		10		; Check each Linux host 10 times (max)
        check_command           	check-host-alive ; Default command to check Linux hosts
	notification_period		24x7	; Linux admins hate to be woken up, so we only notify during the day
							; Note that the notification_period variable is being overridden from
							; the value that is inherited from the generic-host template!
	notification_interval		120		; Resend notifications every 2 hours
#	notification_options		d,u,r		; Only send notifications for specific host states
	contact_groups			admins		; Notifications get sent to the admins by default
	register			0		; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
	}
The host in question:

Code: Select all

define host{
use linux-server
host_name examplename
alias examplename.example.org
address 192.168.0.1
contact_groups examplegroup
}

# Define a service to "ping" the local machine

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       example
        service_description             PING
	check_command			check_ping!100.0,20%!500.0,60%
	notifications_enabled		1
        }
Please note I've edited/taken a lot out of those examples.

My issue is that notification emails only go to example1 instead of going to the whole group like the host is assigned.

If it makes any difference, I can see both contacts in Nagios and there aren't any errors in my config that I, or Nagios, can see.

Any help would be great!
User avatar
gshergill
Posts: 231
Joined: Tue Aug 07, 2012 5:08 am

Re: Nagios Email Notification

Post by gshergill »

Hi Mooash,

Looking at your configs, you have defined for your host a specific contact group, in this case examplegroup.
This means when your host goes down, emails will be sent to examplegroup.

However, you are using generic-service for your services:

Code: Select all

define service{
        use                             generic-service         ; Name of service template to use
...
The chances are your service template will have the following lines:

Code: Select all

define service{
   name            generic-service   ; The name of this service template
...
   contact_groups         admins      ; Notifications get sent to the admins by default
   register         0      ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
   }
There are multiple ways to combat this.
1. Change the contact_groups on your generic-service template to be examplegroup, i.e.

Code: Select all

define service{
   name            generic-service   ; The name of this service template
...
   contact_groups         examplegroup     ; Notifications get sent to the admins by default
   register         0      ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
   }
2. Add the line below to each service which will need both contacts on the email list.

Code: Select all

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       example
        service_description             PING
   check_command         check_ping!100.0,20%!500.0,60%
   notifications_enabled      1
  contact_groups         examplegroup
        }
3. Create a new service template, e.g. generic-service-examplegroup, which has the contact_groups as examplegroup, then use this as the template for services.

Code: Select all

define service{
   name            generic-service-examplegroup   ; The name of this service template
    use         generic-service 
   contact_groups         examplegroup
   register         0      ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
   }

Code: Select all

define service{
        use                             generic-service-examplegroup         ; Name of service template to use
        host_name                       example
        service_description             PING
   check_command         check_ping!100.0,20%!500.0,60%
   notifications_enabled      1
        }
4. (Not 100% on this one) Remove contact_groups from your service template to force it to use the hosts contacts_group.

Hope this helps.

Kind Regards,

Gary Shergill
Mooash
Posts: 3
Joined: Tue Mar 19, 2013 11:59 pm

Re: Nagios Email Notification

Post by Mooash »

Thank you so much! I forgot that services had a different setting!

For anyone else that sees this and wonders how I did it, setting up a custom service template fixed it. I used the following:

Code: Select all

define service{
   name            generic-service-examplegroup   ; The name of this service template
    use         generic-service 
   contact_groups         examplegroup
   register         0      ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
   }
Which from my rough understanding simply uses the generic-service for everything BUT the contact group, its a really good option. You then have to go through and update each check for that host and set it to use this new template.

Thanks again!
User avatar
gshergill
Posts: 231
Joined: Tue Aug 07, 2012 5:08 am

Re: Nagios Email Notification

Post by gshergill »

Hi Mooash,

Great to hear it's working!

Kind Regards,

Gary Shergill
Locked