Temporary searchgroup patch

Armin Wolfermann aw at osn.de
Wed Jul 2 15:34:23 CEST 2008


Hi,

this patch changes the search function (via Show Host:) to show all
hosts with a common prefix in a temporary hostgroup. Maybe this is
useful for other nagios users as well.

Index: cgi/status.c
===================================================================
RCS file: /cvsroot/nagios/nagios/cgi/status.c,v
retrieving revision 1.75
diff -u -r1.75 status.c
--- cgi/status.c	23 Jun 2008 20:47:46 -0000	1.75
+++ cgi/status.c	2 Jul 2008 13:18:58 -0000
@@ -186,7 +186,7 @@
 	host *temp_host=NULL;
 	hostgroup *temp_hostgroup=NULL;
 	servicegroup *temp_servicegroup=NULL;
-	
+
 	time(&current_time);
 
 	/* get the arguments passed in the URL */
@@ -241,45 +241,23 @@
 	get_authentication_information(&current_authdata);
 
 	/* if a navbar search was performed, find the host by name, address or partial name */
-	if(navbar_search==TRUE){
-		if((temp_host=find_host(host_name))==NULL){
-			for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
-				if(is_authorized_for_host(temp_host,&current_authdata)==FALSE)
-					continue;
-				if(!strcmp(host_name,temp_host->address)){
-					free(host_name);
-					host_name=strdup(temp_host->name);
-					break;
-			                }
-		                }
-			if(temp_host==NULL){
-				for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
-					if(is_authorized_for_host(temp_host,&current_authdata)==FALSE)
-						continue;
-					if((strstr(temp_host->name,host_name)==temp_host->name) || !strncasecmp(temp_host->name,host_name,strlen(host_name))){
-						free(host_name);
-						host_name=strdup(temp_host->name);
-						break;
-			                        }
-		                        }
-			        }
-			}
-			/* last effort, search hostgroups then servicegroups */
-			if(temp_host==NULL){
-				if((temp_hostgroup=find_hostgroup(host_name))!=NULL){
-					display_type=DISPLAY_HOSTGROUPS;
-					show_all_hostgroups=FALSE;
-					free(host_name);
-					hostgroup_name=strdup(temp_hostgroup->group_name);
-					}
-				else if((temp_servicegroup=find_servicegroup(host_name))!=NULL){
-					display_type=DISPLAY_SERVICEGROUPS;
-					show_all_servicegroups=FALSE;
-					free(host_name);
-					servicegroup_name=strdup(temp_servicegroup->group_name);
-				}
+	if(navbar_search==TRUE) {
+		display_type = DISPLAY_HOSTGROUPS;
+		group_style_type = STYLE_DETAIL;
+		show_all_hostgroups = FALSE;
+		display_header = FALSE;
+
+		temp_hostgroup = add_hostgroup("Temporary searchgroup", "Temporary searchgroup");
+		hostgroup_name = strdup(temp_hostgroup->group_name);
+
+		for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next) {
+			if(is_authorized_for_host(temp_host, &current_authdata)==FALSE)
+				continue;
+			if((strstr(temp_host->name, host_name) == temp_host->name) || !strncasecmp(temp_host->name, host_name, strlen(host_name))) {
+				(void)add_host_to_hostgroup(temp_hostgroup, temp_host->name);
 			}
-	        }
+		}
+	}
 
 	if(display_header==TRUE){
 

Regards,
Armin Wolfermann

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08




More information about the Developers mailing list