[Nagios-devel] [PATCH] Add display of parent and child hosts to extinfo.cgi

psychotrahe at gmx.de psychotrahe at gmx.de
Sun May 17 10:53:18 UTC 2009


From: Matthias Eble <matthias.eble at mailing.kaufland-informationssysteme.com>

When extinfo.cgi displays a host's status, parent and/or child hosts
get displayed also. New cgi.cfg variables have been added to prevent
flooding in case of too many parents/children:
  child_host_display_len
  parent_host_display_len
---

Hi all,

so after some tinkering I thought that it'd be a good idea to display
parent/child hosts on extinfo.cgi rather linking to config.cgi.
So here's the patch including doc updates.

Matthias

 cgi/cgiutils.c           |    8 ++++
 cgi/extinfo.c            |   59 +++++++++++++++++++++++++++++
 html/docs/configcgi.html |   93 ++++++++++++++++++++++++++++++++++++++++++++++
 sample-config/cgi.cfg.in |    9 ++++
 4 files changed, 169 insertions(+), 0 deletions(-)

diff --git a/cgi/cgiutils.c b/cgi/cgiutils.c
index a373ec3..1f3b985 100644
--- a/cgi/cgiutils.c
+++ b/cgi/cgiutils.c
@@ -109,6 +109,8 @@ int             refresh_rate=DEFAULT_REFRESH_RATE;
 int             escape_html_tags=FALSE;
 
 int             use_ssl_authentication=FALSE;
+int             child_host_display_len=200;
+int             parent_host_display_len=200;
 
 int             default_statusmap_layout_method=0;
 int             default_statuswrl_layout_method=0;
@@ -410,6 +412,12 @@ int read_cgi_config_file(char *filename){
 
 		else if(!strcmp(var,"use_ssl_authentication"))
 			use_ssl_authentication=(atoi(val)>0)?TRUE:FALSE;
+
+		else if(!strcmp(var,"child_host_display_len"))
+			child_host_display_len=atoi(val);
+
+		else if(!strcmp(var,"parent_host_display_len"))
+			parent_host_display_len=atoi(val);
  	        }
 
 	/* free memory and close the file */
diff --git a/cgi/extinfo.c b/cgi/extinfo.c
index c3f2e83..6168399 100644
--- a/cgi/extinfo.c
+++ b/cgi/extinfo.c
@@ -67,6 +67,8 @@ extern char url_logo_images_path[MAX_FILENAME_LENGTH];
 extern char log_file[MAX_FILENAME_LENGTH];
 
 extern int              enable_splunk_integration;
+extern int              child_host_display_len;
+extern int              parent_host_display_len;
 
 extern char             *notes_url_target;
 extern char             *action_url_target;
@@ -77,6 +79,7 @@ extern hoststatus *hoststatus_list;
 extern servicestatus *servicestatus_list;
 extern hostgroup *hostgroup_list;
 extern servicegroup *servicegroup_list;
+extern host *host_list;
 
 
 #define MAX_MESSAGE_BUFFER		4096
@@ -121,6 +124,8 @@ char *servicegroup_name="";
 char *service_desc="";
 
 int display_type=DISPLAY_PROCESS_INFO;
+int display_all_parents=FALSE;
+int display_all_children=FALSE;
 
 int sort_type=SORT_ASCENDING;
 int sort_option=SORT_NEXTCHECKTIME;
@@ -133,9 +138,13 @@ int display_header=TRUE;
 int main(void){
 	int result=OK;
 	int found=FALSE;
+	int len=0;
 	char temp_buffer[MAX_INPUT_BUFFER]="";
 	char *processed_string=NULL;
+	char *query_string=NULL;
 	host *temp_host=NULL;
+	host *temp_host2=NULL;
+	hostsmember *temp_parenthost=NULL;
 	hostgroup *temp_hostgroup=NULL;
 	service *temp_service=NULL;
 	servicegroup *temp_servicegroup=NULL;
@@ -143,6 +152,8 @@ int main(void){
 
 	/* get the arguments passed in the URL */
 	process_cgivars();
+	if(!(query_string = getenv("QUERY_STRING")))
+		query_string="";
 
 	/* reset internal variables */
 	reset_cgi_vars();
@@ -325,6 +336,45 @@ int main(void){
 				printf("<DIV CLASS='data'>Host</DIV>\n");
 				printf("<DIV CLASS='dataTitle'>%s</DIV>\n",temp_host->alias);
 				printf("<DIV CLASS='dataTitle'>(%s)</DIV><BR>\n",temp_host->name);
+
+				if (temp_host->parent_hosts != NULL) {
+					/* display parent hosts */
+					printf("<DIV CLASS='data'>Parent Hosts:</DIV>\n");
+					printf("<DIV CLASS='dataTitle'>\n");
+					for(temp_parenthost=temp_host->parent_hosts;temp_parenthost!=NULL;temp_parenthost=temp_parenthost->next){
+						len += strlen(temp_parenthost->host_name);
+						if(len > parent_host_display_len && !display_all_parents) {
+							printf("<A HREF='%s?%s&display_all_parents'>...</A>",EXTINFO_CGI,query_string);
+							break;
+						}
+						printf("<A HREF='%s?host=%s'>%s</A>\n",STATUS_CGI, url_encode(temp_parenthost->host_name),temp_parenthost->host_name);
+					}
+					printf("</DIV><BR>\n");
+				}
+
+				len=0;
+				/* look up and display child hosts */
+				for(temp_host2=host_list;temp_host2!=NULL;temp_host2=temp_host2->next){
+					if(len > child_host_display_len && !display_all_children) {
+						printf("<A HREF='%s?%s&display_all_children'>...</A>", EXTINFO_CGI, query_string);
+						break;
+					}
+					if (temp_host2->parent_hosts != NULL) {
+						for(temp_parenthost=temp_host2->parent_hosts;temp_parenthost!=NULL;temp_parenthost=temp_parenthost->next){
+							if(!strcmp(temp_host->name, temp_parenthost->host_name)) {
+								if(len == 0){
+									printf("<DIV CLASS='data'>Child Hosts:</DIV>\n");
+									printf("<DIV CLASS='dataTitle'>\n");
+								}
+								len += strlen(temp_parenthost->host_name);
+								printf("<A HREF='%s?host=%s'>%s</A>\n",STATUS_CGI,url_encode(temp_host2->name),temp_host2->name);
+							}
+						}
+					}
+				}
+				if(len != 0)
+					printf("</DIV><BR>\n");
+
 				printf("<DIV CLASS='data'>Member of</DIV><DIV CLASS='dataTitle'>");
 				for(temp_hostgroup=hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){
 					if(is_host_member_of_hostgroup(temp_hostgroup,temp_host)==TRUE){
@@ -755,6 +805,15 @@ int process_cgivars(void){
 		/* we found the noheader option */
 		else if(!strcmp(variables[x],"noheader"))
 			display_header=FALSE;
+
+		/* we found the display_all_parents option */
+		else if(!strcmp(variables[x],"display_all_parents"))
+			display_all_parents=TRUE;
+
+		/* we found the display_all_children option */
+		else if(!strcmp(variables[x],"display_all_children"))
+			display_all_children=TRUE;
+
 	        }
 
 	/* free memory allocated to the CGI variables */
diff --git a/html/docs/configcgi.html b/html/docs/configcgi.html
index a26b96a..56fd182 100644
--- a/html/docs/configcgi.html
+++ b/html/docs/configcgi.html
@@ -852,6 +852,99 @@ This option allows you to restrict users from changing the author name when subm
 
 
 
+<a name="parent_host_display_len"></a>
+
+<table border="0" width="100%" class="Default">
+
+<tr>
+
+<td bgcolor="#cbcbcb"><strong>Displayed length of parent hosts in extinfo.cgi</strong></td>
+
+</tr>
+
+</table>
+
+<br>
+
+
+
+<table border="0" class="Default">
+
+<tr>
+
+<td valign=top>Format:</td>
+
+<td><strong>parent_host_display_len=&lt;length&gt;</strong></td>
+
+</tr>
+
+<tr>
+
+<td valign=top>Example:</td>
+
+<td><font color="red"><strong>parent_host_display_len=200</strong></font></td>
+
+</tr>
+
+</table>
+
+
+
+<p>
+
+This option prevents flooding the output of extinfo.cgi if a host has many parent hosts. When the length of all parent hostnames exceeds this number, a continuation link is displayed, so that, when followed all parent hostnames are displayed.
+
+</p>
+
+
+
+<a name="child_host_display_len"></a>
+
+<table border="0" width="100%" class="Default">
+
+<tr>
+
+<td bgcolor="#cbcbcb"><strong>Displayed length of child hosts in extinfo.cgi</strong></td>
+
+</tr>
+
+</table>
+
+<br>
+
+
+
+<table border="0" class="Default">
+
+<tr>
+
+<td valign=top>Format:</td>
+
+<td><strong>child_host_display_len=&lt;length&gt;</strong></td>
+
+</tr>
+
+<tr>
+
+<td valign=top>Example:</td>
+
+<td><font color="red"><strong>child_host_display_len=200</strong></font></td>
+
+</tr>
+
+</table>
+
+
+
+<p>
+
+These options prevent flooding the output of extinfo.cgi if a host has many child hosts. When the length of all child hostnames exceeds this number, a continuation link is displayed, so that, when followed all child hostnames are displayed.
+
+</p>
+
+
+
+
 
 
 <a name="statusmap_background_image"></a>
diff --git a/sample-config/cgi.cfg.in b/sample-config/cgi.cfg.in
index 1d2060c..51110e8 100644
--- a/sample-config/cgi.cfg.in
+++ b/sample-config/cgi.cfg.in
@@ -307,6 +307,15 @@ notes_url_target=_blank
 
 lock_author_names=1
 
+# PARENT / HOST DISPLAY LENGTH
+# These options prevent flooding the output of extinfo.cgi if a host has
+# many parent or child hosts. When the length of all parent/child hostnames
+# exceeds this number, a continuation link is displayed, so that, when followed
+# all parent/child hostnames are displayed.
+# Default: 200
+#
+# child_host_display_len=200
+# parent_host_display_len=200
 
 
 
-- 
1.6.0.6





More information about the Nagios-devel mailing list