File: objectinheritance.html

package info (click to toggle)
icinga 1.14.2%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 49,264 kB
  • sloc: ansic: 108,564; sql: 9,656; sh: 4,945; perl: 3,439; makefile: 1,213; php: 581; xml: 104
file content (701 lines) | stat: -rw-r--r-- 33,978 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>7.26. Object Inheritance</title>
<link rel="stylesheet" href="../stylesheets/icinga-docs.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.1">
<meta name="keywords" content="Supervision, Icinga, Nagios, Linux">
<link rel="home" href="index.html" title="Icinga Version 1.14 Documentation">
<link rel="up" href="ch07.html" title="Chapter 7. Advanced Topics">
<link rel="prev" href="modified_attr.html" title="7.25. Modified attributes">
<link rel="next" href="objecttricks.html" title="7.27. Time-Saving Tricks For Object Definitions">
<script src="../js/jquery-min.js" type="text/javascript"></script><script src="../js/icinga-docs.js" type="text/javascript"></script>
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<CENTER><IMG src="../images/logofullsize.png" border="0" alt="Icinga" title="Icinga"></CENTER>
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">7.26. Object Inheritance</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="modified_attr.html">Prev</a> </td>
<th width="60%" align="center">Chapter 7. Advanced Topics</th>
<td width="20%" align="right"> <a accesskey="n" href="objecttricks.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="section" title="7.26. Object Inheritance">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="objectinheritance"></a>7.26. <a name="object_inheritance"></a>Object Inheritance</h2></div></div></div>
<div class="toc"><dl>
<dt><span class="section">7.26.1. <a href="objectinheritance.html#objectinheritance-introduction">Introduction</a></span></dt>
<dt><span class="section">7.26.2. <a href="objectinheritance.html#objectinheritance-basics">Basics</a></span></dt>
<dt><span class="section">7.26.3. <a href="objectinheritance.html#objectinheritance-localvsinveritedvars">Local Variables vs. Inherited Variables</a></span></dt>
<dt><span class="section">7.26.4. <a href="objectinheritance.html#objectinheritance-inheritancechaining">Inheritance Chaining</a></span></dt>
<dt><span class="section">7.26.5. <a href="objectinheritance.html#objectinheritance-templates">Using Incomplete Object Definitions as Templates</a></span></dt>
<dt><span class="section">7.26.6. <a href="objectinheritance.html#objectinheritance-customobjectvariables">Custom Object Variables</a></span></dt>
<dt><span class="section">7.26.7. <a href="objectinheritance.html#objectinheritance-cancel_string">Cancelling Inheritance of String Values</a></span></dt>
<dt><span class="section">7.26.8. <a href="objectinheritance.html#objectinheritance-add_string">Additive Inheritance of String Values</a></span></dt>
<dt><span class="section">7.26.9. <a href="objectinheritance.html#objectinheritance-implied_inheritance">Implied Inheritance</a></span></dt>
<dt><span class="section">7.26.10. <a href="objectinheritance.html#objectinheritance-implied_escalations">Implied/Additive Inheritance in Escalations</a></span></dt>
<dt><span class="section">7.26.11. <a href="objectinheritance.html#objectinheritance-important_values">Important values</a></span></dt>
<dt><span class="section">7.26.12. <a href="objectinheritance.html#objectinheritance-multiple_templates">Multiple Inheritance Sources</a></span></dt>
<dt><span class="section">7.26.13. <a href="objectinheritance.html#objectinheritance-multipleinheritancesources">Precedence With Multiple Inheritance Sources</a></span></dt>
</dl></div>
  

  <div class="section" title="7.26.1. Introduction">
<div class="titlepage"><div><div><h3 class="title">
<a name="objectinheritance-introduction"></a>7.26.1. Introduction</h3></div></div></div>
	  

  <p>This documentation attempts to explain object inheritance and how it can be used in your <a class="link" href="objectdefinitions.html" title="3.4. Object Definitions">object
  definitions</a>.</p>

  <p>If you are confused about how recursion and inheritance work after reading this, take a look at the sample object config files
  provided in the Icinga distribution. If that still doesn't help, drop an email message with a <span class="emphasis"><em>detailed</em></span>
  description of your problem to the <span class="emphasis"><em>icinga-users</em></span> mailing list.</p>

  </div>

  <div class="section" title="7.26.2. Basics">
<div class="titlepage"><div><div><h3 class="title">
<a name="objectinheritance-basics"></a>7.26.2. Basics</h3></div></div></div>
	  

  <p>There are three variables affecting recursion and inheritance that are present in all object definitions. They are
  <span class="emphasis"><em>"indicated"</em></span> as follows...</p>

  <pre class="screen"> define <span class="emphasis"><em> someobjecttype</em></span>{
       <span class="emphasis"><em> object-specific variables</em></span> ...
        name           <span class="emphasis"><em> template_name</em></span>
        use            <span class="emphasis"><em> name_of_template_to_use</em></span>
        register        [0/1]
        }</pre>

  <p>The first variable is <span class="emphasis"><em>name</em></span>. Its just a "template" name that can be referenced in other object definitions so
  they can inherit the objects properties/variables. Template names must be unique amongst objects of the same type, so you can't have two
  or more host definitions that have "hosttemplate" as their template name.</p>

  <p>The second variable is <span class="emphasis"><em>use</em></span>. This is where you specify the name of the template object that you want to inherit
  properties/variables from. The name you specify for this variable must be defined as another object's template named (using the
  <span class="emphasis"><em>name</em></span> variable).</p>

  <p>The third variable is <span class="emphasis"><em>register</em></span>. This variable is used to indicate whether or not the object definition should
  be "registered" with Icinga. By default, all object definitions are registered. If you are using a partial object definition as a
  template, you would want to prevent it from being registered (an example of this is provided later). Values are as follows: 0 = do NOT
  register object definition, 1 = register object definition (this is the default). This variable is NOT inherited; every (partial) object
  definition used as a template must explicitly set the <span class="emphasis"><em>register</em></span> directive to be <span class="emphasis"><em>0</em></span>. This prevents
  the need to override an inherited <span class="emphasis"><em>register</em></span> directive with a value of <span class="emphasis"><em>1</em></span> for every object that
  should be registered.</p>

  </div>

  <div class="section" title="7.26.3. Local Variables vs. Inherited Variables">
<div class="titlepage"><div><div><h3 class="title">
<a name="objectinheritance-localvsinveritedvars"></a>7.26.3. Local Variables vs. Inherited Variables</h3></div></div></div>
	  

  <p>One important thing to understand with inheritance is that "local" object variables always take precedence over variables defined in
  the template object. Take a look at the following example of two host definitions (not all required variables have been supplied):</p>

  <pre class="screen"> define host{
        host_name               bighost1
        check_command           check-host-alive
        notification_options    d,u,r
        max_check_attempts      5
                
        name                    hosttemplate1
        }

 define host{
        host_name               bighost2
        max_check_attempts      3
                
        use                     hosttemplate1
        }</pre>

  <p>You'll note that the definition for host <span class="emphasis"><em>bighost1</em></span> has been defined as having <span class="emphasis"><em>hosttemplate1</em></span>
  as its template name. The definition for host <span class="emphasis"><em>bighost2</em></span> is using the definition of <span class="emphasis"><em>bighost1</em></span> as
  its template object. Once Icinga processes this data, the resulting definition of host <span class="emphasis"><em>bighost2</em></span> would be
  equivalent to this definition:</p>

  <pre class="screen"> define host{
        host_name               bighost2
        check_command           check-host-alive
        notification_options    d,u,r
        max_check_attempts      3
        }</pre>

  <p>You can see that the <span class="emphasis"><em>check_command</em></span> and <span class="emphasis"><em>notification_options</em></span> variables were inherited from
  the template object (where host <span class="emphasis"><em>bighost1</em></span> was defined). However, the <span class="emphasis"><em>host_name</em></span> and
  <span class="emphasis"><em>max_check_attempts</em></span> variables were not inherited from the template object because they were defined locally. Remember,
  locally defined variables override variables that would normally be inherited from a template object. That should be a fairly easy concept
  to understand.</p>

  <div class="tip" title="Tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top">
    <p>If you would like local string variables to be appended to inherited string values, you can do so. Read more about how to
    accomplish this <a class="link" href="objectinheritance.html#objectinheritance-add_string" title="7.26.8. Additive Inheritance of String Values">below</a>.</p>
  </td></tr>
</table></div>

  </div>

  <div class="section" title="7.26.4. Inheritance Chaining">
<div class="titlepage"><div><div><h3 class="title">
<a name="objectinheritance-inheritancechaining"></a>7.26.4. Inheritance Chaining</h3></div></div></div>
	  

  <p>Objects can inherit properties/variables from multiple levels of template objects. Take the following example:</p>

  <pre class="screen"> define host{
        host_name               bighost1
        check_command           check-host-alive
        notification_options    d,u,r
        max_check_attempts      5
                
        name                    hosttemplate1
        }

 define host{
        host_name               bighost2
        max_check_attempts      3
                
        use                     hosttemplate1
                
        name                    hosttemplate2
        }

 define host{
        host_name               bighost3
                
        use                     hosttemplate2
        }</pre>

  <p>You'll notice that the definition of host <span class="emphasis"><em>bighost3</em></span> inherits variables from the definition of host
  <span class="emphasis"><em>bighost2</em></span>, which in turn inherits variables from the definition of host <span class="emphasis"><em>bighost1</em></span>. Once
  Icinga processes this configuration data, the resulting host definitions are equivalent to the following:</p>

  <pre class="screen"> define host{
        host_name               bighost1
        check_command           check-host-alive
        notification_options    d,u,r
        max_check_attempts      5
        }

 define host{
        host_name               bighost2
        check_command           check-host-alive
        notification_options    d,u,r
        max_check_attempts      3
        }

 define host{
        host_name               bighost3
        check_command           check-host-alive
        notification_options    d,u,r
        max_check_attempts      3
        }</pre>

  <p>There is no inherent limit on how "deep" inheritance can go, but you'll probably want to limit yourself to at most a few levels in
  order to maintain sanity.</p>

  </div>

  <div class="section" title="7.26.5. Using Incomplete Object Definitions as Templates">
<div class="titlepage"><div><div><h3 class="title">
<a name="objectinheritance-templates"></a>7.26.5. Using Incomplete Object Definitions as Templates</h3></div></div></div>
	  

  <p>It is possible to use imcomplete object definitions as templates for use by other object definitions. By "incomplete" definition, I
  mean that all required variables in the object have not been supplied in the object definition. It may sound odd to use incomplete
  definitions as templates, but it is in fact recommended that you use them. Why? Well, they can serve as a set of defaults for use in all
  other object definitions. Take the following example:</p>

  <pre class="screen"> define host{
        check_command           check-host-alive
        notification_options    d,u,r
        max_check_attempts      5
                
        name                    generichosttemplate
                
        register                0
        }

 define host{
        host_name               bighost1
        address                 192.168.1.3
                
        use                     generichosthosttemplate
        }

 define host{
        host_name               bighost2
        address                 192.168.1.4
                
        use                     generichosthosttemplate
        }</pre>

  <p>Notice that the first host definition is incomplete because it is missing the required <span class="emphasis"><em>host_name</em></span> variable. We
  don't need to supply a host name because we just want to use this definition as a generic host template. In order to prevent this
  definition from being registered with Icinga as a normal host, we set the <span class="emphasis"><em>register</em></span> variable to 0.</p>

  <p>The definitions of hosts <span class="emphasis"><em>bighost1</em></span> and <span class="emphasis"><em>bighost2</em></span> inherit their values from the generic host
  definition. The only variable we've chosed to override is the <span class="emphasis"><em>address</em></span> variable. This means that both hosts will have
  the exact same properties, except for their <span class="emphasis"><em>host_name</em></span> and <span class="emphasis"><em>address</em></span> variables. Once Icinga
  processes the config data in the example, the resulting host definitions would be equivalent to specifying the following:</p>

  <pre class="screen"> define host{
        host_name               bighost1
        address                 192.168.1.3
        check_command           check-host-alive
        notification_options    d,u,r
        max_check_attempts      5
        }

 define host{
        host_name               bighost2
        address                 192.168.1.4
        check_command           check-host-alive
        notification_options    d,u,r
        max_check_attempts      5
        }</pre>

  <p>At the very least, using a template definition for default variables will save you a lot of typing. It'll also save you a lot of
  headaches later if you want to change the default values of variables for a large number of hosts.</p>

  </div>

  <div class="section" title="7.26.6. Custom Object Variables">
<div class="titlepage"><div><div><h3 class="title">
<a name="objectinheritance-customobjectvariables"></a>7.26.6. Custom Object Variables</h3></div></div></div>
	  

  <p>Any <a class="link" href="customobjectvars.html" title="3.5. Custom Object Variables">custom object variables</a> that you define in your host, service, or contact definition
  templates will be inherited just like other standard variables. Take the following example:</p>

  <pre class="screen"> define host{
        _customvar1             somevalue  ; &lt;-- Custom host variable
        _snmp_community         public  ; &lt;-- Custom host variable
                
        name                    generichosttemplate
                
        register                0
        }

 define host{
        host_name               bighost1
        address                 192.168.1.3
                
        use                     generichosthosttemplate
        }</pre>

  <p>The host <span class="emphasis"><em>bighost1</em></span> will inherit the custom host variables <span class="emphasis"><em>_customvar1</em></span> and
  <span class="emphasis"><em>_snmp_community</em></span>, as well as their respective values, from the <span class="emphasis"><em>generichosttemplate</em></span> definition.
  The effective result is a definition for <span class="emphasis"><em>bighost1</em></span> that looks like this:</p>

  <pre class="screen"> define host{
        host_name               bighost1
        address                 192.168.1.3
        _customvar1             somevalue
        _snmp_community         public
        }</pre>

  </div>

  <div class="section" title="7.26.7. Cancelling Inheritance of String Values">
<div class="titlepage"><div><div><h3 class="title">
<a name="objectinheritance-cancel_string"></a>7.26.7. Cancelling Inheritance of String Values</h3></div></div></div>
	  

  <p>In some cases you may not want your host, service, or contact definitions to inherit values of string variables from the templates
  they reference. If this is the case, you can specify "<span class="bold"><strong>null</strong></span>" (without quotes) as the value of the variable
  that you do not want to inherit. Take the following example:</p>

  <pre class="screen"> define host{
        event_handler           my-event-handler-command
                
        name                    generichosttemplate
                
        register                0
        }

 define host{
        host_name               bighost1
        address                 192.168.1.3
        event_handler           null
                
        use                     generichosthosttemplate
        }</pre>

  <p>In this case, the host <span class="emphasis"><em>bighost1</em></span> will not inherit the value of the <span class="emphasis"><em>event_handler</em></span> variable
  that is defined in the <span class="emphasis"><em>generichosttemplate</em></span>. The resulting effective definition of <span class="emphasis"><em>bighost1</em></span> is
  the following:</p>

  <pre class="screen"> define host{
        host_name               bighost1
        address                 192.168.1.3
        }</pre>

  </div>

  <div class="section" title="7.26.8. Additive Inheritance of String Values">
<div class="titlepage"><div><div><h3 class="title">
<a name="objectinheritance-add_string"></a>7.26.8. Additive Inheritance of String Values</h3></div></div></div>
	  

  <p>Icinga gives preference to local variables instead of values inherited from templates. In most cases local variable values
  override those that are defined in templates. In some cases it makes sense to allow Icinga to use the values of inherited
  <span class="emphasis"><em>and</em></span> local variables together.</p>

  <p>This "additive inheritance" can be accomplished by prepending the local variable value with a plus sign (<span class="bold"><strong>+</strong></span>). This features is only available for standard (non-custom) variables that contain string values. Take the
  following example:</p>

  <pre class="screen"> define host{
        hostgroups              all-servers
                
        name                    generichosttemplate
                
        register                0
        }

 define host{
        host_name               linuxserver1
        hostgroups              +linux-servers,web-servers
                
        use                     generichosthosttemplate
        }</pre>

  <p>In this case, the host <span class="emphasis"><em>linuxserver1</em></span> will append the value of its local <span class="emphasis"><em>hostgroups</em></span> variable
  to that from <span class="emphasis"><em>generichosttemplate</em></span>. The resulting effective definition of <span class="emphasis"><em>linuxserver1</em></span> is the
  following:</p>

  <pre class="screen"> define host{
        host_name               linuxserver1
        hostgroups              all-servers,linux-servers,web-servers
        }</pre>

  </div>

  <div class="section" title="7.26.9. Implied Inheritance">
<div class="titlepage"><div><div><h3 class="title">
<a name="objectinheritance-implied_inheritance"></a>7.26.9. Implied Inheritance</h3></div></div></div>
	  

  <p>Normally you have to either explicitly specify the value of a required variable in an object definition or inherit it from a
  template. There are a few exceptions to this rule, where Icinga will assume that you want to use a value that instead comes from a
  related object. For example, the values of some service variables will be copied from the host the service is associated with if you don't
  otherwise specify them.</p>

  <p>The following table lists the object variables that will be implicitly inherited from related objects if you don't explicitly
  specify their value in your object definition or inherit them from a template.</p>

  <div class="informaltable">
    <table border="1">
<colgroup>
<col>
<col>
<col>
</colgroup>
<tbody>
<tr>
<td><p> <span class="bold"><strong>Object Type</strong></span> </p></td>
<td><p> <span class="bold"><strong>Object Variable</strong></span> </p></td>
<td><p> <span class="bold"><strong>Implied Source</strong></span> </p></td>
</tr>
<tr>
<td rowspan="4" align="left" valign="middle"><p> <span class="bold"><strong>Services</strong></span> </p></td>
<td><p> <span class="emphasis"><em>contact_groups</em></span> </p></td>
<td><p><span class="emphasis"><em>contact_groups</em></span> in the associated host definition</p></td>
</tr>
<tr>
<td><p> <span class="emphasis"><em>contacts</em></span> </p></td>
<td><p><span class="emphasis"><em>contacts</em></span> in the associated host definition</p></td>
</tr>
<tr>
<td><p> <span class="emphasis"><em>notification_interval</em></span> </p></td>
<td><p><span class="emphasis"><em>notification_interval</em></span> in the associated host definition</p></td>
</tr>
<tr>
<td><p> <span class="emphasis"><em>notification_period</em></span> </p></td>
<td><p><span class="emphasis"><em>notification_period</em></span> in the associated host definition</p></td>
</tr>
<tr>
<td rowspan="4" align="left" valign="middle"><p> <span class="bold"><strong>Host Escalations</strong></span> </p></td>
<td><p> <span class="emphasis"><em>contact_groups</em></span> </p></td>
<td><p><span class="emphasis"><em>contact_groups</em></span> in the associated host definition</p></td>
</tr>
<tr>
<td><p> <span class="emphasis"><em>contacts</em></span> </p></td>
<td><p><span class="emphasis"><em>contacts</em></span> in the associated host definition</p></td>
</tr>
<tr>
<td><p> <span class="emphasis"><em>notification_interval</em></span> </p></td>
<td><p><span class="emphasis"><em>notification_interval</em></span> in the associated host definition</p></td>
</tr>
<tr>
<td><p> <span class="emphasis"><em>escalation_period</em></span> </p></td>
<td><p><span class="emphasis"><em>notification_period</em></span> in the associated host definition</p></td>
</tr>
<tr>
<td rowspan="4" align="left" valign="middle"><p> <span class="bold"><strong>Service Escalations</strong></span> </p></td>
<td><p> <span class="emphasis"><em>contact_groups</em></span> </p></td>
<td><p><span class="emphasis"><em>contact_groups</em></span> in the associated service definition</p></td>
</tr>
<tr>
<td><p> <span class="emphasis"><em>contacts</em></span> </p></td>
<td><p><span class="emphasis"><em>contacts</em></span> in the associated service definition</p></td>
</tr>
<tr>
<td><p> <span class="emphasis"><em>notification_interval</em></span> </p></td>
<td><p><span class="emphasis"><em>notification_interval</em></span> in the associated service definition</p></td>
</tr>
<tr>
<td><p> <span class="emphasis"><em>escalation_period</em></span> </p></td>
<td><p><span class="emphasis"><em>notification_period</em></span> in the associated service definition</p></td>
</tr>
</tbody>
</table>
  </div>

  <div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
    <p>These values are inherited in case of an object changing its state so "in the associated ... definition" only means the one
    host/service combination failing/recovering although it is possibly to execute a service for one or more host groups.</p>
  </td></tr>
</table></div>

  </div>

  <div class="section" title="7.26.10. Implied/Additive Inheritance in Escalations">
<div class="titlepage"><div><div><h3 class="title">
<a name="objectinheritance-implied_escalations"></a>7.26.10. Implied/Additive Inheritance in Escalations</h3></div></div></div>
	  

  <p>Service and host escalation definitions can make use of a special rule that combines the features of implied and additive
  inheritance. If escalations 1) do not inherit the values of their <span class="emphasis"><em>contact_groups</em></span> or <span class="emphasis"><em>contacts</em></span>
  directives from another escalation template and 2) their <span class="emphasis"><em>contact_groups</em></span> or <span class="emphasis"><em>contacts</em></span> directives
  begin with a plus sign (+), then the values of their corresponding host or service definition's <span class="emphasis"><em>contact_groups</em></span> or
  <span class="emphasis"><em>contacts</em></span> directives will be used in the additive inheritance logic.</p>

  <p>Confused? Here's an example:</p>

  <pre class="screen"> define host{
        name            linux-server
        contact_groups  linux-admins
        ...
        }

 define hostescalation{
        host_name       linux-server
        contact_groups  +management
        ...
        }</pre>

  <p>This is a much simpler equivalent to:</p>

  <pre class="screen"> define hostescalation{
        host_name       linux-server
        contact_groups  linux-admins,management
        ...
        }</pre>

  </div>

  <div class="section" title="7.26.11. Important values">
<div class="titlepage"><div><div><h3 class="title">
<a name="objectinheritance-important_values"></a>7.26.11. Important values</h3></div></div></div>
	  

  <p>Service templates can make use of a special rule which gives precedence to their check_command value. If the check_command is
  prefixed with an exclamation mark (!), then the template's check_command is marked as important and will be used over the check_command
  defined for the service (this is styled after CSS syntax, which uses ! as an important attribute).</p>

  <p>Why is this useful? It is mainly useful when setting a different check_command for distributed systems. You may want to set a
  freshness threshold and a check_command that forces the service into a failed state, but this doesn't work with the normal templating
  system. Using this important flag allows the custom check_command to be written, but a general distributed template can be used to
  overrule the check_command when used on a central Icinga-erver.</p>

  <p>For instance:</p>

  <pre class="screen"># On master
define service {
        name                   service-distributed
        register               0
        active_checks_enabled  0
        check_freshness        1
        check_command          !set_to_stale
        }
# On slave
define service {
        name                   service-distributed
        register               0
        active_checks_enabled  1
        }
# Service definition, used by master and slave
define service {
        host_name              host1
        service_description    serviceA
        check_command          check_http...
        use                    service-distributed
        ...
        }</pre>

  <div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
    <p>Please note that only one level of inheritance is possible using important values. That means that you cannot inherit the
    check_command from one template to another and from the latter to a service. </p>
<pre class="programlisting"> Template1 =&gt; Service1                &lt;== will work
 Template1 =&gt; Template2 =&gt; Service1   &lt;== will NOT work</pre>
  </td></tr>
</table></div>

  </div>

  <div class="section" title="7.26.12. Multiple Inheritance Sources">
<div class="titlepage"><div><div><h3 class="title">
<a name="objectinheritance-multiple_templates"></a>7.26.12. Multiple Inheritance Sources</h3></div></div></div>
	  

  <p>Thus far, all examples of inheritance have shown object definitions inheriting variables/values from just a single source. You are
  also able to inherit variables/values from multiple sources for more complex configurations, as shown below.</p>

  <div class="informaltable">
    <table border="0">
<colgroup>
<col>
<col>
</colgroup>
<tbody><tr>
<td>
<p> </p>
<pre class="screen"># Generic host template
define host{
        name                    generic-host
        active_checks_enabled   1
        check_interval          10
        ...
        register                0
        }

# Development web server template
define host{
        name                    development-server
        check_interval          15
        notification_options    d,u,r
        ...
        register                0
        }

# Development web server
define host{
        use                     generic-host,development-server
        host_name               devweb1
        ...
        }</pre>
<p> </p>
</td>
<td align="center" valign="top"><p> <span class="inlinemediaobject"><img src="../images/multiple-templates1.png"></span> </p></td>
</tr></tbody>
</table>
  </div>

  <p>In the example above, <span class="emphasis"><em>devweb1</em></span> is inheriting variables/values from two sources:
  <span class="emphasis"><em>generic-host</em></span> and <span class="emphasis"><em>development-server</em></span>. You'll notice that a <span class="emphasis"><em>check_interval</em></span>
  variable is defined in both sources. Since <span class="emphasis"><em>generic-host</em></span> was the first template specified in
  <span class="emphasis"><em>devweb1</em></span>'s <span class="emphasis"><em>use</em></span> directive, its value for the <span class="emphasis"><em>check_interval</em></span> variable is
  inherited by the <span class="emphasis"><em>devweb1</em></span> host. After inheritance, the effective definition of <span class="emphasis"><em>devweb1</em></span> would be
  as follows:</p>

  <pre class="screen"># Development web server
define host{
        host_name               devweb1
        active_checks_enabled   1
        check_interval          10
        notification_options    d,u,r
        ...
        }</pre>

  </div>

  <div class="section" title="7.26.13. Precedence With Multiple Inheritance Sources">
<div class="titlepage"><div><div><h3 class="title">
<a name="objectinheritance-multipleinheritancesources"></a>7.26.13. Precedence With Multiple Inheritance Sources</h3></div></div></div>
	  

  <p>When you use multiple inheritance sources, it is important to know how Icinga handles variables that are defined in multiple
  sources. In these cases Icinga will use the variable/value from the first source that is specified in the <span class="emphasis"><em>use</em></span>
  directive. Since inheritance sources can themselves inherit variables/values from one or more other sources, it can get tricky to figure
  out what variable/value pairs take precedence.</p>

  <div class="informaltable">
    <table border="0">
<colgroup>
<col>
<col>
</colgroup>
<tbody><tr>
<td align="left" valign="top">
<p> Consider the following host definition that references three templates:</p> <pre class="screen"> # Development web server
 define host{ 
       use        1,  4,  8 
       host_name  devweb1 ...
 } </pre> <p>If some of those referenced templates themselves inherit variables/values from one or more other templates, the
          precendence rules are shown to the right.</p> <p>Testing, trial, and error will help you better understand exactly how
          things work in complex inheritance situations like this. :-)</p>
</td>
<td align="center" valign="top"><p> <span class="inlinemediaobject"><img src="../images/multiple-templates2.png"></span> </p></td>
</tr></tbody>
</table>
  </div>

  <a class="indexterm" name="idm140381623517952"></a>

  <a class="indexterm" name="idm140381623516944"></a>

  <a class="indexterm" name="idm140381623515552"></a>

  <a class="indexterm" name="idm140381623514160"></a>

  <a class="indexterm" name="idm140381623512768"></a>

  <a class="indexterm" name="idm140381623511072"></a>

  <a class="indexterm" name="idm140381623509376"></a>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="modified_attr.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="ch07.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="objecttricks.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">7.25. Modified attributes </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> 7.27. Time-Saving Tricks For Object Definitions</td>
</tr>
</table>
</div>
<P class="copyright">© 1999-2009 Ethan Galstad, 2009-2017 Icinga Development Team, https://www.icinga.com</P>
</body>
</html>