Page 1 of 1

Host, service and template value precendence?

Posted: Wed Jun 17, 2015 5:20 pm
by gormank
It seems that both host and service definitions require things like max_check_attempts, check_interval, and retry_interval, etc. I'm putting the values in templates.
One set of values has to override the other, so who wins, or which values take precedence, the host or service definition?
A similar question is do the values defined in the host override all others? I'm guessing this is yes...

Code: Select all

define host {
       name                                     generic-host
       max_check_attempts                       3
       check_interval                           5
       retry_interval                           5
       check_period                             24x7
       event_handler_enabled                    1
       flap_detection_enabled                   1
       process_perf_data                        1
       retain_status_information                1
       retain_nonstatus_information             1
       notification_period                      24x7
       notifications_enabled                    1
       register                                 0
}

Code: Select all

define service {
       name                                     default-service
       service_description                      default-service
       display_name                             default-service
       is_volatile                              0
       max_check_attempts                       3
       check_interval                           5
       retry_interval                           5
       active_checks_enabled                    1
       passive_checks_enabled                   1
       check_period                             24x7
       parallelize_check                        1
       obsess_over_service                      0
       check_freshness                          0
       event_handler_enabled                    1
       flap_detection_enabled                   1
       process_perf_data                        1
       retain_status_information                1
       retain_nonstatus_information             1
       notification_interval                    60
       notification_period                      24x7
       notification_options                     w,c,u,r,
       notifications_enabled                    1
       contact_groups                           admins
       register                                 0
}

Re: Host, service and template value precendence?

Posted: Thu Jun 18, 2015 1:06 am
by Box293
Have a read of this:

http://nagios.sourceforge.net/docs/nagi ... tance.html

Think of templates like this.
TemplateA
TemplateB
TheObject

Nagios reads TemplateA and gets any settings defined and builds the "current config"
Nagios reads TemplateB and gets any settings defined, these will override any specific settings in the "current config" (unless specifically defined) and updates the "current config"
Nagios reads TheObject and gets any settings defined, these will override any specific settings in the "current config" (unless specifically defined) and updates the "current config"

It's a layering process. Usually, whatever is closest to TheObject wins (specifically defined directives on TheObject win over all others ... unless specifically defined).


Does this help?

Re: Host, service and template value precendence?

Posted: Thu Jun 18, 2015 10:58 am
by gormank
Sorry, I'm still not seeing where the precedence is...

The intersection is at the service. Values are difined in the service template, hosts are defined in the host group, and host values are defined in the host template.
I don't see anything that says which template takes precedence, or which is read last.

Re: Host, service and template value precendence?

Posted: Thu Jun 18, 2015 11:25 am
by lmiltchev
One important thing to understand with inheritance is that "local" object variables always take precedence over variables defined in the template object.
You may have object variables defined:
1. On a host/service level:
define host{
host_name myhost
max_check_attempts 5
...
}
2. Inherited from a template:
define host{
host_name myhost
use myhosttemplate
...
}
define host{
host_name myhosttemplate
max_check_attempts 3
...
register 0
}
3. Or both:
define host{
host_name myhost
max_check_attempts 5
use myhosttemplate
...
}
In the 3rd example, the "max_check_attempts" will be 5, as this variable is defined on a host level and it will take precedence over the template (max_check_attempts=3).

When you have multiple templates in use (and variables are not defined locally), as Box293 said: "whatever is closest to TheObject wins". I hope this makes sense.

Re: Host, service and template value precendence?

Posted: Thu Jun 18, 2015 11:45 am
by gormank
You're still talking about host definitions and seem to have gone to a bit of trouble to explain something that isn't part of the question asked. But thanks.

Re: Host, service and template value precendence?

Posted: Thu Jun 18, 2015 12:17 pm
by tmcdonald
Hosts and services work the same in terms of template inheritance.

The rule is: A setting made directly on the host/service will override that same setting if present in the host/service template being used.
gormank wrote:One set of values has to override the other, so who wins, or which values take precedence, the host or service definition?
A service's settings have no bearing on a host's settings, and vice versa. The only exception to this is called Implied Inheritance:

http://nagios.sourceforge.net/docs/3_0/ ... nheritance

Basically, if a service has no contact_groups, notification_interval, or notification_period set (either in the service itself or in any templates it uses), then it will inherit these values from the host it is attached to.

The best way to think of this is that host and service checks are basically the same thing, just defined in different places.

Re: Host, service and template value precendence?

Posted: Thu Jun 25, 2015 4:06 pm
by nagiosadmin42
Hi tmcdonald,

It would be a VERY useful feature in NagiosXI to be able to display a host/service's inheritance list.

When I have to change a setting, it's a tedious process to manually search through a host/service's various configuration screens to determine where a value comes from. It would make it much easier if the GUI could simply show me the hierarchy, and let me edit from there.

Please forward to your planning team for consideration in a future release.

Thanks!

Alan

Re: Host, service and template value precendence?

Posted: Thu Jun 25, 2015 4:10 pm
by tmcdonald
This has been brought up in the past and I took a stab at it about a year ago. The way I remember it, there are issues when you have multiple layers of templates and template options like null/skip. When it was explained to me initially, I was not as familiar with the inner workings of the CCM. I can certainly bring it back up for discussion, but this is not the first time it has been mentioned.