Title: [opsview-base] [44] On the back of Ton's work, added a NAGIOS_CONTACTGROUPLIST macro / environment variable, which contains hostgroup or servicegroup keywords.
Revision
44
Author
pknight
Date
2012-10-23 14:38:28 +0100 (Tue, 23 Oct 2012)

Log Message

On the back of Ton's work, added a NAGIOS_CONTACTGROUPLIST macro / environment variable, which contains hostgroup or servicegroup keywords.
Note that there is currently no limit to the size of this variable, which could cause some issues with notifications not working.

Modified Paths

Added Paths

Modified: trunk/Makefile
===================================================================
--- trunk/Makefile	2012-10-11 11:31:11 UTC (rev 43)
+++ trunk/Makefile	2012-10-23 13:38:28 UTC (rev 44)
@@ -536,6 +536,7 @@
 	cd ${NAGIOS} && patch -p1 < ../patches/nagios_statedata_with_acks_downtime.patch
 	cd ${NAGIOS} && patch -p1 < ../patches/nagios_addack_info_on_statechange.patch
 	cd ${NAGIOS} && patch -p1 < ../patches/nagios_cgi_add_infobox.patch
+	cd ${NAGIOS} && patch -p1 < ../patches/nagios_contactgrouplist_macro.patch
 	if [ $(KERNEL_NAME) = Linux ] ; then \
 		cd ${NAGIOS} && CFLAGS="${CFLAGS}" ./configure --with-nagios-user=$(NAGIOS_USER) --with-nagios-group=$(NAGIOS_GROUP) --with-command-group=$(NAGIOS_GROUP) --with-cgiurl=/cgi-bin --with-htmurl=/ --enable-libtap ; \
 	elif [ $(KERNEL_NAME) = Darwin ] ; then \

Added: trunk/patches/nagios_contactgrouplist_macro.patch
===================================================================
--- trunk/patches/nagios_contactgrouplist_macro.patch	                        (rev 0)
+++ trunk/patches/nagios_contactgrouplist_macro.patch	2012-10-23 13:38:28 UTC (rev 44)
@@ -0,0 +1,101 @@
+diff -bur nagios-3.2.3.orig/base/notifications.c nagios-3.2.3/base/notifications.c
+--- nagios-3.2.3.orig/base/notifications.c	2012-10-23 13:08:33.000000000 +0000
++++ nagios-3.2.3/base/notifications.c	2012-10-23 13:02:35.000000000 +0000
+@@ -74,6 +74,10 @@
+ 	int result=OK;
+ 	int contacts_notified=0;
+ 	int increment_notification_number=FALSE;
++	contactgroupsmember *temp_contactgroupmember = NULL;
++	char *buf = NULL;
++	char *temp_buf = NULL;
++	int first;
+ 
+ 	log_debug_info(DEBUGL_FUNCTIONS,0,"service_notification()\n");
+ 
+@@ -211,6 +215,23 @@
+ 		my_free(macro_x[MACRO_SERVICENOTIFICATIONID]);
+ 		asprintf(&macro_x[MACRO_SERVICENOTIFICATIONID],"%lu",svc->current_notification_id);
+ 
++		// Opsview patch: Set the contactgroup names this service belongs to.
++		first = 1;
++		asprintf( &buf, "" );
++		for ( temp_contactgroupmember = svc->contact_groups;
++			  temp_contactgroupmember != NULL;
++			  temp_contactgroupmember = temp_contactgroupmember->next ) {
++			temp_buf = buf; // Save this pointer for later freeing
++			asprintf( &buf, "%s%s%s", buf, ( first == 1 ? "" : "," ),
++					temp_contactgroupmember->group_name );
++			if (first == 1)
++				first = 0;
++			my_free(temp_buf);
++		}
++		my_free(macro_x[MACRO_CONTACTGROUPLIST]);
++		macro_x[MACRO_CONTACTGROUPLIST] = (char *)strdup(buf);
++		my_free(buf);
++
+ 		/* notify each contact (duplicates have been removed) */
+ 		for(temp_notification=notification_list;temp_notification!=NULL;temp_notification=temp_notification->next){
+ 
+@@ -1029,6 +1050,10 @@
+ 	int result=OK;
+ 	int contacts_notified=0;
+ 	int increment_notification_number=FALSE;
++	contactgroupsmember *temp_contactgroupmember = NULL;
++	char *buf = NULL;
++	char *temp_buf = NULL;
++	int first;
+ 
+ 	/* clear volatile macros */
+ 	clear_volatile_macros();
+@@ -1158,6 +1183,23 @@
+ 		my_free(macro_x[MACRO_HOSTNOTIFICATIONID]);
+ 		asprintf(&macro_x[MACRO_HOSTNOTIFICATIONID],"%lu",hst->current_notification_id);
+ 
++		// Opsview patch: Set the contactgroup names this host belongs to.
++		first = 1;
++		asprintf( &buf, "" );
++		for ( temp_contactgroupmember = hst->contact_groups;
++			  temp_contactgroupmember != NULL;
++			  temp_contactgroupmember = temp_contactgroupmember->next ) {
++			temp_buf = buf; // Save this pointer for later freeing
++			asprintf( &buf, "%s%s%s", buf, ( first == 1 ? "" : "," ),
++					temp_contactgroupmember->group_name );
++			if (first == 1)
++				first = 0;
++			my_free(temp_buf);
++		}
++		my_free(macro_x[MACRO_CONTACTGROUPLIST]);
++		macro_x[MACRO_CONTACTGROUPLIST] = (char *)strdup(buf);
++		my_free(buf);
++
+ 		/* notify each contact (duplicates have been removed) */
+ 		for(temp_notification=notification_list;temp_notification!=NULL;temp_notification=temp_notification->next){
+ 
+diff -bur nagios-3.2.3.orig/common/macros.c nagios-3.2.3/common/macros.c
+--- nagios-3.2.3.orig/common/macros.c	2010-09-21 15:05:31.000000000 +0000
++++ nagios-3.2.3/common/macros.c	2012-10-23 12:03:41.000000000 +0000
+@@ -2722,6 +2722,7 @@
+ 	add_macrox_name(MACRO_LASTHOSTSTATEID,"LASTHOSTSTATEID");
+ 	add_macrox_name(MACRO_LASTSERVICESTATE,"LASTSERVICESTATE");
+ 	add_macrox_name(MACRO_LASTSERVICESTATEID,"LASTSERVICESTATEID");
++	add_macrox_name(MACRO_CONTACTGROUPLIST,"CONTACTGROUPLIST");
+ 
+ 	return OK;
+         }
+diff -bur nagios-3.2.3.orig/include/macros.h nagios-3.2.3/include/macros.h
+--- nagios-3.2.3.orig/include/macros.h	2008-11-30 17:22:59.000000000 +0000
++++ nagios-3.2.3/include/macros.h	2012-10-23 10:42:36.000000000 +0000
+@@ -40,7 +40,7 @@
+ 
+ #define MAX_USER_MACROS				256	/* maximum number of $USERx$ macros */
+ 
+-#define MACRO_X_COUNT				153	/* size of macro_x[] array */
++#define MACRO_X_COUNT				154	/* size of macro_x[] array */
+ 
+ #define MACRO_HOSTNAME				0
+ #define MACRO_HOSTALIAS				1
+@@ -195,6 +195,7 @@
+ #define MACRO_LASTHOSTSTATEID                   150
+ #define MACRO_LASTSERVICESTATE                  151
+ #define MACRO_LASTSERVICESTATEID                152
++#define MACRO_CONTACTGROUPLIST                  153

_______________________________________________
Opsview-checkins mailing list
[email protected]
http://lists.opsview.org/lists/listinfo/opsview-checkins

Reply via email to