Inherit service contacts from host

Marek Marczykowski marmarek at staszic.waw.pl
Sat Feb 21 19:27:19 CET 2009


I've written some patch to include host contacts when senting
notification about some service of that host. It adds config option
"notify_host_contacts" to service definition. Maybe it will be useful
for someone else. Attached patch is against nagios-3.1.0 (not cvs head),
but I think it isn't problem. What do you think?

-- 
Regargs,
Marek Marczykowski          |   gg:2873965
marmarek at staszic waw pl  | xmpp:marmarek at staszic waw pl

-------------- next part --------------
diff -ur nagios-3.1.0.orig/base/notifications.c nagios-3.1.0/base/notifications.c
--- nagios-3.1.0.orig/base/notifications.c	2008-11-30 18:22:58.000000000 +0100
+++ nagios-3.1.0/base/notifications.c	2009-02-21 16:56:27.000000000 +0100
@@ -112,6 +112,11 @@
 	/* create the contact notification list for this service */
 	create_notification_list_from_service(svc,options,&escalated);
 
+	if (svc->notify_host_contacts) {
+		/* create the contact notification list for this host */
+		create_notification_list_from_host(svc->host_ptr,options,&escalated);
+	}
+
 #ifdef USE_EVENT_BROKER
 	/* send data to event broker */
 	end_time.tv_sec=0L;
diff -ur nagios-3.1.0.orig/common/objects.c nagios-3.1.0/common/objects.c
--- nagios-3.1.0.orig/common/objects.c	2008-11-30 18:22:59.000000000 +0100
+++ nagios-3.1.0/common/objects.c	2009-02-21 16:47:02.000000000 +0100
@@ -1762,7 +1762,7 @@
 
 
 /* add a new service to the list in memory */
-service *add_service(char *host_name, char *description, char *display_name, char *check_period, int initial_state, int max_attempts, int parallelize, int accept_passive_checks, double check_interval, double retry_interval, double notification_interval, double first_notification_delay, char *notification_period, int notify_recovery, int notify_unknown, int notify_warning, int notify_critical, int notify_flapping, int notify_downtime, int notifications_enabled, int is_volatile, char *event_handler, int event_handler_enabled, char *check_command, int checks_enabled, int flap_detection_enabled, double low_flap_threshold, double high_flap_threshold, int flap_detection_on_ok, int flap_detection_on_warning, int flap_detection_on_unknown, int flap_detection_on_critical, int stalk_on_ok, int stalk_on_warning, int stalk_on_unknown, int stalk_on_critical, int process_perfdata, int failure_prediction_enabled, char *failure_prediction_options, int check_freshness, int freshness_threshold, char *notes, char *notes_url, char *action_url, char *icon_image, char *icon_image_alt, int retain_status_information, int retain_nonstatus_information, int obsess_over_service){
+service *add_service(char *host_name, char *description, char *display_name, char *check_period, int initial_state, int max_attempts, int parallelize, int accept_passive_checks, double check_interval, double retry_interval, double notification_interval, double first_notification_delay, char *notification_period, int notify_recovery, int notify_unknown, int notify_warning, int notify_critical, int notify_flapping, int notify_downtime, int notifications_enabled, int notify_host_contacts, int is_volatile, char *event_handler, int event_handler_enabled, char *check_command, int checks_enabled, int flap_detection_enabled, double low_flap_threshold, double high_flap_threshold, int flap_detection_on_ok, int flap_detection_on_warning, int flap_detection_on_unknown, int flap_detection_on_critical, int stalk_on_ok, int stalk_on_warning, int stalk_on_unknown, int stalk_on_critical, int process_perfdata, int failure_prediction_enabled, char *failure_prediction_options, int check_freshness, int freshness_threshold, char *notes, char *notes_url, char *action_url, char *icon_image, char *icon_image_alt, int retain_status_information, int retain_nonstatus_information, int obsess_over_service){
 	service *new_service=NULL;
 	int result=OK;
 #ifdef NSCORE
@@ -1908,6 +1908,7 @@
 	new_service->retain_status_information=(retain_status_information>0)?TRUE:FALSE;
 	new_service->retain_nonstatus_information=(retain_nonstatus_information>0)?TRUE:FALSE;
 	new_service->notifications_enabled=(notifications_enabled>0)?TRUE:FALSE;
+	new_service->notify_host_contacts=(notify_host_contacts>0)?TRUE:FALSE;
 	new_service->obsess_over_service=(obsess_over_service>0)?TRUE:FALSE;
 	new_service->failure_prediction_enabled=(failure_prediction_enabled>0)?TRUE:FALSE;
 #ifdef NSCORE
diff -ur nagios-3.1.0.orig/include/objects.h nagios-3.1.0/include/objects.h
--- nagios-3.1.0.orig/include/objects.h	2008-11-30 18:22:59.000000000 +0100
+++ nagios-3.1.0/include/objects.h	2009-02-21 16:22:58.000000000 +0100
@@ -424,6 +424,7 @@
 	int	notify_on_recovery;
 	int     notify_on_flapping;
 	int     notify_on_downtime;
+	int     notify_host_contacts;
 	int     stalk_on_ok;
 	int     stalk_on_warning;
 	int     stalk_on_unknown;
@@ -657,7 +658,7 @@
 contactgroup *add_contactgroup(char *,char *);								/* adds a contactgroup definition */
 contactsmember *add_contact_to_contactgroup(contactgroup *,char *);					/* adds a contact to a contact group definition */
 command *add_command(char *,char *);									/* adds a command definition */
-service *add_service(char *,char *,char *,char *,int,int,int,int,double,double,double,double,char *,int,int,int,int,int,int,int,int,char *,int,char *,int,int,double,double,int,int,int,int,int,int,int,int,int,int,char *,int,int,char *,char *,char *,char *,char *,int,int,int);	/* adds a service definition */
+service *add_service(char *,char *,char *,char *,int,int,int,int,double,double,double,double,char *,int,int,int,int,int,int,int,int,int,char *,int,char *,int,int,double,double,int,int,int,int,int,int,int,int,int,int,char *,int,int,char *,char *,char *,char *,char *,int,int,int);	/* adds a service definition */
 contactgroupsmember *add_contactgroup_to_service(service *,char *);					/* adds a contact group to a service definition */
 contactsmember *add_contact_to_service(service *,char *);                                               /* adds a contact to a host definition */
 serviceescalation *add_serviceescalation(char *,char *,int,int,double,char *,int,int,int,int);          /* adds a service escalation definition */
diff -ur nagios-3.1.0.orig/xdata/xodtemplate.c nagios-3.1.0/xdata/xodtemplate.c
--- nagios-3.1.0.orig/xdata/xodtemplate.c	2009-01-25 15:42:35.000000000 +0100
+++ nagios-3.1.0/xdata/xodtemplate.c	2009-02-21 16:45:56.000000000 +0100
@@ -1685,6 +1685,8 @@
 		new_service->have_notification_options=FALSE;
 		new_service->notifications_enabled=TRUE;
 		new_service->have_notifications_enabled=FALSE;
+		new_service->notify_host_contacts=FALSE;
+		new_service->have_notify_host_contacts=FALSE;
 		new_service->notification_interval=30.0;
 		new_service->have_notification_interval=FALSE;
 		new_service->first_notification_delay=0;
@@ -4075,6 +4077,10 @@
 			temp_service->notifications_enabled=(atoi(value)>0)?TRUE:FALSE;
 			temp_service->have_notifications_enabled=TRUE;
 		        }
+		else if(!strcmp(variable,"notify_host_contacts")){
+			temp_service->notify_host_contacts=(atoi(value)>0)?TRUE:FALSE;
+			temp_service->have_notify_host_contacts=TRUE;
+		        }
 		else if(!strcmp(variable,"notification_interval")){
 			temp_service->notification_interval=strtod(value,NULL);
 			temp_service->have_notification_interval=TRUE;
@@ -6269,6 +6275,8 @@
 	new_service->have_notification_options=temp_service->have_notification_options;
 	new_service->notifications_enabled=temp_service->notifications_enabled;
 	new_service->have_notifications_enabled=temp_service->have_notifications_enabled;
+	new_service->notify_host_contacts=temp_service->notify_host_contacts;
+	new_service->have_notify_host_contacts=temp_service->have_notify_host_contacts;
 	new_service->notification_interval=temp_service->notification_interval;
 	new_service->have_notification_interval=temp_service->have_notification_interval;
 	new_service->first_notification_delay=temp_service->first_notification_delay;
@@ -8192,6 +8200,10 @@
 			this_service->notifications_enabled=template_service->notifications_enabled;
 			this_service->have_notifications_enabled=TRUE;
 	                }
+		if(this_service->have_notify_host_contacts==FALSE && template_service->have_notify_host_contacts==TRUE){
+			this_service->notify_host_contacts=template_service->notify_host_contacts;
+			this_service->have_notify_host_contacts=TRUE;
+	                }
 		if(this_service->have_notification_interval==FALSE && template_service->have_notification_interval==TRUE){
 			this_service->notification_interval=template_service->notification_interval;
 			this_service->have_notification_interval=TRUE;
@@ -10480,7 +10492,7 @@
 		return OK;
 
 	/* add the service */
-	new_service=add_service(this_service->host_name,this_service->service_description,this_service->display_name,this_service->check_period,this_service->initial_state,this_service->max_check_attempts,this_service->parallelize_check,this_service->passive_checks_enabled,this_service->check_interval,this_service->retry_interval,this_service->notification_interval,this_service->first_notification_delay,this_service->notification_period,this_service->notify_on_recovery,this_service->notify_on_unknown,this_service->notify_on_warning,this_service->notify_on_critical,this_service->notify_on_flapping,this_service->notify_on_downtime,this_service->notifications_enabled,this_service->is_volatile,this_service->event_handler,this_service->event_handler_enabled,this_service->check_command,this_service->active_checks_enabled,this_service->flap_detection_enabled,this_service->low_flap_threshold,this_service->high_flap_threshold,this_service->flap_detection_on_ok,this_service->flap_detection_on_warning,this_service->flap_detection_on_unknown,this_service->flap_detection_on_critical,this_service->stalk_on_ok,this_service->stalk_on_warning,this_service->stalk_on_unknown,this_service->stalk_on_critical,this_service->process_perf_data,this_service->failure_prediction_enabled,this_service->failure_prediction_options,this_service->check_freshness,this_service->freshness_threshold,this_service->notes,this_service->notes_url,this_service->action_url,this_service->icon_image,this_service->icon_image_alt,this_service->retain_status_information,this_service->retain_nonstatus_information,this_service->obsess_over_service);
+	new_service=add_service(this_service->host_name,this_service->service_description,this_service->display_name,this_service->check_period,this_service->initial_state,this_service->max_check_attempts,this_service->parallelize_check,this_service->passive_checks_enabled,this_service->check_interval,this_service->retry_interval,this_service->notification_interval,this_service->first_notification_delay,this_service->notification_period,this_service->notify_on_recovery,this_service->notify_on_unknown,this_service->notify_on_warning,this_service->notify_on_critical,this_service->notify_on_flapping,this_service->notify_on_downtime,this_service->notifications_enabled,this_service->notify_host_contacts,this_service->is_volatile,this_service->event_handler,this_service->event_handler_enabled,this_service->check_command,this_service->active_checks_enabled,this_service->flap_detection_enabled,this_service->low_flap_threshold,this_service->high_flap_threshold,this_service->flap_detection_on_ok,this_service->flap_detection_on_warning,this_service->flap_detection_on_unknown,this_service->flap_detection_on_critical,this_service->stalk_on_ok,this_service->stalk_on_warning,this_service->stalk_on_unknown,this_service->stalk_on_critical,this_service->process_perf_data,this_service->failure_prediction_enabled,this_service->failure_prediction_options,this_service->check_freshness,this_service->freshness_threshold,this_service->notes,this_service->notes_url,this_service->action_url,this_service->icon_image,this_service->icon_image_alt,this_service->retain_status_information,this_service->retain_nonstatus_information,this_service->obsess_over_service);
 
 	/* return with an error if we couldn't add the service */
 	if(new_service==NULL){
diff -ur nagios-3.1.0.orig/xdata/xodtemplate.h nagios-3.1.0/xdata/xodtemplate.h
--- nagios-3.1.0.orig/xdata/xodtemplate.h	2008-11-30 18:22:59.000000000 +0100
+++ nagios-3.1.0/xdata/xodtemplate.h	2009-02-21 16:44:20.000000000 +0100
@@ -401,6 +401,7 @@
 	int        notify_on_flapping;
 	int        notify_on_downtime;
 	int        notifications_enabled;
+	int        notify_host_contacts;
 	char       *notification_period;
 	double     notification_interval;
 	double     first_notification_delay;
@@ -458,6 +459,7 @@
 	int        have_flap_detection_options;
 	int        have_notification_options;
 	int        have_notifications_enabled;
+	int        have_notify_host_contacts;
 	int        have_notification_dependencies;
 	int        have_notification_interval;
 	int        have_first_notification_delay;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <https://www.monitoring-lists.org/archive/developers/attachments/20090221/17b384a5/attachment.sig>
-------------- next part --------------
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
-------------- next part --------------
_______________________________________________
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