1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
9
<title>Host and Service Dependencies</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">Host and Service Dependencies</h1>
51
<img src="images/upto.gif" border="0" align="middle" alt="Up To" title="Up To">Up To: <a href="toc.html">Contents</a><br>
53
<img src="images/seealso.gif" border="0" align="middle" alt="See Also" title="See Also"> See Also: <a href="dependencychecks.html">Predictive Dependency Checks</a>, <a href="servicechecks.html">Service Checks</a>, <a href="hostchecks.html">Host Checks</a>
61
<strong><u>Introduction</u></strong>
69
Service and host dependencies are an advanced feature of Nagios that allow you to control the behavior of hosts and services based on the status of one or more other hosts or services. I'll explain how dependencies work, along with the differences between host and service dependencies.
77
<strong><u>Service Dependencies Overview</u></strong>
85
There are a few things you should know about service dependencies:
91
<li>A service can be dependent on one or more other services
93
<li>A service can be dependent on services which are not associated with the same host
95
<li>Service dependencies are not inherited (unless specifically configured to)
97
<li>Service dependencies can be used to cause service check execution and service notifications to be suppressed under different circumstances (OK, WARNING, UNKNOWN, and/or CRITICAL states)
99
<li>Service dependencies might only be valid during specific <a href="timeperiods.html">timeperiods</a></li>
109
<strong><u>Defining Service Dependencies</u></strong>
117
First, the basics. You create service dependencies by adding <a href="objectdefinitions.html#servicedependency">service dependency definitions</a> in your <a href="configobject.html">object config file(s)</a>. In each definition you specify the <i>dependent</i> service, the service you are <i>depending on</i>, and the criteria (if any) that cause the execution and notification dependencies to fail (these are described later).
125
You can create several dependencies for a given service, but you must add a separate service dependency definition for each dependency you create.
135
<strong><u>Example Service Dependencies</u></strong>
143
The image below shows an example logical layout of service notification and execution dependencies. Different services are dependent on other services for notifications and check execution.
149
<img src="images/service-dependencies.png" alt="Service Dependencies">
155
In this example, the dependency definitions for <i>Service F</i> on <i>Host C</i> would be defined as follows:
163
define servicedependency{
167
service_description Service D
169
dependent_host_name Host C
171
dependent_service_description Service F
173
execution_failure_criteria o
175
notification_failure_criteria w,u
181
define servicedependency{
185
service_description Service E
187
dependent_host_name Host C
189
dependent_service_description Service F
191
execution_failure_criteria n
193
notification_failure_criteria w,u,c
199
define servicedependency{
203
service_description Service C
205
dependent_host_name Host C
207
dependent_service_description Service F
209
execution_failure_criteria w
211
notification_failure_criteria c
223
The other dependency definitions shown in the image above would be defined as follows:
231
define servicedependency{
235
service_description Service A
237
dependent_host_name Host B
239
dependent_service_description Service D
241
execution_failure_criteria u
243
notification_failure_criteria n
249
define servicedependency{
253
service_description Service B
255
dependent_host_name Host B
257
dependent_service_description Service E
259
execution_failure_criteria w,u
261
notification_failure_criteria c
267
define servicedependency{
271
service_description Service C
273
dependent_host_name Host B
275
dependent_service_description Service E
277
execution_failure_criteria n
279
notification_failure_criteria w,u,c
291
<strong><u>How Service Dependencies Are Tested</u></strong>
299
Before Nagios executes a service check or sends notifications out for a service, it will check to see if the service has any dependencies. If it doesn't have any dependencies, the check is executed or the notification is sent out as it normally would be. If the service <i>does</i> have one or more dependencies, Nagios will check each dependency entry as follows:
307
<li>Nagios gets the current status<sup><a href="#hard_dependencies">*</a></sup> of the service that is being <i>depended upon</i>.
309
<li>Nagios compares the current status of the service that is being <i>depended upon</i> against either the execution or notification failure options in the dependency definition (whichever one is relevant at the time).
311
<li>If the current status of the service that is being <i>depended upon</i> matches one of the failure options, the dependency is said to have failed and Nagios will break out of the dependency check loop.
313
<li>If the current state of the service that is being <i>depended upon</i> does not match any of the failure options for the dependency entry, the dependency is said to have passed and Nagios will go on and check the next dependency entry. </ol>
319
This cycle continues until either all dependencies for the service have been checked or until one dependency check fails.
327
<a name="hard_dependencies"></a>
329
<img src="images/note.gif" border="0" align="bottom" alt="Note" title="Note"> Note: <sup>*</sup>One important thing to note is that by default, Nagios will use the most current <a href="statetypes.html">hard state</a> of the service(s) that is/are being depended upon when it does the dependeny checks. If you want Nagios to use the most current state of the services (regardless of whether its a soft or hard state), enable the <a href="configmain.html#soft_state_dependencies">soft_state_dependencies</a> option.
337
<strong><u>Execution Dependencies</u></strong>
345
Execution dependencies are used to restrict when <a href="activechecks.html">active checks</a> of a service can be performed. <a href="passivechecks.html">Passive checks</a> are not restricted by execution dependencies.
353
If <i>all</i> of the execution dependency tests for the service <i>passed</i>, Nagios will execute the check of the service as it normally would. If even just one of the execution dependencies for a service fails, Nagios will temporarily prevent the execution of checks for that (dependent) service. At some point in the future the execution dependency tests for the service may all pass. If this happens, Nagios will start checking the service again as it normally would. More information on the check scheduling logic can be found <a href="checkscheduling.html">here</a>.
361
In the example above, <b>Service E</b> would have failed execution dependencies if <b>Service B</b> is in a WARNING or UNKNOWN state. If this was the case, the service check would not be performed and the check would be scheduled for (potential) execution at a later time.
369
<strong><u>Notification Dependencies</u></strong>
377
If <i>all</i> of the notification dependency tests for the service <i>passed</i>, Nagios will send notifications out for the service as it normally would. If even just one of the notification dependencies for a service fails, Nagios will temporarily repress notifications for that (dependent) service. At some point in the future the notification dependency tests for the service may all pass. If this happens, Nagios will start sending out notifications again as it normally would for the service. More information on the notification logic can be found <a href="notifications.html">here</a>.
385
In the example above, <b>Service F</b> would have failed notification dependencies if <b>Service C</b> is in a CRITICAL state, <i>and/or</i> <b>Service D</b> is in a WARNING or UNKNOWN state, <i>and/or</i> if <b>Service E</b> is in a WARNING, UNKNOWN, or CRITICAL state. If this were the case, notifications for the service would not be sent out.
393
<strong><u>Dependency Inheritance</u></strong>
401
As mentioned before, service dependencies are <i>not</i> inherited by default. In the example above you can see that Service F is dependent on Service E. However, it does not automatically inherit Service E's dependencies on Service B and Service C. In order to make Service F dependent on Service C we had to add another service dependency definition. There is no dependency definition for Service B, so Service F is <i>not</i> dependent on Service B.
409
If you <i>do</i> wish to make service dependencies inheritable, you must use the <i>inherits_parent</i> directive in the <a href="objectdefinitions.html#servicedependency">service dependency</a> definition. When this directive is enabled, it indicates that the dependency inherits dependencies of the service <i>that is being depended upon</i> (also referred to as the master service). In other words, if the master service is dependent upon other services and any one of those dependencies fail, this dependency will also fail.
417
In the example above, imagine that you want to add a new dependency for service F to make it dependent on service A. You could create a new dependency definition that specified service F as the <i>dependent</i> service and service A as being the <i>master</i> service (i.e. the service <i>that is being dependend on</i>). You could alternatively modify the dependency definition for services D and F to look like this:
425
define servicedependency{
429
service_description Service D
431
dependent_host_name Host C
433
dependent_service_description Service F
435
execution_failure_criteria o
437
notification_failure_criteria n
451
Since the <i>inherits_parent</i> directive is enabled, the dependency between services A and D will be tested when the dependency between services F and D are being tested.
459
Dependencies can have multiple levels of inheritence. If the dependency definition between A and D had its <i>inherits_parent</i> directive enable and service A was dependent on some other service (let's call it service G), the service F would be dependent on services D, A, and G (each with potentially different criteria).
467
<strong><u>Host Dependencies</u></strong>
475
As you'd probably expect, host dependencies work in a similiar fashion to service dependencies. The difference is that they're for hosts, not services.
483
<img src="images/tip.gif" border="0" align="bottom" alt="Tip" title="Tip"> Tip: Do not confuse host dependencies with parent/child host relationships. You should be using parent/child host relationships (defined with the <i>parents</i> directive in <a href="objectdefinitions.html#host">host</a> definitions) for most cases, rather than host dependencies. A description of how parent/child host relationships work can be found in the documentation on <a href="networkreachability.html">network reachability</a>.
491
Here are the basics about host dependencies:
497
<li>A host can be dependent on one or more other host
499
<li>Host dependencies are not inherited (unless specifically configured to)
501
<li>Host dependencies can be used to cause host check execution and host notifications to be suppressed under different circumstances (UP, DOWN, and/or UNREACHABLE states)
503
<li>Host dependencies might only be valid during specific <a href="timeperiods.html">timeperiods</a></li>
511
<strong><u>Example Host Dependencies</u></strong>
519
The image below shows an example of the logical layout of host notification dependencies. Different hosts are dependent on other hosts for notifications.
525
<img src="images/host-dependencies.png" alt="Host Dependencies">
531
In the example above, the dependency definitions for <i>Host C</i> would be defined as follows:
539
define hostdependency{
543
dependent_host_name Host C
545
notification_failure_criteria d
551
define hostdependency{
555
dependent_host_name Host C
557
notification_failure_criteria d,u
567
As with service dependencies, host dependencies are not inherited. In the example image you can see that Host C does not inherit the host dependencies of Host B. In order for Host C to be dependent on Host A, a new host dependency definition must be defined.
575
Host notification dependencies work in a similiar manner to service notification dependencies. If <i>all</i> of the notification dependency tests for the host <i>pass</i>, Nagios will send notifications out for the host as it normally would. If even just one of the notification dependencies for a host fails, Nagios will temporarily repress notifications for that (dependent) host. At some point in the future the notification dependency tests for the host may all pass. If this happens, Nagios will start sending out notifications again as it normally would for the host. More information on the notification logic can be found <a href="notifications.html">here</a>.