Fix for host dependency checks

Holger Weiss holger at CIS.FU-Berlin.DE
Mon Jan 30 16:54:58 CET 2006


There is a timing problem in the host[*] dependency check logic: If host
B is configured to be dependent on host A being up and host A goes down,
the dependency will only fail if host A "incidentally" was checked
_prior_ to host B after going down.  Hence, the host dependency logic
will sometimes work and sometimes not.  I'd therefore suggest to
explicitly (re-)check host A during the dependency checking for host B,
as the attached patch does.

Holger

[*] A similar problem _can_ arise for service dependencies, but unlike
    for host dependencies, Nagios can be configured in a way that this
    problem won't show up:

    http://sf.net/mailarchive/message.php?msg_id=14420901

-- 
PGP fingerprint:  F1F0 9071 8084 A426 DD59  9839 59D3 F3A1 B8B5 D3DE
-------------- next part --------------
Index: checks.c
===================================================================
RCS file: /cvsroot/nagios/nagios/base/checks.c,v
retrieving revision 1.81
diff -u -r1.81 checks.c
--- checks.c	23 Dec 2005 19:31:35 -0000	1.81
+++ checks.c	30 Jan 2006 12:51:40 -0000
@@ -1579,6 +1579,7 @@
 int check_host_dependencies(host *hst,int dependency_type){
 	hostdependency *temp_dependency;
 	host *temp_host;
+	int route_result;
 
 #ifdef DEBUG0
 	printf("check_host_dependencies() start\n");
@@ -1596,14 +1597,17 @@
 		if(temp_host==NULL)
 			continue;
 
+		/* check the host we depend on */
+		route_result=verify_route_to_host(temp_host,CHECK_OPTION_FORCE_EXECUTION);
+
 		/* is the host we depend on in state that fails the dependency tests? */
-		if(temp_host->current_state==HOST_UP && temp_dependency->fail_on_up==TRUE)
+		if(route_result==HOST_UP && temp_dependency->fail_on_up==TRUE)
 			return DEPENDENCIES_FAILED;
-		if(temp_host->current_state==HOST_DOWN && temp_dependency->fail_on_down==TRUE)
+		if(route_result==HOST_DOWN && temp_dependency->fail_on_down==TRUE)
 			return DEPENDENCIES_FAILED;
-		if(temp_host->current_state==HOST_UNREACHABLE && temp_dependency->fail_on_unreachable==TRUE)
+		if(route_result==HOST_UNREACHABLE && temp_dependency->fail_on_unreachable==TRUE)
 			return DEPENDENCIES_FAILED;
-		if((temp_host->current_state==HOST_UP && temp_host->has_been_checked==FALSE) && temp_dependency->fail_on_pending==TRUE)
+		if((route_result==HOST_UP && temp_host->has_been_checked==FALSE) && temp_dependency->fail_on_pending==TRUE)
 			return DEPENDENCIES_FAILED;
 
 		/* immediate dependencies ok at this point - check parent dependencies if necessary */


More information about the Developers mailing list