using contacts causing double email alert

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.
User avatar
millisa
Posts: 69
Joined: Thu Jan 16, 2014 11:13 pm
Location: Austin, TX
Contact:

Re: using contacts causing double email alert

Post by millisa »

You will want to do that for any template.
The service definitions for generic-service, generic-service-dba, generic-service-mesproject, generic-service-cim all should likely have 'register 0' (I don't know that I see all those in use in the configs provided, but since they are intended to be templates with only partial configs that are for inclusion in other definitions, register 0 is appropriate).

The example you provided of double notification was for '6800SRETDB', which I don't see in that config.zip - I do see it in a hostgroup, just no host definition - I'll assume it is the same as the 6800SHDB and 6800SHDB-DR hosts' H drive check which you did include:

Code: Select all

define service{
        use                     generic-service-dba
        host_name               6800SHDB,6800SHDB-DR
        service_description     H Drive
        check_command           check_snmp_disk!public!H!70%!80%
}
So that service definition includes the generic-service-dba template found in your generic-service_nagios2.cfg file:

Code: Select all

define service{
        name                            generic-service-dba
        use                             generic-service-template
        #contacts                       itdba
        contact_groups                  db-admins
        register 0 #added since this is a template
}
Here is the contactgroup from your config that this template is using:

Code: Select all

define contactgroup{
        contactgroup_name       db-admins
        alias                   DB Admins
        members                 itdba
}
So, if you don't define a contacts or contact_groups in the H drive service definition, the template alone will notify the itdba address because of the inclusion of the db-admins contactgroup in the generic-service-dba service template. If you add a

Code: Select all

 contacts root
To the original H drive check like this:

Code: Select all

define service{
        use                     generic-service-dba
        host_name               6800SHDB,6800SHDB-DR
        service_description     H Drive
        check_command           check_snmp_disk!public!H!70%!80%
        contacts root
}
You would then have both a contacts and a contact_groups defined for that H Drive service check due to the inheritance of the generic-service-dba service template. Defining contacts here does not override the inclusion of the contact_groups in the template. If you place a new contact_groups in the H drive service definition it *will* override the service templates setting. If you want to cancel the inheritance of a value from one of the chained templates, you would use 'null' along with the value:

Code: Select all

define service{
        use                     generic-service-dba
        host_name               6800SHDB,6800SHDB-DR
        service_description     H Drive
        check_command           check_snmp_disk!public!H!70%!80%
        contacts root
        contact_groups null
}
See Cancelling Inheritance of String Values on the object inheritance page.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: using contacts causing double email alert

Post by abrist »

Do you have any follow up for us OP (hata_ph)?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
hata_ph
Posts: 31
Joined: Wed Aug 20, 2014 9:41 pm

Re: using contacts causing double email alert

Post by hata_ph »

sorry for the late reply. i try put register 0 in my service template but still receive duplicate alert email...
you all can double check the full config files i have attached.

Code: Select all

# default services template
define service{
	name				generic-service
	use				generic-service-template
	contacts			root
	#contact_groups			admins
	register		0
}

# services template for DBA team
define service{
	name				generic-service-dba
	use				generic-service-template
	#contacts			root
	contacts			itdba
	#contact_groups			db-admins
	register		0
}

Code: Select all

[2014-09-10 12:46:58] SERVICE NOTIFICATION: itdba;6800SRETDB;F Drive;CRITICAL;notify-service-by-email;SNMP CRITICAL - F:\ Label:New Volume Serial Number 46939174 at 96% with 10,200 of 286,081 MB free
[2014-09-10 12:46:58] SERVICE NOTIFICATION: itnetworksupport;6800SRETDB;F Drive;CRITICAL;notify-service-by-email;SNMP CRITICAL - F:\ Label:New Volume Serial Number 46939174 at 96% with 10,200 of 286,081 MB free
[2014-09-10 12:45:58] SERVICE ALERT: SPDFSERVER;CPU Load;OK;SOFT;2;2 CPU, average load 60.5% < 80% : OK
[2014-09-10 12:44:58] SERVICE ALERT: SPDFSERVER;CPU Load;CRITICAL;SOFT;1;2 CPU, average load 93.0% > 90% : CRITICAL
[2014-09-10 12:44:48] SERVICE NOTIFICATION: itdba;6800SRETDB;G Drive;CRITICAL;notify-service-by-email;SNMP CRITICAL - G:\ Label:New Volume Serial Number 447b705e at 90% with 54,753 of 572,158 MB free
[2014-09-10 12:44:48] SERVICE NOTIFICATION: itnetworksupport;6800SRETDB;G Drive;CRITICAL;notify-service-by-email;SNMP CRITICAL - G:\ Label:New Volume Serial Number 447b705e at 90% with 54,753 of 572,158 MB free
Attachments
conf.d.zip
(2.52 KiB) Downloaded 165 times
User avatar
millisa
Posts: 69
Joined: Thu Jan 16, 2014 11:13 pm
Location: Austin, TX
Contact:

Re: using contacts causing double email alert

Post by millisa »

That config doesn't match up with the logs - the logs show a notification to an 'itnetworksupport' contact. There isn't one of those in the conf.d zip (it has an itnetworksupport1, but not an itnetworksupport).

Looking at the F drive service definition as provided in that zip, it has no contact or contact groups defined, and includes the generic-service-dba template. The generic-service-dba template has only a contact of itdba, no contact groups and includes the generic-service-template template. The generic-service-template template has no contact groups or contacts defined. Only the itdba contact should be being contacted for an F drive alert based on the config in the latest zip. The G drive service definition in that zip has the same setup.

Code: Select all

melanogaster:nagios-tmp-support millisa$ cat *.cfg |grep itnetworksupport
	contact_name			itnetworksupport1
        members                 itnetworksupport1
I suspect the configs were edited between when those logs showing the notifications and the zip up the conf files happened with more changes than just removing email addresses you want to keep private. This will make this last example difficult to explain why you saw a notification to both contacts. If I had to guess, that itnetworksupport1 was called itnetworksupport when you had the log entries, and was a member of the 'admins' contactgroup. That 'admins' contact_groups line was likely not commented out in the generic-service-template template at the time you got those notifications (this is supported by the file modtime of 12:47pm local of generic-service_nagios.cfg which is after when those logs show notifications - I understand needing to edit the real emails in contacts_nagios2.cfg, so that modtime should be after your log entries). In short - if you see the double notification again and want an explanation of why, avoid changing the config files for the service definition and template (except editing the email addresses from the contacts config).

I am certain this is the config you effectively had at the time the log entries came in:

Code: Select all

define contact{
        contact_name                    itdba
        alias                           IT DBA
        use                             contact-template
        email                           xxx2
}
define contact{
        contact_name                    itnetworksupport
        alias                           IT Network Support
        use                             contact-template
        email                           xxx3
}
define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 itnetworksupport
        }
define service{
        use                     generic-service-dba
        host_name               6800SRETDB
        service_description     F Drive
        check_command           check_snmp_disk!public!F!80%!90%
}
define service{
        name                            generic-service-dba
        use                             generic-service-template
        contacts                        itdba  
        register                0
}
define service{
        name                            generic-service-template ; The 'name' of this service template
        active_checks_enabled           1       ; Active service checks are enabled
        passive_checks_enabled          1       ; Passive service checks are enabled/accepted
        parallelize_check               1       ; Active service checks should be parallelized (disabling this can lead to major performance problems)
        obsess_over_service             1       ; We should obsess over this service (if necessary)
        check_freshness                 0       ; Default is to NOT check service 'freshness'
        notifications_enabled           1       ; Service notifications are enabled
        event_handler_enabled           1       ; Service event handler is enabled
        flap_detection_enabled          1       ; Flap detection is enabled
        failure_prediction_enabled      1       ; Failure prediction is enabled
        process_perf_data               1       ; Process performance data
        retain_status_information       1       ; Retain status information across program restarts
        retain_nonstatus_information    1       ; Retain non-status information across program restarts
                notification_interval           20              ; Only send notifications on status change by default.
                is_volatile                     0
                check_period                    24x7
                normal_check_interval           5
                retry_check_interval            1
                max_check_attempts              4
                notification_period             24x7
                notification_options            w,u,c,r
                contact_groups                  admins
        register                        0       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
        }
That config, with just that one contact_groups uncommented and the itnetworksupport without the '1' would give you exactly the notification you saw when the F drive went critical. The F drive check would include the generic-service-dba template which would cause itdba to get notified and that template would in turn include the generic-service-template template, which would notify itnetworksupport if that contact_groups for admins was uncommented. I can't say with absolute 100% certainty that the above was your config, but it seems likely based on what the logs showed and comparing this conf zip up with the earlier one.

At this point, I'm sure you are running into an inheritance issue and are ending up with a service definition that has both a contact and contact_group defined after it has included all the chained templates. Try this: explicitly define or undefine your contacts and contact_groups in the final service definition. For example, if you want the itdba user to be the only one who receives an alert for the F drive on 6800SRETDB use this config:

Code: Select all

define service{
        use                     generic-service-dba
        host_name               6800SRETDB
        service_description     F Drive
        check_command           check_snmp_disk!public!F!80%!90%
        contacts              itdba
        contact_groups     null
}
That will make absolutely sure that if there are any defined contact_groups in the template chain leading up to that service check, it'll get explicitly undefined for the F drive check. If you want to make sure just the contact_groups you define for a specific service check only go to the contact group and not any previously templated contact that may be being included in the chain, like say make it so only the erp-admins and no one else gets notified do this:

Code: Select all

define service{
        use                     generic-service-dba
        host_name               6800SRETDB
        service_description     F Drive
        check_command           check_snmp_disk!public!F!80%!90%
        contacts              null
        contact_groups     erp-admins
}
If there are any contacts defined in the generic-service-dba template or further up the chain that 'contacts null' setting is going to explicitly overrule it. This should at least assure you that there isn't some bug causing double notifications but it is being caused by something higher in the chain.

Though I don't suggest it for your actual configuration, if you are running into an inheritance issue, copying your service definition, followed by any templates it includes in the order they are included, one beneath the other will likely help you spot which contacts and contact_groups are taking precedence in your template chains.

Edit: Corrected a couple typos.
User avatar
millisa
Posts: 69
Joined: Thu Jan 16, 2014 11:13 pm
Location: Austin, TX
Contact:

Re: using contacts causing double email alert

Post by millisa »

I took a few minutes to give a couple examples that I believe outline what you are running into. Maybe the arrows and diagramming will help (there are bits left out for clarity; the bottom service definition would have a 'name' line at least).

In the first example, you end up with both productionadmin1 and the contact group driveadmins getting notified when the bottom service goes critical.
Service Contact Inheritance Example 1
Service Contact Inheritance Example 1
In the second example, the developers group gets notified, and the sqladmin contact gets notified. The dbadmins contact group does NOT get notified because it is overidden.
Service Contact Inheritance Example 2b
Service Contact Inheritance Example 2b
Edit: Fixed error in 2nd example image.
hata_ph
Posts: 31
Joined: Wed Aug 20, 2014 9:41 pm

Re: using contacts causing double email alert

Post by hata_ph »

milisa, thanks for your help...maybe there is some commented settings that make you confuse...i will re-upload my config again...

Let me re-phase again, use contacts will get double email but contact_groups single...

Code: Select all

# services template for DBA team
define service{
   name            generic-service-dba
   use            generic-service-template
   contacts         itdba
   #contact_groups         db-admins
   register      0
}
PS: I will try the contacts/contact_groups null setting when back at office...
Attachments
conf.dv2.zip
(2.61 KiB) Downloaded 160 times
User avatar
millisa
Posts: 69
Joined: Thu Jan 16, 2014 11:13 pm
Location: Austin, TX
Contact:

Re: using contacts causing double email alert

Post by millisa »

Which check in that latest config gives you notifications you don't expected? Based on what I see in the above conf.d zip, the F drive critical will notify the itdba:
the F drive check defines no contacts or contact groups and uses generic-service-dba template.
The generic-service-dba template defines only the contact itdba and includes the generic-service-template template.
The generic-service-template template has neither contact or contact group. This results in one contact, itdba, and no contact groups in the final F drive check.
With that config above the F drive check shouldn't generate but a single notification.
hata_ph
Posts: 31
Joined: Wed Aug 20, 2014 9:41 pm

Re: using contacts causing double email alert

Post by hata_ph »

milisa, my thought is same with you but it is not the case if i use contacts instead of contact_groups...

BTW, if i put contact_groups null in the generic-service-dba and i got 1 email alert...strange..
where did I inherit the contact_groups from?

Code: Select all

# default services template
define service{
   name            generic-service
   use            generic-service-template
   contacts         root
   #contact_groups         admins
}

# services template for DBA team
define service{
   name            generic-service-dba
   use            generic-service-template
   contacts         itdba
   #contact_groups         db-admins
   contact_groups    null
}
Last edited by hata_ph on Wed Sep 10, 2014 11:22 pm, edited 2 times in total.
User avatar
millisa
Posts: 69
Joined: Thu Jan 16, 2014 11:13 pm
Location: Austin, TX
Contact:

Re: using contacts causing double email alert

Post by millisa »

Please post exact logs showing the multiple notifications and the corresponding configs without modifying them after the time the multiple notification occur.
What you just posted has you putting a contact_groups null in the generic-service-dba template, not the generic-service-template template as you believe (and would account for eliminating the inherited notifications if your config was as suspected a couple posts ago).

The current troubleshooting instructions were to eliminate the extra notifications by placing the contact_groups null entry in the real service definition, not a template.
hata_ph
Posts: 31
Joined: Wed Aug 20, 2014 9:41 pm

Re: using contacts causing double email alert

Post by hata_ph »

milisa, sorry is generic-service-dba, not generic-service-template...
Locked