[icinga-checkins] icinga.org: icinga-core/test/cgis: Prevent empty partial hostgroups from displaying

git at icinga.org git at icinga.org
Sun Jul 17 12:02:01 CEST 2011


Module: icinga-core
Branch: test/cgis
Commit: ff256802fdafafebc4805ef1c2b142ebce427d53
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=ff256802fdafafebc4805ef1c2b142ebce427d53

Author: Matthew J. Brooks <matthew at sonomatechpartners.com>
Date:   Sat Jul 16 14:35:11 2011 -0700

Prevent empty partial hostgroups from displaying

The initial change to status.c for partial hostgroup display made it
so that users would see empty hostgroups even for the hostgroups they
are not authorized to see.

This change prevents that from occuring by pre-iterating over the
hostgroup and suppressing the display of it if the hostgroup would
be empty.

refs #1013

---

 cgi/status.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/cgi/status.c b/cgi/status.c
index 33b6acc..e1f2815 100644
--- a/cgi/status.c
+++ b/cgi/status.c
@@ -3688,11 +3688,48 @@ void show_hostgroup_overview(hostgroup *hstgrp){
 	hoststatus *temp_hoststatus=NULL;
 	int odd=0;
 	int json_start=TRUE;
+	int partial_hosts=FALSE;
 
 	/* make sure the user is authorized to view this hostgroup */
 	if(show_partial_hostgroups==FALSE && is_authorized_for_hostgroup(hstgrp,&current_authdata)==FALSE)
 		return;
 
+	/* if we're showing partial hostgroups, find out if there will be any hosts that belong to the hostgroup */
+	/* sadly, this means we are iterating over the host members twice when show_partial_hostgroups==TRUE,
+	 * so this should only be considered a temporary workaround */
+	if(show_partial_hostgroups==TRUE) {
+		for(temp_member=hstgrp->members;temp_member!=NULL;temp_member=temp_member->next){
+
+			/* find the host... */
+			temp_host=find_host(temp_member->host_name);
+			if(temp_host==NULL)
+				continue;
+
+			/* only shown in partial hostgroups if user is authorized to view this host */
+			if (is_authorized_for_host(temp_host,&current_authdata)==FALSE)
+				continue;
+
+			/* find the host status */
+			temp_hoststatus=find_hoststatus(temp_host->name);
+			if(temp_hoststatus==NULL)
+				continue;
+
+			/* make sure we will only be displaying hosts of the specified status levels */
+			if(!(host_status_types & temp_hoststatus->status))
+				continue;
+
+			/* make sure we will only be displaying hosts that have the desired properties */
+			if(passes_host_properties_filter(temp_hoststatus)==FALSE)
+				continue;
+
+			partial_hosts=TRUE;
+		}
+	}
+
+	/* if we're showing partial hostgroups, but there are no hosts to display, there's nothing to see here */
+	if(show_partial_hostgroups==TRUE && partial_hosts==FALSE)
+		return;
+
 	/* print json format */
 	if(content_type==JSON_CONTENT) {
 		printf("{ \"hostgroup_name\": \"%s\",\n",json_encode(hstgrp->group_name));





More information about the icinga-checkins mailing list