1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
9
<title>Time-Saving Tricks For Object Definitions</title>
13
<STYLE type="text/css">
17
.Default { font-family: verdana,arial,serif; font-size: 8pt; }
19
.PageTitle { font-family: verdana,arial,serif; font-size: 16pt; font-weight: bold; }
31
<body bgcolor="#FFFFFF" text="black" class="Default">
37
<img src="images/nagios.jpg" border="0" alt="Nagios" title="Nagios">
39
<h1 class="PageTitle">Time-Saving Tricks For Object Definitions</h1>
43
<b>"How To Preserve Your Sanity"</b>
55
<img src="images/upto.gif" border="0" align="middle" alt="Up To" title="Up To">Up To: <a href="toc.html">Contents</a><br>
57
<img src="images/seealso.gif" border="0" align="middle" alt="See Also" title="See Also"> See Also: <a href="objectdefinitions.html">Object Configuration</a>, <a href="objectinheritance.html">Object Inheritance</a>
65
<strong><u>Introduction</u></strong>
73
This documentation attempts to explain how you can exploit the (somewhat) hidden features of <a href="objectdefinitions.html">template-based object definitions</a> 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:
81
<li><a href="#service">Services</a>
83
<li><a href="#serviceescalation">Service escalations</a>
85
<li><a href="#servicedependency">Service dependencies</a>
87
<li><a href="#hostescalation">Host escalations</a>
89
<li><a href="#hostdependency">Host dependencies</a>
91
<li><a href="#hostgroup">Hostgroups</a>
99
Object types that are not listed above (i.e. timeperiods, commands, etc.) do not support the features I'm about to describe.
107
<strong><u>Regular Expression Matching</u></strong>
115
The examples I give below use "standard" matching of object names
117
and <b>*require*</b> <a href="configmain.html#use_regexp_matching">use_regexp_matching</a> to be <b>*disabled*</b>.
125
If you wish, you can enable regular expression matching for object names by using the <a href="configmain.html#use_regexp_matching">use_regexp_matching</a> config option. By default, regular expression matching will only be used in object names that contain <b>*</b>, <b>?</b>, <b>+</b>, or <b>\.</b>. If you want regular expression matching to be used on all object names, enable the <a href="configmain.html#use_true_regexp_matching">use_true_regexp_matching</a> config option. Regular expressions can be used in any of the fields used in the examples below (host names, hostgroup names, service names, and servicegroup names).
133
<img src="images/note.gif" border="0" align="bottom" alt="Note" title="Note"> Note: Be careful when enabling regular expression matching - you may have to change your config file, since some directives that you might not want to be interpreted as a regular expression just might be! Any problems should become evident once you verify your configuration.
143
<a name="service"></a>
147
<strong><u>Service Definitions</u></strong>
155
<b>Multiple Hosts:</b><br> If you want to create identical <a href="objectdefinitions.html#service">services</a> that are assigned to multiple hosts, you can specify multiple hosts in the <i>host_name</i> directive. The definition below would create a service called <i>SOMESERVICE</i> on hosts <i>HOST1</i> through <i>HOSTN</i>. All the instances of the <i>SOMESERVICE</i> service would be identical (i.e. have the same check command, max check attempts, notification period, etc.).
163
define <i>service</i>{
165
<font color="red">host_name <i>HOST1,HOST2,HOST3,...,HOSTN</i></font>
167
<font color="red">service_description <i>SOMESERVICE</i></font>
169
<i>other service directives</i> ...
181
<b>All Hosts In Multiple Hostgroups:</b><br>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 <i>hostgroup_name</i> directive allows you to specify the name of one or more hostgroups that the service should be created for. The definition below would create a service called <i>SOMESERVICE</i> on all hosts that are members of hostgroups <i>HOSTGROUP1</i> through <i>HOSTGROUPN</i>. All the instances of the <i>SOMESERVICE</i> service would be identical (i.e. have the same check command, max check attempts, notification period, etc.).
189
define <i>service</i>{
191
<font color="red">hostgroup_name <i>HOSTGROUP1,HOSTGROUP2,...,HOSTGROUPN</i></font>
193
<font color="red">service_description <i>SOMESERVICE</i></font>
195
<i>other service directives</i> ...
205
<b>All Hosts:</b><br> 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 <i>host_name</i> directive. The definition below would create a service called <i>SOMESERVICE</i> on <b>all hosts</b> that are defined in your configuration files. All the instances of the <i>SOMESERVICE</i> service would be identical (i.e. have the same check command, max check attempts, notification period, etc.).
213
define <i>service</i>{
215
<font color="red">host_name <i>*</i></font>
217
<font color="red">service_description <i>SOMESERVICE</i></font>
219
<i>other service directives</i> ...
229
<b>Excluding Hosts:</b><br>If you want to create identical services on numerous hosts or hostgroups, but would like to exclude some hosts from the definition, this can be accomplished by preceding the host or hostgroup with a ! symbol.
237
define <i>service</i>{
239
<font color="red">host_name <i>HOST1,HOST2,!HOST3,!HOST4,...,HOSTN</i></font>
241
<font color="red">hostgroup_name <i>HOSTGROUP1,HOSTGROUP2,!HOSTGROUP3,!HOSTGROUP4,...,HOSTGROUPN</i></font>
243
<font color="red">service_description <i>SOMESERVICE</i></font>
245
<i>other service directives</i> ...
257
<a name="serviceescalation"></a>
261
<strong><u>Service Escalation Definitions</u></strong>
269
<b>Multiple Hosts:</b><br> If you want to create <a href="objectdefinitions.html#serviceescalation">service escalations</a> for services of the same name/description that are assigned to multiple hosts, you can specify multiple hosts in the <i>host_name</i> directive. The definition below would create a service escalation for services called <i>SOMESERVICE</i> on hosts <i>HOST1</i> through <i>HOSTN</i>. All the instances of the service escalation would be identical (i.e. have the same contact groups, notification interval, etc.).
277
define <i>serviceescalation</i>{
279
<font color="red">host_name <i>HOST1,HOST2,HOST3,...,HOSTN</i></font>
281
<font color="red">service_description <i>SOMESERVICE</i></font>
283
<i>other escalation directives</i> ...
295
<b>All Hosts In Multiple Hostgroups:</b><br> 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 <i>hostgroup_name</i> directive. The definition below would create a service escalation for services called <i>SOMESERVICE</i> on all hosts that are members of hostgroups <i>HOSTGROUP1</i> through <i>HOSTGROUPN</i>. All the instances of the service escalation would be identical (i.e. have the same contact groups, notification interval, etc.).
303
define <i>serviceescalation</i>{
305
<font color="red">hostgroup_name <i>HOSTGROUP1,HOSTGROUP2,...,HOSTGROUPN</i></font>
307
<font color="red">service_description <i>SOMESERVICE</i></font>
309
<i>other escalation directives</i> ...
319
<b>All Hosts:</b><br> 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 <i>host_name</i> directive. The definition below would create a service escalation for all services called <i>SOMESERVICE</i> on <b>all hosts</b> 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.).
327
define <i>serviceescalation</i>{
329
<font color="red">host_name <i>*</i></font>
331
<font color="red">service_description <i>SOMESERVICE</i></font>
333
<i>other escalation directives</i> ...
343
<b>Excluding Hosts:</b><br>If you want to create identical services escalations for services on numerous hosts or hostgroups,
345
but would like to exclude some hosts from the definition, this can be accomplished by preceding the host or hostgroup with a ! symbol.
353
define <i>serviceescalation</i>{
355
<font color="red">host_name <i>HOST1,HOST2,!HOST3,!HOST4,...,HOSTN</i></font>
357
<font color="red">hostgroup_name <i>HOSTGROUP1,HOSTGROUP2,!HOSTGROUP3,!HOSTGROUP4,...,HOSTGROUPN</i></font>
359
<font color="red">service_description <i>SOMESERVICE</i></font>
361
<i>other escalation directives</i> ...
371
<b>All Services On Same Host:</b><br> If you want to create <a href="objectdefinitions.html#serviceescalation">service escalations</a> for all services assigned to a particular host, you can use a wildcard in the <i>service_description</i> directive. The definition below would create a service escalation for <b>all</b> services on host <i>HOST1</i>. All the instances of the service escalation would be identical (i.e. have the same contact groups, notification interval, etc.).
377
If you feel like being particularly adventurous, you can specify a wildcard in both the <i>host_name</i> and <i>service_description</i> directives. Doing so would create a service escalation for <b>all services</b> that you've defined in your configuration files.
385
define <i>serviceescalation</i>{
387
<font color="red">host_name <i>HOST1</i></font>
389
<font color="red">service_description <i>*</i></font>
391
<i>other escalation directives</i> ...
403
<b>Multiple Services On Same Host:</b><br> If you want to create <a href="objectdefinitions.html#serviceescalation">service escalations</a> for all multiple services assigned to a particular host, you can use a specify more than one service description in the <i>service_description</i> directive. The definition below would create a service escalation for services <i>SERVICE1</i> through <i>SERVICEN</i> on host <i>HOST1</i>. All the instances of the service escalation would be identical (i.e. have the same contact groups, notification interval, etc.).
411
define <i>serviceescalation</i>{
413
<font color="red">host_name <i>HOST1</i></font>
415
<font color="red">service_description <i>SERVICE1,SERVICE2,...,SERVICEN</i></font>
417
<i>other escalation directives</i> ...
427
<b>All Services In Multiple Servicegroups:</b><br> If you want to create service escalations for all services that belong in one or more servicegroups, you can do use the <i>servicegroup_name</i> directive. The definition below would create service escalations for all services that are members of servicegroups <i>SERVICEGROUP1</i> through <i>SERVICEGROUPN</i>. All the instances of the service escalation would be identical (i.e. have the same contact groups, notification interval, etc.).
435
define <i>serviceescalation</i>{
437
<font color="red">servicegroup_name <i>SERVICEGROUP1,SERVICEGROUP2,...,SERVICEGROUPN</i></font>
439
<i>other escalation directives</i> ...
451
<a name="servicedependency"></a>
455
<strong><u>Service Dependency Definitions</u></strong>
463
<b>Multiple Hosts:</b><br> If you want to create <a href="objectdefinitions.html#servicedependency">service dependencies</a> for services of the same name/description that are assigned to multiple hosts, you can specify multiple hosts in the <i>host_name</i> and or <i>dependent_host_name</i> directives. In the example below, service <i>SERVICE2</i> on hosts <i>HOST3</i> and <i>HOST4</i> would be dependent on service <i>SERVICE1</i> on hosts <i>HOST1</i> and <i>HOST2</i>. All the instances of the service dependencies would be identical except for the host names (i.e. have the same notification failure criteria, etc.).
471
define <i>servicedependency</i>{
473
<font color="red">host_name <i>HOST1,HOST2</i></font>
475
<font color="red">service_description <i>SERVICE1</i></font>
477
<font color="red">dependent_host_name <i>HOST3,HOST4</i></font>
479
<font color="red">dependent_service_description <i>SERVICE2</i></font>
481
<i>other dependency directives</i> ...
491
<b>All Hosts In Multiple Hostgroups:</b><br> 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 <i>hostgroup_name</i> and/or <i>dependent_hostgroup_name</i> directives. In the example below, service <i>SERVICE2</i> on all hosts in hostgroups <i>HOSTGROUP3</i> and <i>HOSTGROUP4</i> would be dependent on service <i>SERVICE1</i> on all hosts in hostgroups <i>HOSTGROUP1</i> and <i>HOSTGROUP2</i>. 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.).
499
define <i>servicedependency</i>{
501
<font color="red">hostgroup_name <i>HOSTGROUP1,HOSTGROUP2</i></font>
503
<font color="red">service_description <i>SERVICE1</i></font>
505
<font color="red">dependent_hostgroup_name <i>HOSTGROUP3,HOSTGROUP4</i></font>
507
<font color="red">dependent_service_description <i>SERVICE2</i></font>
509
<i>other dependency directives</i> ...
519
<b>All Services On A Host:</b><br> If you want to create service dependencies for all services assigned to a particular host, you can use a wildcard in the <i>service_description</i> and/or <i>dependent_service_description</i> directives. In the example below, <b>all services</b> on host <i>HOST2</i> would be dependent on <b>all services</b> on host <i>HOST1</i>. All the instances of the service dependencies would be identical (i.e. have the same notification failure criteria, etc.).
527
define <i>servicedependency</i>{
529
<font color="red">host_name <i>HOST1</i></font>
531
<font color="red">service_description <i>*</i></font>
533
<font color="red">dependent_host_name <i>HOST2</i></font>
535
<font color="red">dependent_service_description <i>*</i></font>
537
<i>other dependency directives</i> ...
547
<b>Multiple Services On A Host:</b><br> If you want to create service dependencies for multiple services assigned to a particular host, you can specify more than one service description in the <i>service_description</i> and/or <i>dependent_service_description</i> directives as follows:
555
define <i>servicedependency</i>{
557
<font color="red">host_name <i>HOST1</i></font>
559
<font color="red">service_description <i>SERVICE1,SERVICE2,...,SERVICEN</i></font>
561
<font color="red">dependent_host_name <i>HOST2</i></font>
563
<font color="red">dependent_service_description <i>SERVICE1,SERVICE2,...,SERVICEN</i></font>
565
<i>other dependency directives</i> ...
575
<b>All Services In Multiple Servicegroups:</b><br> If you want to create service dependencies for all services that belong in one or more servicegroups, you can do use the <i>servicegroup_name</i> and/or <i>dependent_servicegroup_name</i> directive as follows:
583
define <i>servicedependency</i>{
585
<font color="red">servicegroup_name <i>SERVICEGROUP1,SERVICEGROUP2,...,SERVICEGROUPN</i></font>
587
<font color="red">dependent_servicegroup_name <i>SERVICEGROUP3,SERVICEGROUP4,...SERVICEGROUPN</i></font>
589
<i>other dependency directives</i> ...
597
<a name="same_host_dependency"></a>
601
<b>Same Host Dependencies:</b><br> If you want to create service dependencies for multiple services that are dependent on services on the same host, leave the <i>dependent_host_name</i> and <i>dependent_hostgroup_name</i> directives empty. The example below assumes that hosts <i>HOST1</i> and <i>HOST2</i> have at least the following four services associated with them: <i>SERVICE1</i>, <i>SERVICE2</i>, <i>SERVICE3</i>, and <i>SERVICE4</i>. In this example, <i>SERVICE3</i> and <i>SERVICE4</i> on <i>HOST1</i> will be dependent on both <i>SERVICE1</i> and <i>SERVICE2</i> on <i>HOST1</i>. Similiarly, <i>SERVICE3</i> and <i>SERVICE4</i> on <i>HOST2</i> will be dependent on both <i>SERVICE1</i> and <i>SERVICE2</i> on <i>HOST2</i>.
609
define <i>servicedependency</i>{
611
<font color="red">host_name <i>HOST1,HOST2</i></font>
613
<font color="red">service_description <i>SERVICE1,SERVICE2</i></font>
615
<font color="red">dependent_service_description <i>SERVICE3,SERVICE4</i></font>
617
<i>other dependency directives</i> ...
629
<a name="hostescalation"></a>
633
<strong><u>Host Escalation Definitions</u></strong>
641
<b>Multiple Hosts:</b><br> If you want to create <a href="objectdefinitions.html#hostescalation">host escalations</a> for multiple hosts, you can specify multiple hosts in the <i>host_name</i> directive. The definition below would create a host escalation for hosts <i>HOST1</i> through <i>HOSTN</i>. All the instances of the host escalation would be identical (i.e. have the same contact groups, notification interval, etc.).
649
define <i>hostescalation</i>{
651
<font color="red">host_name <i>HOST1,HOST2,HOST3,...,HOSTN</i></font>
653
<i>other escalation directives</i> ...
663
<b>All Hosts In Multiple Hostgroups:</b><br> If you want to create host escalations for all hosts in in one or more hostgroups, you can do use the <i>hostgroup_name</i> directive. The definition below would create a host escalation on all hosts that are members of hostgroups <i>HOSTGROUP1</i> through <i>HOSTGROUPN</i>. All the instances of the host escalation would be identical (i.e. have the same contact groups, notification interval, etc.).
671
define <i>hostescalation</i>{
673
<font color="red">hostgroup_name <i>HOSTGROUP1,HOSTGROUP2,...,HOSTGROUPN</i></font>
675
<i>other escalation directives</i> ...
685
<b>All Hosts:</b><br> 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 <i>host_name</i> directive. The definition below would create a hosts escalation for <b>all hosts</b> 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.).
693
define <i>hostescalation</i>{
695
<font color="red">host_name <i>*</i></font>
697
<i>other escalation directives</i> ...
707
<b>Excluding Hosts:</b><br>If you want to create identical host escalations on numerous hosts or hostgroups, but would like to
709
exclude some hosts from the definition, this can be accomplished by preceding the host or hostgroup with a ! symbol.
717
define <i>hostescalation</i>{
719
<font color="red">host_name <i>HOST1,HOST2,!HOST3,!HOST4,...,HOSTN</i></font>
721
<font color="red">hostgroup_name <i>HOSTGROUP1,HOSTGROUP2,!HOSTGROUP3,!HOSTGROUP4,...,HOSTGROUPN</i></font>
723
<i>other escalation directives</i> ...
735
<a name="hostdependency"></a>
739
<strong><u>Host Dependency Definitions</u></strong>
747
<b>Multiple Hosts:</b><br> If you want to create <a href="objectdefinitions.html#hostdependency">host dependencies</a> for multiple hosts, you can specify multiple hosts in the <i>host_name</i> and/or <i>dependent_host_name</i> directives. The definition below would be equivalent to creating six seperate host dependencies. In the example above, hosts <i>HOST3</i>, <i>HOST4</i> and <i>HOST5</i> would be dependent upon both <i>HOST1</i> and <i>HOST2</i>. All the instances of the host dependencies would be identical except for the host names (i.e. have the same notification failure criteria, etc.).
755
define <i>hostdependency</i>{
757
<font color="red">host_name <i>HOST1,HOST2</i></font>
759
<font color="red">dependent_host_name <i>HOST3,HOST4,HOST5</i></font>
761
<i>other dependency directives</i> ...
771
<b>All Hosts In Multiple Hostgroups:</b><br> If you want to create host escalations for all hosts in in one or more hostgroups, you can do use the <i>hostgroup_name</i> and /or <i>dependent_hostgroup_name</i> directives. In the example below, all hosts in hostgroups <i>HOSTGROUP3</i> and <i>HOSTGROUP4</i> would be dependent on all hosts in hostgroups <i>HOSTGROUP1</i> and <i>HOSTGROUP2</i>. All the instances of the host dependencies would be identical except for host names (i.e. have the same notification failure criteria, etc.).
779
define <i>hostdependency</i>{
781
<font color="red">hostgroup_name <i>HOSTGROUP1,HOSTGROUP2</i></font>
783
<font color="red">dependent_hostgroup_name <i>HOSTGROUP3,HOSTGROUP4</i></font>
785
<i>other dependency directives</i> ...
797
<a name="hostgroup"></a>
801
<strong><u>Hostgroups</u></strong>
809
<b>All Hosts:</b><br> 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 <i>members</i> directive. The definition below would create a hostgroup called <i>HOSTGROUP1</i> that has <b>all hosts</b> that are defined in your configuration files as members.
817
define <i>hostgroup</i>{
819
<i>hostgroup_name</i> <i>HOSTGROUP1</i>
821
<font color="red">members <i>*</i></font>
823
<i>other hostgroup directives</i> ...