NagiosEnterprises / nagioscore

Nagios Core
GNU General Public License v2.0
1.55k stars 448 forks source link

Contact inheritance for service does not work after update #804

Open dan-m-joh opened 3 years ago

dan-m-joh commented 3 years ago

I am having a problem with "contact inheritance" after Update from Core 4.4.5 to 4.4.6. We have a lot of services defined with "contact_groups +\<group>" and before this was working fine (adding the group to the list of groups). Now it just replaces the contact_groups with \<group>".

Example:

    define host {
            use                             host-template
            host_name                       testhost
            contact_groups                  group_a
    }
    define service {
            use                             service-defs
            service_description             service1
            host_name                       testhost
            check_command                   check_service1
    }

    define service {
            use                             service-defs
            service_description             service2
            host_name                       testhost
            check_command                   check_service2
            contact_groups                  +group_b
    }

I would expect that for service1 to have "contact_groups = group_a" and service2 to have "contact_groups = group_a,group_b", but with 4.4.6 this is not the case. In 4.4.6 the result is that service2 ONLY have "contact_groups = group_b" (the "+" is ignored).

Any quick fix for this issue (short of change all services with "contact_groups +")?

Or have I misunderstood the use of "+\<group>" and it was just luck that it worked before? Use of "contacts +\<contact>" works fine for both Hosts and Services.

Regards, D/\N

rpv-tomsk commented 3 years ago

Hi, Just cloned repo and did git diff nagios-4.4.5 nagios-4.4.6. It shows there is no changes in core logic. Full list of changes matches Changelog records.

dan-m-joh commented 3 years ago

Hello,

Thanks for the feedback.

Then this has been introduced before 4.4.5 (and I only noticed it after the update to 4.4.6), OR have I misunderstood how contact-group inheritance for services is supposed to work?

rpv-tomsk commented 3 years ago

I can't confirm/check how it works, as my setup explicitly defines contact_groups in service definition.

There is https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/objectinheritance.html document, but it is a bit unclear about 'Implied Inheritance' and 'Additive Inheritance' relations.

Implied Inheritance

Normally you have to either explicitly specify the value of a required variable in an object definition or inherit it from a template. There are a few exceptions to this rule, where Nagios will assume that you want to use a value that instead comes from a related object. For example, the values of some service variables will be copied from the host the service is associated with if you don't otherwise specify them.

It looks like 'additive inheritance' treated as 'specify'.

xdata/xodtemplate.c:4685 and below:

/* services inherit some properties from their associated host... */
for(temp_service = xodtemplate_service_list; temp_service != NULL; temp_service = temp_service->next) {
        ...  
        /*
         * if the service has no contacts specified, it will inherit
         * them from the host
         */
        if(temp_service->have_contact_groups == FALSE && temp_service->have_contacts == FALSE) {
                xod_inherit_str(temp_service, temp_host, contact_groups);
                xod_inherit_str(temp_service, temp_host, contacts);
                }

... and 'have_contact_groups' flag is set before directive value is parsed (in xdata/xodtemplate.c:2830), just because directive is present in config.

dan-m-joh commented 3 years ago

Yes, so it seems....

The question is if this is intentional or a bug?

Any Nagios-Developer out there that can comment on this?

sawolf commented 2 years ago

Sure - I can confirm that a lot of the patterns that work for host and service configuration don't seem to work for contacts. I agree that I would expect a pattern like this to work normally, but if it doesn't work, I'm guessing that there's something that makes the implementation difficult. I'll be looking into this in the near future