[icinga-checkins] icinga.org: icinga-core/next: classic-ui: Added host/ service selection for commands, leaving out passive only checks on check reschedule in cmd.cgi #2697

git at icinga.org git at icinga.org
Mon Aug 20 10:30:56 CEST 2012


Module: icinga-core
Branch: next
Commit: 449580ef0628bebfd2ea5f23eb63d92eb0648c6e
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=449580ef0628bebfd2ea5f23eb63d92eb0648c6e

Author: Ricardo Bartels <ricardo at bitchbrothers.com>
Date:   Sat Aug 18 01:33:05 2012 +0200

classic-ui: Added host/service selection for commands, leaving out passive only checks on check reschedule in cmd.cgi #2697

refs: #2697

passive checks get disable for:
* CMD_SCHEDULE_HOST_CHECK
* CMD_DISABLE_HOST_CHECK
* CMD_SCHEDULE_SVC_CHECK
* CMD_DISABLE_SVC_CHECK

now you have a checkbox on every line when sending a command, where you can enable/disable
the host/service if you like to.

Enjoy!

---

 Changelog |    1 +
 cgi/cmd.c |   74 ++++++++++++++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 62 insertions(+), 13 deletions(-)

diff --git a/Changelog b/Changelog
index 1439850..0fbf5f8 100644
--- a/Changelog
+++ b/Changelog
@@ -41,6 +41,7 @@ ENHANCEMENTS
 * classic ui: Separate host_name/display_name and service_description/display_name in json output #2693 - RB
 * classic ui: Added date/time selection for all date/time input fields #2576 - RB
 * classic ui: Added 'All Problems' to 'Problems' group in menu #2645 - RB
+* classic ui: Added host/service selection for commands, leaving out passive only checks on check reschedule in cmd.cgi #2697 - RB
 
 * idoutils: do not pass host and port if not set in the config, letting mysql|pgsql drivers autoselect the socket #2698 - MF
 * idoutils: fix mismatched types for uint casts in bulkops (oracle) #2646 - TD
diff --git a/cgi/cmd.c b/cgi/cmd.c
index 52b2cb7..32f84b8 100644
--- a/cgi/cmd.c
+++ b/cgi/cmd.c
@@ -33,6 +33,7 @@
 #include "../include/objects.h"
 #include "../include/comments.h"
 #include "../include/downtime.h"
+#include "../include/statusdata.h"
 
 #include "../include/cgiutils.h"
 #include "../include/cgiauth.h"
@@ -330,6 +331,17 @@ int main(void) {
 		return ERROR;
 	}
 
+	/* read all status data */
+	result = read_all_status_data(get_cgi_config_location(), READ_ALL_STATUS_DATA);
+	if (result == ERROR && daemon_check == TRUE) {
+		document_header(CGI_ID, FALSE, "Error");
+		print_error(NULL, ERROR_CGI_STATUS_DATA);
+		document_footer(CGI_ID);
+		free_memory();
+		return ERROR;
+	}
+
+
 	document_header(CGI_ID, TRUE, "External Command Interface");
 
 	/* get authentication information */
@@ -790,22 +802,54 @@ int process_cgivars(void) {
 }
 
 void print_object_list(int list_type) {
+	hoststatus *temp_hoststatus = NULL;
+	servicestatus *temp_servicestatus = NULL;
 	int x = 0;
 	int row_color = 0;
+	int host_passive = FALSE;
+	int service_passive = FALSE;
 
-	printf("<tr><td COLSPAN=\"2\"> </td></tr>\n");
-	printf("<tr CLASS=\"sectionHeader\"><td COLSPAN=\"2\" >Affected Objects</td></tr>\n");
+
+	printf("<tr><td colspan=\"2\"> </td></tr>\n");
+	printf("<tr class=\"sectionHeader\"><td colspan=\"2\" >Affected Objects</td></tr>\n");
+
+	printf("<tr><td colspan=\"2\"><TABLE cellspacing='2' cellpadding='0' border='0' width='100%%'>\n");
 
 	if (list_type == PRINT_SERVICE_LIST)
-		printf("<tr class=\"objectDescription\"><td width=\"50%%\">Host</td><td width=\"50%%\">Service</td></tr>\n");
+		printf("<tr class=\"objectDescription\"><td width=\"46%%\">Host</td><td width=\"46%%\">Service</td><td width='16'></td></tr>\n");
+	else if (list_type == PRINT_HOST_LIST)
+		printf("<tr class=\"objectDescription\"><td colspan=\"2\" width=\"96%%\">Hosts</td><td width='16'></td></tr>\n");
 	else
-		printf("<tr><td COLSPAN=\"2\"> </td></tr>\n");
+		printf("<tr><td colspan=\"3\"> </td></tr>\n");
 
 	for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
 
 		if (list_type == PRINT_HOST_LIST || list_type == PRINT_SERVICE_LIST) {
+			host_passive = FALSE;
+			service_passive = FALSE;
+
 			if (commands[x].host_name == NULL)
 				continue;
+
+			if (strlen(commands[x].host_name) != 0 && (
+				command_type == CMD_SCHEDULE_HOST_CHECK ||
+				command_type == CMD_DISABLE_HOST_CHECK ||
+				command_type == CMD_SCHEDULE_SVC_CHECK ||
+				command_type == CMD_DISABLE_SVC_CHECK )) {
+				if((temp_hoststatus = find_hoststatus(commands[x].host_name)) != NULL) {
+					if (temp_hoststatus->checks_enabled == FALSE)
+						host_passive = TRUE;
+				}
+
+
+				if (list_type == PRINT_SERVICE_LIST && strlen(commands[x].description) != 0 ) {
+					if((temp_servicestatus = find_servicestatus(commands[x].host_name, commands[x].description)) != NULL) {
+						if (temp_servicestatus->checks_enabled == FALSE)
+							service_passive = TRUE;
+					}
+				}
+			}
+
 		} else {
 			if (multi_ids[x] == FALSE)
 				continue;
@@ -817,10 +861,8 @@ void print_object_list(int list_type) {
 		if (list_type == PRINT_SERVICE_LIST) {
 			/* hostname and service description are present */
 			if (strlen(commands[x].host_name) != 0  && strlen(commands[x].description) != 0) {
-				printf(">%s</td>", escape_string(commands[x].host_name));
-				/* we can use "escape_string" only twice in one line */
-				printf("<td><INPUT TYPE='HIDDEN' NAME='hostservice' VALUE='%s^%s'>", escape_string(commands[x].host_name), escape_string(commands[x].description));
-				printf("%s</td></tr>\n", escape_string(commands[x].description));
+				printf(">%s</td><td>%s</td>", escape_string(commands[x].host_name), escape_string(commands[x].description));
+				printf("<td align='center'><input type='checkbox' name='hostservice' value='%s^%s' %s></td></tr>\n", escape_string(commands[x].host_name), escape_string(commands[x].description), (service_passive == FALSE) ? "checked" : "");
 			} else {
 				/* if hostname is empty print inputbox instead */
 				if (!strcmp(commands[x].host_name, ""))
@@ -829,16 +871,20 @@ void print_object_list(int list_type) {
 					printf("><INPUT TYPE='HIDDEN' NAME='host' VALUE='%s'>%s</td>", escape_string(commands[x].host_name), escape_string(commands[x].host_name));
 				/* if service description is empty print inputbox instead */
 				if (!strcmp(commands[x].description, ""))
-					printf("<td><INPUT TYPE='TEXT' NAME='service' SIZE=30></td></tr>\n");
+					printf("<td><INPUT TYPE='TEXT' NAME='service' SIZE=30></td>");
 				else
-					printf("<td><INPUT TYPE='HIDDEN' NAME='service' VALUE='%s'>%s</td></tr>\n", escape_string(commands[x].description), escape_string(commands[x].description));
+					printf("<td><INPUT TYPE='HIDDEN' NAME='service' VALUE='%s'>%s</td>", escape_string(commands[x].description), escape_string(commands[x].description));
+
+				printf("<td></td></tr>\n");
 			}
 		} else if (list_type == PRINT_HOST_LIST) {
 			/* if hostname is empty print inputbox instead */
 			if (!strcmp(commands[x].host_name, ""))
-				printf(" style=\"font-weight:bold;\">Host:</td><td><INPUT TYPE='TEXT' NAME='host' SIZE=30></td></tr>\n");
-			else
-				printf(" style=\"font-weight:bold;\">Host:</td><td><INPUT TYPE='HIDDEN' NAME='host' VALUE='%s'>%s</td></tr>\n", escape_string(commands[x].host_name), escape_string(commands[x].host_name));
+				printf(" style=\"font-weight:bold;\">Host:</td><td><INPUT TYPE='TEXT' NAME='host' SIZE=30></td><td></td></tr>\n");
+			else {
+				printf(" style=\"font-weight:bold;\">Host:</td><td>%s</td>", escape_string(commands[x].host_name));
+				printf("<td align='center'><input type='checkbox' name='host' value='%s' %s></td></tr>\n", escape_string(commands[x].host_name), (host_passive == FALSE) ? "checked" : "");
+			}
 		} else if (list_type == PRINT_COMMENT_LIST) {
 			printf(" style=\"font-weight:bold;\">Comment ID:</td><td><INPUT TYPE='HIDDEN' NAME='com_id' VALUE='%lu'>%lu</td></tr>\n", multi_ids[x], multi_ids[x]);
 		} else if (list_type == PRINT_DOWNTIME_LIST) {
@@ -846,6 +892,8 @@ void print_object_list(int list_type) {
 		}
 	}
 
+	printf("</td><tr></table>\n");
+
 	return;
 }
 





More information about the icinga-checkins mailing list