[icinga-checkins] icinga.org: icinga-core/rbartels/cgi-current: Added option to show partial hostgroups #1013

git at icinga.org git at icinga.org
Tue Jun 14 20:42:32 CEST 2011


Module: icinga-core
Branch: rbartels/cgi-current
Commit: 50767197fda2b4a685f730b88be0b6aee06a374f
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=50767197fda2b4a685f730b88be0b6aee06a374f

Author: Matthew J. Brooks <matthew at sonomatechpartners.com>
Date:   Thu Jun  2 23:09:19 2011 -0700

Added option to show partial hostgroups #1013

By default, a user only sees a hostgroup and the hosts within it if
they are an authorized contact for all of the hosts of the group.

This commit adds the cgi.cfg option:

show_partial_hostgroups=0

When enabled, the hostgroups overview will show a partial listing
of hosts that the user is an authorized contact for within each
hostgroup.

It will also add the string "(Partial Hostgroups Enabled)" to the
top of the Hostgroup Overview to help prevent any confusion over
whether the option is in use or not. However for privacy reasons,
hostgroups that are only showing a partial listing are not
specifically indicated.

COMPATABILITY NOTICE: As with any tweak made to the output of the
CGIs, enabling this option may adversely impact third party
programs that rely on 'screen scraping' to get their information.
If you encounter such a problem, turn this option back to it's
default of off and encourage the developer(s) of the program to
use JSON for their data needs instead.

refs #1013

---

 Changelog                |    1 +
 cgi/cgiutils.c           |    5 +++++
 cgi/status.c             |   27 +++++++++++++++++++--------
 sample-config/cgi.cfg.in |   11 +++++++++++
 4 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/Changelog b/Changelog
index b51e15a..1f09dc3 100644
--- a/Changelog
+++ b/Changelog
@@ -5,6 +5,7 @@ Icinga 1.5.x Change Log
 1.5.0 - ??/08/2011
 
 ENHANCEMENTS
+* classic ui: Added option to show partial hostgroups (Matthew Brooks) #1013
 
 FIXES
 * classic ui: fix cross site scripting vulnerability in config.cgi on config expander arguments #1605
diff --git a/cgi/cgiutils.c b/cgi/cgiutils.c
index 7bedc77..defc338 100644
--- a/cgi/cgiutils.c
+++ b/cgi/cgiutils.c
@@ -140,6 +140,8 @@ int		add_notif_num_soft=0;
 int		enforce_comments_on_actions=FALSE;
 int		week_starts_on_monday=FALSE;
 
+int		show_partial_hostgroups=FALSE;
+
 extern hostgroup       *hostgroup_list;
 extern contactgroup    *contactgroup_list;
 extern command         *command_list;
@@ -371,6 +373,9 @@ int read_cgi_config_file(char *filename){
 		else if(!strcmp(var,"show_all_services_host_is_authorized_for"))
 			show_all_services_host_is_authorized_for=(atoi(val)>0)?TRUE:FALSE;
 
+		else if(!strcmp(var,"show_partial_hostgroups"))
+			show_partial_hostgroups=(atoi(val)>0)?TRUE:FALSE;
+
 		else if(!strcmp(var,"use_pending_states"))
 			use_pending_states=(atoi(val)>0)?TRUE:FALSE;
 
diff --git a/cgi/status.c b/cgi/status.c
index 820fc00..5d8b97c 100644
--- a/cgi/status.c
+++ b/cgi/status.c
@@ -71,6 +71,9 @@ extern servicegroup *servicegroup_list;
 extern hoststatus *hoststatus_list;
 extern servicestatus *servicestatus_list;
 
+/* show any hosts in hostgroups the user is authorized for */
+extern show_partial_hostgroups;
+
 #define MAX_MESSAGE_BUFFER		4096
 
 #define DISPLAY_HOSTS			0
@@ -3484,7 +3487,7 @@ void show_hostgroup_overviews(void){
 			for(temp_hostgroup=hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){
 
 				/* make sure the user is authorized to view this hostgroup */
-				if(is_authorized_for_hostgroup(temp_hostgroup,&current_authdata)==FALSE)
+				if(show_partial_hostgroups==FALSE && is_authorized_for_hostgroup(temp_hostgroup,&current_authdata)==FALSE)
 					continue;
 
 				// always add a comma, except for the first line
@@ -3501,7 +3504,7 @@ void show_hostgroup_overviews(void){
 			if(temp_hostgroup==NULL)
 				hostgroup_error=TRUE;
 			else {
-				if(is_authorized_for_hostgroup(temp_hostgroup,&current_authdata)==TRUE){
+				if(show_partial_hostgroups==FALSE && is_authorized_for_hostgroup(temp_hostgroup,&current_authdata)==TRUE){
 
 					show_hostgroup_overview(temp_hostgroup);
 
@@ -3525,7 +3528,7 @@ void show_hostgroup_overviews(void){
 
 		printf("<DIV ALIGN=CENTER CLASS='statusTitle'>Service Overview For ");
 		if(show_all_hostgroups==TRUE)
-			printf("All Host Groups");
+			printf("%s",show_partial_hostgroups?"All Host Groups<br>(Partial Hostgroups Enabled)":"All Host Groups");
 		else
 			printf("Host Group '%s'",hostgroup_name);
 		printf("</DIV>\n");
@@ -3555,7 +3558,7 @@ void show_hostgroup_overviews(void){
 			for(temp_hostgroup=hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){
 
 				/* make sure the user is authorized to view this hostgroup */
-				if(is_authorized_for_hostgroup(temp_hostgroup,&current_authdata)==FALSE)
+				if(show_partial_hostgroups==FALSE && is_authorized_for_hostgroup(temp_hostgroup,&current_authdata)==FALSE)
 					continue;
 
 				if(current_column==1)
@@ -3598,7 +3601,7 @@ void show_hostgroup_overviews(void){
 				printf("<DIV ALIGN=CENTER>\n");
 				printf("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD ALIGN=CENTER>\n");
 
-				if(is_authorized_for_hostgroup(temp_hostgroup,&current_authdata)==TRUE){
+				if(show_partial_hostgroups==FALSE && is_authorized_for_hostgroup(temp_hostgroup,&current_authdata)==TRUE){
 
 					show_hostgroup_overview(temp_hostgroup);
 
@@ -3650,7 +3653,7 @@ void show_hostgroup_overview(hostgroup *hstgrp){
 	int json_start=TRUE;
 
 	/* make sure the user is authorized to view this hostgroup */
-	if(is_authorized_for_hostgroup(hstgrp,&current_authdata)==FALSE)
+	if(show_partial_hostgroups==FALSE && is_authorized_for_hostgroup(hstgrp,&current_authdata)==FALSE)
 		return;
 
 	/* print json format */
@@ -3679,6 +3682,10 @@ void show_hostgroup_overview(hostgroup *hstgrp){
 		if(temp_host==NULL)
 			continue;
 
+		/* only show in partial hostgroups if user is authorized to view this host */
+		if (show_partial_hostgroups==TRUE && 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)
@@ -3981,7 +3988,7 @@ void show_hostgroup_summaries(void){
 		for(temp_hostgroup=hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){
 
 			/* make sure the user is authorized to view this hostgroup */
-			if(is_authorized_for_hostgroup(temp_hostgroup,&current_authdata)==FALSE)
+			if(show_partial_hostgroups==FALSE && is_authorized_for_hostgroup(temp_hostgroup,&current_authdata)==FALSE)
 				continue;
 
 			if(odd==0)
@@ -4587,7 +4594,7 @@ void show_hostgroup_grids(void){
 		for(temp_hostgroup=hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){
 
 			/* make sure the user is authorized to view this hostgroup */
-			if(is_authorized_for_hostgroup(temp_hostgroup,&current_authdata)==FALSE)
+			if(show_partial_hostgroups==FALSE && is_authorized_for_hostgroup(temp_hostgroup,&current_authdata)==FALSE)
 				continue;
 
 			if(odd==0)
@@ -4689,6 +4696,10 @@ void show_hostgroup_grid(hostgroup *temp_hostgroup){
 		if(temp_host==NULL)
 			continue;
 
+		/* only show in partial hostgroups if user is authorized to view this host */
+		if (show_partial_hostgroups==TRUE && is_authorized_for_host(temp_host,&current_authdata)==FALSE)
+			continue;
+
 		/* grab macros */
 		grab_host_macros_r(mac, temp_host);
 
diff --git a/sample-config/cgi.cfg.in b/sample-config/cgi.cfg.in
index 830cca2..2c6e6d3 100644
--- a/sample-config/cgi.cfg.in
+++ b/sample-config/cgi.cfg.in
@@ -265,6 +265,17 @@ authorized_for_all_host_commands=icingaadmin
 show_all_services_host_is_authorized_for=1
 
 
+# SHOW PARTIAL HOSTGROUPS
+# By default, a user only sees a hostgroup and the hosts within it if
+# they are an authorized contact for all of the hosts of the group. By
+# enabling this option hostgroups will show a partial listing of hosts
+# the user is an authorized contact for in the hostgroups.
+# Values: 0 - disabled, user only sees full hostgroups (default)
+#         1 - enabled, user sees partial hostgroups
+
+show_partial_hostgroups=0
+
+
 # STATUSMAP BACKGROUND IMAGE
 # This option allows you to specify an image to be used as a
 # background in the statusmap CGI.  It is assumed that the image





More information about the icinga-checkins mailing list