[PATCH] Same Host Dependencies With Servicegroups

Mathieu Gagné mgagne at iweb.com
Mon Nov 15 19:08:37 CET 2010


Allow to create service dependencies for all services that belong
in one or more servicegroups on a service on the same host running
the dependent service.
---
 Changelog                       |    1 +
 html/docs/objecttricks.html     |   26 +++++++
 t/etc/minimal.cfg               |   56 +++++++++++++++
 t/var/objects.precache.expected |  144 +++++++++++++++++++++++++++++++++++++++
 xdata/xodtemplate.c             |   16 ++++-
 5 files changed, 242 insertions(+), 1 deletions(-)

diff --git a/Changelog b/Changelog
index 15c162c..91814de 100644
--- a/Changelog
+++ b/Changelog
@@ -5,6 +5,7 @@ Nagios 3.x Change Log
 3.2.4 - ?????
 ------------------
 ENHANCEMENTS
+* Added support for same host service dependencies with servicegroups (Mathieu Gagné)
 
 FIXES
 * Fixes status.cgi when called with no parameters, where host should be set to all if none specified (Michael Friedrich)
diff --git a/html/docs/objecttricks.html b/html/docs/objecttricks.html
index f9a49c0..5ef5884 100644
--- a/html/docs/objecttricks.html
+++ b/html/docs/objecttricks.html
@@ -621,6 +621,32 @@ If you feel like being particularly adventurous, you can specify a wildcard in b
 </pre>
 
 
+<a name="same_host_dependency_with_servicegroups"></a>
+
+<p>
+
+<b>Same Host Dependencies With Servicegroups:</b><br> If you want to create service dependencies for all services that belong in one or more servicegroups on a service on the same host running the dependent service, leave the <i>host_name</i> and <i>hostgroup_name</i> directives empty.  The example below assumes that hosts running services that belong in <i>SERVICEGROUP1</i> and <i>SERVICEGROUP2</i> have the following service associated with them: <i>SERVICE1</i>.  In this example, all services that belong in <i>GROUPSERVICE1</i> and <i>SERVICEGROUP2</i> will be dependent on <i>SERVICE1</i> on the same host running the dependent service.
+
+</p>
+
+
+
+<pre>
+
+	define <i>servicedependency</i>{
+
+		<font color="red">service_description		<i>SERVICE1</i></font>
+
+		<font color="red">dependent_servicegroup_name	<i>SERVICEGROUP1,SERVICEGROUP2</i></font>
+
+		<i>other dependency directives</i> ...
+
+		}
+
+</pre>
+
+
+
 
 <br><br>
 
diff --git a/t/etc/minimal.cfg b/t/etc/minimal.cfg
index 6179ecd..abdb600 100644
--- a/t/etc/minimal.cfg
+++ b/t/etc/minimal.cfg
@@ -20,6 +20,23 @@ define host {
 	notification_period none
 }
 
+define host {
+	host_name host3
+	alias   host3 test
+	address 192.168.2.3
+	max_check_attempts 2
+	check_period    none
+	contacts        nagiosadmin
+	notification_interval 60
+	notification_period none
+	hostgroups	+hosts-with-master-service
+}
+
+define hostgroup {
+	hostgroup_name	hosts-with-master-service
+	alias	Hosts running a master service
+}
+
 define service {
 	host_name	host1
 	service_description Dummy service
@@ -53,6 +70,38 @@ define service {
 	register	0
 }
 
+define service {
+        hostgroup_name  hosts-with-master-service
+        service_description     master-service
+        check_command   check_me!master service
+        max_check_attempts      5
+        check_interval  15
+        retry_interval  1
+        check_period    none
+        notification_interval   65
+        notification_period     none
+        contacts        nagiosadmin
+}
+
+define service {
+	host_name       host3
+	service_description	dependent-service
+	check_command	check_me!dependent service
+	max_check_attempts	5
+	check_interval	15
+	retry_interval	1
+	check_period	none
+	notification_interval	65
+	notification_period	none
+	contacts	nagiosadmin
+        servicegroups   +services-depending-on-master-service
+}
+
+define servicegroup {
+	servicegroup_name	services-depending-on-master-service
+	alias	Servicegroup for services depending on a "master" service on the same host
+}
+
 define command {
 	command_name	set_to_stale
 	command_line	/usr/local/nagios/libexec/set_to_stale
@@ -125,3 +174,10 @@ define serviceescalation {
 	host_name *
 	service_description *,!Dummy service
 }
+
+define servicedependency {
+	service_description	master-service
+	dependent_servicegroup_name	services-depending-on-master-service
+	execution_failure_criteria	n
+	notification_failure_criteria	c,u
+}
diff --git a/t/var/objects.precache.expected b/t/var/objects.precache.expected
index 7ea1c8d..34da93d 100644
--- a/t/var/objects.precache.expected
+++ b/t/var/objects.precache.expected
@@ -47,6 +47,18 @@ define contactgroup {
 	alias	No members defined - this should pass validation
 	}
 
+define hostgroup {
+	hostgroup_name	hosts-with-master-service
+	alias	Hosts running a master service
+	members	host3
+	}
+
+define servicegroup {
+	servicegroup_name	services-depending-on-master-service
+	alias	Servicegroup for services depending on a "master" service on the same host
+	members	host3,dependent-service
+	}
+
 define contact {
 	contact_name	nagiosadmin
 	service_notification_period	none
@@ -141,6 +153,38 @@ define host {
 	retain_nonstatus_information	1
 	}
 
+define host {
+	host_name	host3
+	alias	host3 test
+	address	192.168.2.3
+	check_period	none
+	contacts	nagiosadmin
+	notification_period	none
+	initial_state	o
+	check_interval	5.000000
+	retry_interval	1.000000
+	max_check_attempts	2
+	active_checks_enabled	1
+	passive_checks_enabled	1
+	obsess_over_host	1
+	event_handler_enabled	1
+	low_flap_threshold	0.000000
+	high_flap_threshold	0.000000
+	flap_detection_enabled	1
+	flap_detection_options	o,d,u
+	freshness_threshold	0
+	check_freshness	0
+	notification_options	d,u,r,f,s
+	notifications_enabled	1
+	notification_interval	60.000000
+	first_notification_delay	0.000000
+	stalking_options	n
+	process_perf_data	1
+	failure_prediction_enabled	1
+	retain_status_information	1
+	retain_nonstatus_information	1
+	}
+
 define service {
 	host_name	host1
 	service_description	Dummy service
@@ -243,6 +287,84 @@ define service {
 	retain_nonstatus_information	1
 	}
 
+define service {
+	host_name	host3
+	service_description	dependent-service
+	check_period	none
+	check_command	check_me!dependent service
+	contacts	nagiosadmin
+	notification_period	none
+	initial_state	o
+	check_interval	15.000000
+	retry_interval	1.000000
+	max_check_attempts	5
+	is_volatile	0
+	parallelize_check	1
+	active_checks_enabled	1
+	passive_checks_enabled	1
+	obsess_over_service	1
+	event_handler_enabled	1
+	low_flap_threshold	0.000000
+	high_flap_threshold	0.000000
+	flap_detection_enabled	1
+	flap_detection_options	o,w,u,c
+	freshness_threshold	0
+	check_freshness	0
+	notification_options	u,w,c,r,f,s
+	notifications_enabled	1
+	notification_interval	65.000000
+	first_notification_delay	0.000000
+	stalking_options	n
+	process_perf_data	1
+	failure_prediction_enabled	1
+	retain_status_information	1
+	retain_nonstatus_information	1
+	}
+
+define service {
+	host_name	host3
+	service_description	master-service
+	check_period	none
+	check_command	check_me!master service
+	contacts	nagiosadmin
+	notification_period	none
+	initial_state	o
+	check_interval	15.000000
+	retry_interval	1.000000
+	max_check_attempts	5
+	is_volatile	0
+	parallelize_check	1
+	active_checks_enabled	1
+	passive_checks_enabled	1
+	obsess_over_service	1
+	event_handler_enabled	1
+	low_flap_threshold	0.000000
+	high_flap_threshold	0.000000
+	flap_detection_enabled	1
+	flap_detection_options	o,w,u,c
+	freshness_threshold	0
+	check_freshness	0
+	notification_options	u,w,c,r,f,s
+	notifications_enabled	1
+	notification_interval	65.000000
+	first_notification_delay	0.000000
+	stalking_options	n
+	process_perf_data	1
+	failure_prediction_enabled	1
+	retain_status_information	1
+	retain_nonstatus_information	1
+	}
+
+define servicedependency {
+	host_name	host3
+	service_description	master-service
+	dependent_host_name	host3
+	dependent_service_description	dependent-service
+	inherits_parent	0
+	notification_failure_options	u,c
+	execution_failure_options	n
+	}
+
 define serviceescalation {
 	host_name	host1
 	service_description	Uses important check command
@@ -265,3 +387,25 @@ define serviceescalation {
 	contacts	nagiosadmin
 	}
 
+define serviceescalation {
+	host_name	host3
+	service_description	dependent-service
+	first_notification	-2
+	last_notification	-2
+	notification_interval	65.000000
+	escalation_period	none
+	escalation_options	w,u,c,r
+	contacts	nagiosadmin
+	}
+
+define serviceescalation {
+	host_name	host3
+	service_description	master-service
+	first_notification	-2
+	last_notification	-2
+	notification_interval	65.000000
+	escalation_period	none
+	escalation_options	w,u,c,r
+	contacts	nagiosadmin
+	}
+
diff --git a/xdata/xodtemplate.c b/xdata/xodtemplate.c
index cc8a114..94dfb92 100644
--- a/xdata/xodtemplate.c
+++ b/xdata/xodtemplate.c
@@ -4259,6 +4259,7 @@ int xodtemplate_duplicate_objects(void){
 
 	char *service_descriptions=NULL;
 	int first_item=FALSE;
+	int same_host_servicedependency=FALSE;
 
 
 	/*************************************/
@@ -4718,6 +4719,11 @@ int xodtemplate_duplicate_objects(void){
 				my_free(temp_servicedependency->dependent_hostgroup_name);
 				}
 
+			/* Detected same host servicegroups dependencies */
+			same_host_servicedependency=FALSE;
+			if(temp_servicedependency->host_name==NULL && temp_servicedependency->hostgroup_name==NULL)
+				same_host_servicedependency=TRUE;
+
 			/* duplicate service dependency entries */
 			first_item=TRUE;
 			for(temp_dependentservice=dependent_servicelist;temp_dependentservice!=NULL;temp_dependentservice=temp_dependentservice->next){
@@ -4735,6 +4741,10 @@ int xodtemplate_duplicate_objects(void){
 					my_free(temp_servicedependency->dependent_service_description);
 					temp_servicedependency->dependent_service_description=(char *)strdup(temp_dependentservice->name2);
 
+					/* Same host servicegroups dependencies: Use dependentservice host_name for master host_name */
+					if(same_host_servicedependency==TRUE)
+						temp_servicedependency->host_name=(char*)strdup(temp_dependentservice->name1);
+
 					/* clear the dependent servicegroup */
 					temp_servicedependency->have_dependent_servicegroup_name=FALSE;
 					my_free(temp_servicedependency->dependent_servicegroup_name);
@@ -4749,7 +4759,11 @@ int xodtemplate_duplicate_objects(void){
 					}
 
 				/* duplicate service dependency definition */
-				result=xodtemplate_duplicate_servicedependency(temp_servicedependency,temp_servicedependency->host_name,temp_servicedependency->service_description,NULL,NULL,temp_dependentservice->name1,temp_dependentservice->name2,NULL,NULL);
+				/* Same host servicegroups dependencies: Use dependentservice host_name for master host_name instead of undefined (not yet) master host_name */
+				if(same_host_servicedependency==TRUE)
+					result=xodtemplate_duplicate_servicedependency(temp_servicedependency,temp_dependentservice->name1,temp_servicedependency->service_description,NULL,NULL,temp_dependentservice->name1,temp_dependentservice->name2,NULL,NULL);
+				else
+					result=xodtemplate_duplicate_servicedependency(temp_servicedependency,temp_servicedependency->host_name,temp_servicedependency->service_description,NULL,NULL,temp_dependentservice->name1,temp_dependentservice->name2,NULL,NULL);
 
 				/* exit on error */
 				if(result==ERROR){
-- 
1.7.2.3


------------------------------------------------------------------------------
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
Nagios-devel mailing list
Nagios-devel at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-devel


More information about the Developers mailing list