Time-Saving Tricks For Template-Based Object Definitions

or...
"How To Preserve Your Sanity"


Introduction

This documentation attempts to explain how you can exploit the (somewhat) hidden features template-based object definitions to save your sanity. How so, you ask? Several types of objects allow you to specify multiple host names and/or hostgroup names in definitions, allowing you to "copy" the object defintion to multiple hosts or services. I'll cover each type of object that supports these features seperately. For starters, the object types which support this time-saving feature are as follows:

Object types that are not listed above (i.e. timeperiods, commands, etc.) do not support the features I'm about to describe.

Services

Multiple Hosts: If you want to create identical services that are assigned to multiple hosts, you can specify multiple hosts in the host_name directive as follows:

	define service{
		host_name		HOST1,HOST2,HOST3,...,HOSTN
		service_description	SOMESERVICE
		other service directives ...
		}

The definition above would create a service called SOMESERVICE on hosts HOST1 through HOSTN. All the instances of the SOMESERVICE service would be identical (i.e. have the same check command, max check attempts, notification period, etc.).

All Hosts In Multiple Hostgroups: If you want to create identical services that are assigned to all hosts in one or more hostgroups, you can do so by creating a single service definition. How? The hostgroup_name directive allows you to specify the name of one or more hostgroups that the service should be created for:

	define service{
		hostgroup_name		HOSTGROUP1,HOSTGROUP2,...,HOSTGROUPN
		service_description	SOMESERVICE
		other service directives ...
		}

The definition above would create a service called SOMESERVICE on all hosts that are members of hostgroups HOSTGROUP1 through HOSTGROUPN. All the instances of the SOMESERVICE service would be identical (i.e. have the same check command, max check attempts, notification period, etc.).

All Hosts: If you want to create identical services that are assigned to all hosts that are defined in your configuration files, you can use a wildcard in the host_name directive as follows:

	define service{
		host_name		*
		service_description	SOMESERVICE
		other service directives ...
		}

The definition above would create a service called SOMESERVICE on all hosts that are defined in your configuration files. All the instances of the SOMESERVICE service would be identical (i.e. have the same check command, max check attempts, notification period, etc.).

Service Escalations

Multiple Hosts: If you want to create service escalations for services of the same name/description that are assigned to multiple hosts, you can specify multiple hosts in the host_name directive as follows:

	define serviceescalation{
		host_name		HOST1,HOST2,HOST3,...,HOSTN
		service_description	SOMESERVICE
		other escalation directives ...
		}

The definition above would create a service escalation for services called SOMESERVICE on hosts HOST1 through HOSTN. All the instances of the service escalation would be identical (i.e. have the same contact groups, notification interval, etc.).

All Hosts In Multiple Hostgroups: If you want to create service escalations for services of the same name/description that are assigned to all hosts in in one or more hostgroups, you can do use the hostgroup_name directive as follows:

	define serviceescalation{
		hostgroup_name		HOSTGROUP1,HOSTGROUP2,...,HOSTGROUPN
		service_description	SOMESERVICE
		other escalation directives ...
		}

The definition above would create a service escalation for services called SOMESERVICE on all hosts that are members of hostgroups HOSTGROUP1 through HOSTGROUPN. All the instances of the service escalation would be identical (i.e. have the same contact groups, notification interval, etc.).

All Hosts: If you want to create identical service escalations for services of the same name/description that are assigned to all hosts that are defined in your configuration files, you can use a wildcard in the host_name directive as follows:

	define serviceescalation{
		host_name		*
		service_description	SOMESERVICE
		other escalation directives ...
		}

The definition above would create a service escalation for all services called SOMESERVICE on all hosts that are defined in your configuration files. All the instances of the service escalation would be identical (i.e. have the same contact groups, notification interval, etc.).

Multiple Services: If you want to create service escalations for all services assigned to a particular host, you can use a wildcard in the service_description directive as follows:

	define serviceescalation{
		host_name		HOST1
		service_description	*
		other escalation directives ...
		}

The definition above would create a service escalation for all services on host HOST1. All the instances of the service escalation would be identical (i.e. have the same contact groups, notification interval, etc.).

If you feel like being particularly adventurous, you can specify a wildcard in both the host_name and service_description directives. Doing so would create a service escalation for all services that you've defined in your configuration files.

Service Dependencies

Multiple Hosts: If you want to create service dependencies for services of the same name/description that are assigned to multiple hosts, you can specify multiple hosts in the host_name and or dependent_host_name directives as follows:

	define servicedependency{
		host_name			HOST1,HOST2
		service_description		SERVICE1
		dependent_host_name		HOST3,HOST4
		dependent_service_description	SERVICE2
		other dependency directives ...
		}

In the example above, service SERVICE2 on hosts HOST3 and HOST4 would be dependent on service SERVICE1 on hosts HOST1 and HOST2. All the instances of the service dependencies would be identical except for the host names (i.e. have the same notification failure criteria, etc.).

All Hosts In Multiple Hostgroups: If you want to create service dependencies for services of the same name/description that are assigned to all hosts in in one or more hostgroups, you can do use the hostgroup_name and/or dependent_hostgroup_name directives as follows:

	define servicedependency{
		hostgroup_name			HOSTGROUP1,HOSTGROUP2
		service_description		SERVICE1
		dependent_hostgroup_name	HOSTGROUP3,HOSTGROUP4
		dependent_service_description	SERVICE2
		other dependency directives ...
		}

In the example above, service SERVICE2 on all hosts in hostgroups HOSTGROUP3 and HOSTGROUP4 would be dependent on service SERVICE1 on all hosts in hostgroups HOSTGROUP1 and HOSTGROUP2. Assuming there were five hosts in each of the hostgroups, this definition would be equivalent to creating 100 single service dependency definitions! All the instances of the service dependency would be identical except for the host names (i.e. have the same notification failure criteria, etc.).

Multiple Services: If you want to create service dependencies for all services assigned to a particular host, you can use a wildcard in the service_description and/or dependent_service_description directives as follows:

	define servicedependency{
		host_name			HOST1
		service_description		*
		dependent_host_name		HOST2
		dependent_service_description	*
		other dependency directives ...
		}

In the example above, all services on host HOST2 would be dependent on all services on host HOST1. All the instances of the service dependencies would be identical (i.e. have the same notification failure criteria, etc.).

Host Escalations

Multiple Hosts: If you want to create host escalations for multiple hosts, you can specify multiple hosts in the host_name directive as follows:

	define hostescalation{
		host_name		HOST1,HOST2,HOST3,...,HOSTN
		other escalation directives ...
		}

The definition above would create a host escalation for hosts HOST1 through HOSTN. All the instances of the host escalation would be identical (i.e. have the same contact groups, notification interval, etc.).

All Hosts In Multiple Hostgroups: If you want to create host escalations for all hosts in in one or more hostgroups, you can do use the hostgroup_name directive as follows:

	define hostescalation{
		hostgroup_name		HOSTGROUP1,HOSTGROUP2,...,HOSTGROUPN
		other escalation directives ...
		}

The definition above would create a host escalation on all hosts that are members of hostgroups HOSTGROUP1 through HOSTGROUPN. All the instances of the host escalation would be identical (i.e. have the same contact groups, notification interval, etc.).

All Hosts: If you want to create identical host escalations for all hosts that are defined in your configuration files, you can use a wildcard in the host_name directive as follows:

	define hostescalation{
		host_name		*
		other escalation directives ...
		}

The definition above would create a hosts escalation for all hosts that are defined in your configuration files. All the instances of the host escalation would be identical (i.e. have the same contact groups, notification interval, etc.).

Host Dependencies

Multiple Hosts: If you want to create host dependencies for multiple hosts, you can specify multiple hosts in the host_name and/or dependent_host_name directives as follows:

	define hostdependency{
		host_name		HOST1,HOST2
		dependent_host_name	HOST3,HOST4,HOST5
		other dependency directives ...
		}

The definition above would be equivalent to creating six seperate host dependencies. In the example above, hosts HOST3, HOST4 and HOST5 would be dependent upon both HOST1 and HOST2. All the instances of the host dependencies would be identical except for the host names (i.e. have the same notification failure criteria, etc.).

All Hosts In Multiple Hostgroups: If you want to create host escalations for all hosts in in one or more hostgroups, you can do use the hostgroup_name and /or dependent_hostgroup_name directives as follows:

	define hostdependency{
		hostgroup_name			HOSTGROUP1,HOSTGROUP2
		dependent_hostgroup_name	HOSTGROUP3,HOSTGROUP4
		other dependency directives ...
		}

In the example above, all hosts in hostgroups HOSTGROUP3 and HOSTGROUP4 would be dependent on all hosts in hostgroups HOSTGROUP1 and HOSTGROUP2. All the instances of the host dependencies would be identical except for host names (i.e. have the same notification failure criteria, etc.).

Hostgroups

All Hosts: If you want to create a hostgroup that has all hosts that are defined in your configuration files as members, you can use a wildcard in the members directive as follows:

	define hostgroup{
		hostgroup_name		HOSTGROUP1
		members			*
		other hostgroup directives ...
		}

The definition above would create a hostgroup called HOSTGROUP1 that has all all hosts that are defined in your configuration files as members.

Hostgroup Escalations

Multiple Hostgroups: If you want to create identical hostgroup escalations that are assigned to multiple hostgroups, you can specify multiple hostgroups in the hostgroup_name directive as follows:

	define hostgroupescalation{
		hostgroup_name		HOSTGROUP1,HOSTGROUP2,...,HOSTGROUPN
		other escalation directives ...
		}

The definition above would create a seperate hostgroup escalation for hostgroups HOSTGROUP1 through HOSTGROUPN. All the instances of the hostgroup escalation would be identical (i.e. contact groups, notification interval, etc.).