[icinga-checkins] icinga.org: icinga-core/mfriedrich/solaris: add possibility to use * as a wildcard for all hosts in servicegroup definition #813

git at icinga.org git at icinga.org
Fri Sep 24 19:08:05 CEST 2010


Module: icinga-core
Branch: mfriedrich/solaris
Commit: e9456d287d185fe2e0b359e59b963a307e053f5a
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=e9456d287d185fe2e0b359e59b963a307e053f5a

Author: Ricardo Bartels <ricardo at bitchbrothers.com>
Date:   Thu Sep 23 07:26:18 2010 +0200

add possibility to use * as a wildcard for all hosts in servicegroup definition #813

---

 Changelog           |    3 ++-
 xdata/xodtemplate.c |   40 +++++++++++++++++++++++++++++++---------
 2 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/Changelog b/Changelog
index c2ab00a..d9efe48 100644
--- a/Changelog
+++ b/Changelog
@@ -5,10 +5,11 @@ Icinga 1.2.x Change Log
 1.2.0 - 06/10/2010
 
 ENHANCEMENTS
-i* core: add eventhandler override (Sven Nierlein) #731
+* core: add eventhandler override (Sven Nierlein) #731
 * core: add config option to disable logging into the daemon log file #311
 * core: fix delay sorting of comments/downtimes (Ton Voon) #753
 * core: fix custom macros being cleaned/stripped (as they are user-defined and should be trusted) (Peter Morch) #752
+* core: add the possibility to use * as a wildcard for all hosts in servicegroup definition #813
 
 * classic ui: add commands expander to config display (Jochen Bern) #746
 	- $ARGn$ substitution will be shown between command_line and
diff --git a/xdata/xodtemplate.c b/xdata/xodtemplate.c
index 0b13483..e5f0ca5 100644
--- a/xdata/xodtemplate.c
+++ b/xdata/xodtemplate.c
@@ -13106,10 +13106,11 @@ int xodtemplate_expand_servicegroups(xodtemplate_memberlist **list, xodtemplate_
         }
 
 
-/* expands services (host name is not expanded) */
+/* expands services and hosts as well */
 int xodtemplate_expand_services(xodtemplate_memberlist **list, xodtemplate_memberlist **reject_list, char *host_name, char *services, int _config_file, int _start_line){
 	char *service_names=NULL;
 	char *temp_ptr=NULL;
+	xodtemplate_host *temp_host=NULL;
 	xodtemplate_service *temp_service=NULL;
 	regex_t preg;
 	regex_t preg2;
@@ -13244,16 +13245,37 @@ int xodtemplate_expand_services(xodtemplate_memberlist **list, xodtemplate_membe
 					temp_ptr++;
 		                        }
 
-				/* find the service */
-				if((temp_service=xodtemplate_find_real_service(host_name,temp_ptr))!=NULL){
+				/* excluding all hosts is not allowed */
+				if(strcmp(host_name,"!*")) {
 
-					found_match=TRUE;
+					/* test match against all hosts */
+					for(temp_host=xodtemplate_host_list;temp_host!=NULL;temp_host=temp_host->next){
 
-					/* add service to the list */
-					xodtemplate_add_member_to_memberlist((reject_item==TRUE)?reject_list:list,host_name,temp_service->service_description);
-				        }
-			        }
-		        }
+						if(temp_host->host_name==NULL)
+						    continue;
+						
+						if(host_name[0]=='!'){
+							host_name++;
+							if (reject_item==FALSE)
+								reject_item=TRUE;
+						}
+
+						/* if there are all hosts given or just a single host, find a service for each of them */
+						if(!strcmp(host_name,"*") || !strcmp(temp_host->host_name,host_name)){
+
+							/* find the service */
+							if((temp_service=xodtemplate_find_real_service(temp_host->host_name,temp_ptr))!=NULL){
+
+								found_match=TRUE;
+									
+								/* add service to the list */
+								xodtemplate_add_member_to_memberlist((reject_item==TRUE)?reject_list:list,temp_host->host_name,temp_service->service_description);
+							}
+						} 
+					}
+				}
+			}
+		}
 
 		/* we didn't find a match */
 		if(found_match==FALSE && reject_item==FALSE){





More information about the icinga-checkins mailing list