Page 1 of 1
Template Overload and Confusion
Posted: Tue Jun 04, 2019 3:01 pm
by jbpatric
To begin, I'm not sure how to write this up because my level of confusion and frustration has been compounding the more I look into using templates. Much of my frustration comes from not being able to find clear documentation, forum posts or a YouTube video that explains the big picture of templates in a clear and to the point way. There are many sources of information that explains what a template is, both host and service, but I can't find anything that explains, clearly, what happens when you have multiple templates applied at the various locations in CCM. I've been searching and reading all I can find for several days now and all I have accomplished is confusing myself more than I was when I started.
I've read over this document,
https://assets.nagios.com/downloads/nag ... add_string. It attempts to explain how templates, applied to host/host group/service/service group, plus how inheritance comes into play and how templates can chain together...but this where I go off the rails. When you start looking at all the places you can apply a template, on a host or service via Manage Templates (which can be more than one template), on a host or service group via the Manage Templates in the host or service template management page (which a host can be in multiple host/service groups that apply a template each) your head begins to spin. With all of these options what's the best method for assigning settings via templates? And, how do you know that final outcome will be for the host or service configuration when Nagios combines settings from the host or service with multiple templates? Is there a utility or command you can run to show the final state configuration or do you have to go to paper and write it all down?
What I am trying to setup...
We've exported our long running Core configuration and have imported it into Nagios XI. Over the years our Core configuration became a jumbled up mess of standards. Before we make the final cut over to the new server I want to clean up and standardize the applying of various settings, like, contact(s) or contact group(s) based on host group or service group, check settings, etc. But, how do I know the order the templates will apply? Something else that's not document very well, does using the "+" contact inheritable option in all the template combine the contacts or contact groups into a single large list?
I'm going to stop this message here because it is becoming very long and, you got it, confusing. The bottom line, is there a template best practice guide or tool set that I haven't found?
Re: Template Overload and Confusion
Posted: Tue Jun 04, 2019 4:21 pm
by benjaminsmith
Hi
@jbpatric,
Hopefully, we can help shed some light on this for you. As you know, there are a number of rules associated with template inheritance and it can become complex, so it's best to keep things simple to start.
For documentation, besides the
Nagios Core documentation you have referenced, the following guide also covers the use of templates in the CCM within Nagios XI.
Using The Core Config Manager For Host Management
Multiple templates can be used in a layering fashion. As Nagios core reads the object definition, it then looks at the first template and obtains the settings. It then looks at the next template and layers those settings over the top of the previous settings. This process continues until the final definition is created. In the XI GUI, with multiple templates, the template at the bottom of the list will be overwritten by a template settings above it. The order of preference can be set in the interface.
templates-nagios-gui.png
If you are unsure of the final combination, you can view the objects.cache ( at
/usr/local/nagios/var/objects.cache ) that is created by Nagios Core. The + option used in the settings is an additive identifier and it allows the use of inherited values and the local value together.
Hope that helps. Let us know if you have further questions.
Re: Template Overload and Confusion
Posted: Wed Jun 05, 2019 6:46 am
by jbpatric
Thanks, that helps some. But, I still need some clarification how templates apply when they are assigned from different sources. The documentation is light on details when templates are applied at the host/service level along with at the group level and when templates are linked to templates.
For example:
host-a has template-x assigned to it
the host has a couple contact groups assigned to it, among other settings
I understand that the host settings take priority over template settings
template-x is linked to template-y via Manage Templates under the template-x settings
host-a is also assigned to two host groups, host-grp-a and host-grp-b
host-grp-a has template-z assigned to it
template-z adds two more contact groups, using the "+" option
host-grp-b has template-a assigned to it
template-a has settings for check and retry intervals along with max check attempts plus some other alert settings.
Which, all of these settings will not apply if the host has them set so they need to blanked out on the host
In what order does all of this get applied?
I'll take a look at the objects.cache, should be helpful. A helpful future feature to add could be a option to display the final combination under the host information in the web gui.
Also, doing a deep dive video on this topic would be very helpful!
Re: Template Overload and Confusion
Posted: Wed Jun 05, 2019 7:21 am
by jbpatric
Follow up...
The objects.cache is very helpful. Have been doing some trial and error work this morning and this is what I found out...
The templates assigned to a group are not being applied.
Is this right? If so, what's the point of assigning a template to a group? Can templates only be applied to hosts and services?
Re: Template Overload and Confusion
Posted: Wed Jun 05, 2019 10:51 am
by benjaminsmith
Hi
@jbpatric,
Yes, the objects.cache is very helpful. There are also a few tools in the Nagios XI user interface to help understand object relationships.
In the Core Configuration Manager, click on the relationship link.
Untitled.png
This will display the object relationships.
relationshipds.png
In the object definitions, you can't assign values from the template to the hostgroup as they are only a group of hosts in the core. If you want to make changes to a group of sevices or hosts in XI, use the Bulk Modifications Tool ( Configure > Tools > Bulk Modifications Tool).
Re: Template Overload and Confusion
Posted: Fri Jun 07, 2019 7:09 am
by jbpatric
Another follow up question...
What is the relationship between the host and service settings?
Do all the settings applied at the host level flow down to all of the service checks under that host?
And, do the service settings override the host settings?
Re: Template Overload and Confusion
Posted: Fri Jun 07, 2019 9:41 am
by lmiltchev
Most of the time, the host and service settings are defined separately. They are independent of each other, and don't "flow down from hosts to services". Even though, some of the directives in the configs are the same, they may take a different values.
Example:
define host {
host_name host_name
alias alias
display_name display_name
address address
parents host_names
importance #
hostgroups hostgroup_names
check_command command_name
initial_state [o,d,u]
max_check_attempts #
check_interval #
retry_interval #
active_checks_enabled [0/1]
passive_checks_enabled [0/1]
check_period timeperiod_name
obsess_over_host|obsess [0/1]
check_freshness [0/1]
freshness_threshold #
event_handler command_name
event_handler_enabled [0/1]
low_flap_threshold #
high_flap_threshold #
flap_detection_enabled [0/1]
flap_detection_options [o,d,u]
process_perf_data [0/1]
retain_status_information [0/1]
retain_nonstatus_information [0/1]
contacts contacts
contact_groups contact_groups
notification_interval #
first_notification_delay #
notification_period timeperiod_name
notification_options [d,u,r,f,s]
notifications_enabled [0/1]
stalking_options [o,d,u,N]
notes note_string
notes_url url
action_url url
icon_image image_file
icon_image_alt alt_string
vrml_image image_file
statusmap_image image_file
2d_coords x_coord,y_coord
3d_coords x_coord,y_coord,z_coord
}
define service{
host_name host_name
hostgroup_name hostgroup_name
service_description service_description
display_name display_name
parents service_descriptions
importance #
servicegroups servicegroup_names
is_volatile [0/1]
check_command command_name
initial_state [o,w,u,c]
max_check_attempts #
check_interval #
retry_interval #
active_checks_enabled [0/1]
passive_checks_enabled [0/1]
check_period timeperiod_name
obsess_over_service|obsess [0/1]
check_freshness [0/1]
freshness_threshold #
event_handler command_name
event_handler_enabled [0/1]
low_flap_threshold #
high_flap_threshold #
flap_detection_enabled [0/1]
flap_detection_options [o,w,c,u]
process_perf_data [0/1]
retain_status_information [0/1]
retain_nonstatus_information [0/1]
notification_interval #
first_notification_delay #
notification_period timeperiod_name
notification_options [w,u,c,r,f,s]
notifications_enabled [0/1]
contacts contacts
contact_groups contact_groups
stalking_options [o,w,u,c,N]
notes note_string
notes_url url
action_url url
icon_image image_file
icon_image_alt alt_string
}
There some some cases, where object variables will be implicitly inherited from related objects UNLESS they are explicitly specified in the object definition. This is called "Implied Inheritance", and it is explained in the document that was provided to you by @benjaminsmith:
https://assets.nagios.com/downloads/nag ... tance.html
For example, if you don't explicitly define a contact in the service definition, the contact would be inherited from the host object (this service is added to).