Host, service and template value precendence?

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Host, service and template value precendence?

Post 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
}
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Host, service and template value precendence?

Post 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?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: Host, service and template value precendence?

Post 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.
User avatar
lmiltchev
Former Nagios Staff
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Host, service and template value precendence?

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: Host, service and template value precendence?

Post 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.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Host, service and template value precendence?

Post 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.
Former Nagios employee
nagiosadmin42
Posts: 96
Joined: Sat Feb 11, 2012 2:16 pm

Re: Host, service and template value precendence?

Post 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
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Host, service and template value precendence?

Post 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.
Former Nagios employee
Locked