Nagios Core Configuration - templates

In the case that you have followed steps mentioned at installation of the Nagios Core document at this web page the predefined configuration file with templates related objects are located at:

/opt/nagios-<VERSION>/etc/objects/templates.cfg

Preface

Nagios Core is providing us possibility to split configuration in to several objects. We just need to keep one object in one file.

On another hand it’s possible to use definition of already configured object inside of another objects. In this way we can benefit from the inherency of the object configuration.

In this way Nagios Core is providing us possibility to create a “template” object that will define reoccurring configuration on same type of objects.

It’s nice way how to centralize configuration of multiple objects. In case that we’ll need to update one parameter at several objects, it’s enough to do the update only on “template” obejct level.

Granularity

Template object definition is not related to just one Nagios Core Configuration Object.

With help of “template” object we can centralize configuration for any of configuration objects. It mean that even “template” object definition can use another “template” object.

As well it’s possible to use multiple templates inside of one Nagios Core Configuration Object.

Inherency

Probably you’ve been already thinking about possibility to define one default value that will be used at your Nagios Core Configuration Objects. In case like this, to use a “template” object is the best way how to handle it.

On another hand sometime we’ll need to use as well customization of the standard, for hand full of configuration objects. In case like this it’s possible to use “template” object to define default value for that will be customized at each “configuration” object, when it’s required.

It’s possible to think about this like:

Until we are using “template” configuration and we don’t specify particular parameter at “configuration” object, Nagios Core will use value defined at “template” object.

On another hand, in case that we’ll use template, but we’ll change particular value at “configuration” object, Nagios Core will use the more specific value for this parameter. Defined at “configuration” object, but not the one defined at “template” object (it’s the same in case that “template” object is using another ”template” object).

Templates

Location

Nagios Core is providing to you already predefined set of “service” objects that is possible to copy and modify to for your node.
Located at (in the case that you have followed the installation of Nagios Core described on this website):
/opt/nagios-<VERSION>/etc/objects/templates.cfg

Location Customization

In the case that you prefer to use your own configuration file, to store your customized configuration it is possible to define path to your configuration file.

In this case Nagios Core need to know where to search for the customized configuration file.

According to this it is required to update the main Nagios Core configuration file – “nagios.cfg”
It is possible to specify:

cfg_file=/<path>/<to>/<your>/<config>/<file>         # Direct path to you customized configuration file
cfg_dir=/<path>/<to>/<your>/<config>/<dir>           # Path to the directory where to search for the config file.

Unofficial documentation

In most of my documents I’m preventing to copying of the official documentation. On another hand I think at this point it is really handy as I will not reinvent the wheel.

In this case I haven’t found any official documentation. According to this I’ll try to summarize it.

Description:

In this case we don't speak about regular Nagios Core Configuration Object. Template object can be created based on any regular Nagios Core Configuration Object Parameters, or based on User Defined / Custom Parameters.

It’s possible to use it for central management of values used at multiple Nagios Core Configuration Objects.

Definition Format:

define <object_tipe>{
                     name           <name_of_template>                 # Mandatory parameter
                     register       0                                  # Mandatory parameter
                     use            <name_of_another_tempalte>
                     .
                     .
                     .
                    }

Directive Descriptions:

object_tipe Please replace it with the name of Nagios Core Configuration Object that the template will be related to. For example “host”, “service”, “hostgroup”, “servicegroup”, “command” … .
name Name of the template. This name will be used to include template configuration to another Nagios Core Configuration object.
register To configure object as a “template” object is required to use the value “0”. In this way Nagios Core will not use this object only as “template” object and not as “independent” object.0= “template” object ;1=“standard” object (that is possible to use at Nagios Core)
use Including another template in to object definition.
... Parameters related to “template” object. According to the type of “template” object we can use standard Nagios Core values, or user defined Custom values.

Example

Template for multiple hosts

Already at standard Nagios Core object configuration are template used for reducing configuration files.

In this example we’ll use one “template” object that will define common parameters for multiple “host” objects.

In same way it’s possible to configure templates for another “configuration” objects.

define host{                                                             # Type of the tempalte "host"
            name                            xyz-host                     # Name of the tempalte
            check_period                    24x7
            check_interval                  5
            retry_interval                  1
            max_check_attempts              3
            check_command                   check-host-alive
            notification_interval           0
            register                        0
            check_interval                  2
            notification_options            d,f
            contact_groups                  admins
            notifications_enabled           1
            event_handler_enabled           1
            flap_detection_enabled          1
            process_perf_data               1
            retain_status_information       1
            retain_nonstatus_information    1
            notification_period             24x7
            register                        0                            # Don't use this as regular Nagios Core Object
           }

define host{
        host_name                       router-xyz1.xyz.org
        alias                           router-xyz1
        check_interval                  3
        address                         10.0.0.1
        use                             xyz-host                         # Include values from template
       }

define host{
        host_name                       router-xyz2.xyz.org
        alias                           router-xyz2
        address                         10.0.0.3
        use                             xyz-host                         # Include values from template
       }

After reloading of Nagios Core configuration it’s possible to check object configuration at Web GUI or at “status.dat” file.

[root@NagiosCore ~]# less /opt/nagios-4.0.7/var/status.dat
...
hoststatus {
        host_name=router-xyz1.xyz.org
        modified_attributes=0
        check_command=check-host-alive
        check_period=24x7
        notification_period=24x7
        check_interval=3.000000
        retry_interval=1.000000
        event_handler=
        has_been_checked=1
        should_be_scheduled=1
        check_execution_time=4.011
        check_latency=0.000
        check_type=0
        current_state=0
        last_hard_state=0
        last_event_id=792
        current_event_id=846
        current_problem_id=0
        last_problem_id=286
        plugin_output=PING OK - Packet loss = 0%, RTA = 0.11 ms
        long_plugin_output=
        performance_data=rta=0.113000ms;3000.000000;5000.000000;0.000000 pl=0%;80;100;0
        last_check=1410630521
        next_check=1410630705
        check_options=0
        current_attempt=1
        max_attempts=3
        state_type=1
        last_state_change=1410629605
        last_hard_state_change=1410629605
        last_time_up=1410630525
        last_time_down=1410629605
        last_time_unreachable=1410202003
        last_notification=0
        next_notification=0
        no_more_notifications=0
        current_notification_number=0
        current_notification_id=164
        notifications_enabled=1
        problem_has_been_acknowledged=0
        acknowledgement_type=0
        active_checks_enabled=1
        passive_checks_enabled=1
        event_handler_enabled=1
        flap_detection_enabled=1
        process_performance_data=1
        obsess=1
        last_update=1410630593
        is_flapping=0
        percent_state_change=4.80
        scheduled_downtime_depth=0
        }
...
hoststatus {
        host_name=router-xyz2.xyz.org
        modified_attributes=0
        check_command=check-host-alive
        check_period=24x7
        notification_period=24x7
        check_interval=5.000000
        retry_interval=1.000000
        event_handler=
        has_been_checked=1
        should_be_scheduled=1
        check_execution_time=4.007
        check_latency=0.000
        check_type=0
        current_state=0
        last_hard_state=1
        last_event_id=761
        current_event_id=849
        current_problem_id=0
        last_problem_id=262
        plugin_output=PING OK - Packet loss = 0%, RTA = 0.10 ms
        long_plugin_output=
        performance_data=rta=0.098000ms;3000.000000;5000.000000;0.000000 pl=0%;80;100;0
        last_check=1410630361
        next_check=1410630665
        check_options=0
        current_attempt=1
        max_attempts=3
        state_type=1
        last_state_change=1410630365
        last_hard_state_change=1410630365
        last_time_up=1410621187
        last_time_down=1410630365
        last_time_unreachable=1410202003
        last_notification=0
        next_notification=0
        no_more_notifications=0
        current_notification_number=0
        current_notification_id=138
        notifications_enabled=1
        problem_has_been_acknowledged=0
        acknowledgement_type=0
        active_checks_enabled=1
        passive_checks_enabled=1
        event_handler_enabled=1
        flap_detection_enabled=1
        process_performance_data=1
        obsess=1
        last_update=1410630593
        is_flapping=0
        percent_state_change=6.12
        scheduled_downtime_depth=0
        }
...

Include "template" in "template"

In many situation it’s needed to split the configuration to several templates that will use definition of each another.

Example where to use this is situation, when we are using global values for each “host” in monitoring. In the case that particular “host” will need to customize some global value it’s possible to create specific template. The global template will be used as default definition of values that aren’t customized at our custom template.

define host{                                                             # Type of the tempalte "host"
            name                            custom-host                  # Name of the tempalte
            check_period                    24x7
            check_interval                  5                            # More specific / Custom value
            retry_interval                  1
            max_check_attempts              3
            check_command                   check-host-alive
            notification_interval           0
            register                        0                            # Don't use this as regular Nagios Core Object
            use                             global-host                  # Include Global Host Template
           }
define host{                                                             # Type of the tempalte "host"
            name                            global-host                  # Name of the tempalte
            check_interval                  2                            # Global Value
            notification_options            d,f
            contact_groups                  admins
            notifications_enabled           1
            event_handler_enabled           1
            flap_detection_enabled          1
            process_perf_data               1
            retain_status_information       1
            retain_nonstatus_information    1
            notification_period             24x7
            register                        0                            # Don't use this as regular Nagios Core Object
        }

define host{
        host_name                       router-xyz1.xyz.org
        alias                           router-xyz1
        check_interval                  3
        address                         10.0.0.1
        use                             custom-host                      # Include values from template
       }

define host{
        host_name                       router-xyz2.xyz.org
        alias                           router-xyz2
        address                         10.0.0.3
        use                             custom-host                       # Include values from template
       }

After reloading of Nagios Core configuration it’s possible to check object configuration at Web GUIor at “status.dat” file.

To prevent duplicity of information I will skip the uninteresting part. For full output of “status.dat” for mentioned “hosts” please check pervious example.

[root@NagiosCore ~]# less /opt/nagios-4.0.7/var/status.dat
...
hoststatus {
        host_name=router-xyz1.xyz.org
...
        check_interval=3.000000                                      # Using Value defined at "host" object
        }
...
hoststatus {
        host_name=router-xyz2.xyz.org
...
        check_interval=5.000000                                     # Using value defined at "custom-host" object
        }
...

Overwrite “template” value

In this case we’ll use values of “template” object, that will be included and overwritten at another “template” object and we’ll overwrite them at “host” object level as well.

In this way it’s possible to use global configuration, which can be customized for group of device. In the case that we have particular device that need higher level of customization, we can satisfy as well this need.

define host{                                                             # Type of the tempalte "host"
            name                            custom-host                  # Name of the tempalte
            check_period                    24x7
            check_interval                  5                            # More specific / Custom value
            retry_interval                  1
            max_check_attempts              3
            check_command                   check-host-alive
            notification_interval           0
            register                        0                            # Don't use this as regular Nagios Core Object
            use                             global-host                  # Include Global Host Template
           }
define host{                                                             # Type of the tempalte "host"
            name                            global-host                  # Name of the tempalte
            check_interval                  2                            # Global Value
            notification_options            d,f
            contact_groups                  admins
            notifications_enabled           1
            event_handler_enabled           1
            flap_detection_enabled          1
            process_perf_data               1
            retain_status_information       1
            retain_nonstatus_information    1
            notification_period             24x7
            register                        0                            # Don't use this as regular Nagios Core Object
        }

define host{
        host_name                       router-xyz1.xyz.org
        alias                           router-xyz1
        check_interval                  3                                # The Most Custom Value in this case
        address                         10.0.0.1
        use                             custom-host                      # Include values from template
       }

define host{
        host_name                       router-xyz2.xyz.org
        alias                           router-xyz2
        address                         10.0.0.3
        use                             custom-host                      # Include values from template
       }

After reloading of Nagios Core configuration it’s possible to check object configuration at Web GUIor at “status.dat” file.

To prevent duplicity of information I will skip the uninteresting part. For full output of “status.dat” for mentioned “hosts” please check pervious example.

[root@NagiosCore ~]# less /opt/nagios-4.0.7/var/status.dat
...
hoststatus {
        host_name=router-xyz1.xyz.org
...
        check_interval=3.000000                                      # Using Value defined at "host" object
        }
...
hoststatus {
        host_name=router-xyz2.xyz.org
...
        check_interval=5.000000                                      # Using value defined at "custom-host" object
        }
...
Navigation
Print/export
QR Code
QR Code wiki:infrastructure_tools:nagios:nagios_core_configuration_-_templates (generated for current page)