[icinga-checkins] icinga.org: icinga-core/r1.6: classic ui: fixed json output for comments and downtimes in extinfo. cgi sometimes invalid #2343

git at icinga.org git at icinga.org
Sat Apr 28 11:11:39 CEST 2012


Module: icinga-core
Branch: r1.6
Commit: 11ae7d32fde14a84afc659fe9ae0d7758b7ec0c7
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=11ae7d32fde14a84afc659fe9ae0d7758b7ec0c7

Author: Ricardo Bartels <ricardo at bitchbrothers.com>
Date:   Fri Feb 24 15:00:31 2012 +0100

classic ui: fixed json output for comments and downtimes in extinfo.cgi sometimes invalid #2343

refs: #2343

* changes array names in json output of extinfo.c
        comments  -> host_comments  / service_comments
        downtimes -> host_downtimes / service_downtimes

Conflicts:

	Changelog
	Changelog_json

---

 Changelog          |    1 +
 Changelog_json     |    3 +++
 cgi/extinfo.c      |   50 ++++++++++++++++++++++++++------------------------
 include/cgiutils.h |    2 +-
 4 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/Changelog b/Changelog
index 6c18850..177e50d 100644
--- a/Changelog
+++ b/Changelog
@@ -15,6 +15,7 @@ FIXES
 * core: add trigger_time to downtimes to allow calculating of flexible downtimes endtime #2537 - MF
 
 * classic ui: fixed invalid json output for tac.cgi #2160
+* classic ui: fixed json output for comments and downtimes in extinfo.cgi sometimes invalid #2343
 
 CHANGES
 
diff --git a/Changelog_json b/Changelog_json
index 6ac2be9..abb99eb 100644
--- a/Changelog_json
+++ b/Changelog_json
@@ -4,6 +4,9 @@ Classic-UI JSON Change Log
 
 1.6.2 
 * add is_in_effect and trigger_time to downtime output #2538
+- array names changed!!!! #2343
+	comments  -> host_comments  / service_comments
+	downtimes -> host_downtimes / service_downtimes
 
 1.6.0 - only values added, no existing values changed
 * add more info of (ack, downtime, ... ) status to json export in status.cgi (ivo) #1988
diff --git a/cgi/extinfo.c b/cgi/extinfo.c
index a6172dc..fed3393 100644
--- a/cgi/extinfo.c
+++ b/cgi/extinfo.c
@@ -759,6 +759,8 @@ int main(void) {
 		else {
 			if (content_type == CSV_CONTENT || content_type == JSON_CONTENT) {
 				show_comments(HOST_COMMENT);
+				if (content_type == JSON_CONTENT)
+					printf(",\n");
 				show_comments(SERVICE_COMMENT);
 			} else {
 				printf("<BR />\n");
@@ -776,6 +778,8 @@ int main(void) {
 		else {
 			if (content_type == CSV_CONTENT || content_type == JSON_CONTENT) {
 				show_downtime(HOST_DOWNTIME);
+				if (content_type == JSON_CONTENT)
+					printf(",\n");
 				show_downtime(SERVICE_DOWNTIME);
 			} else {
 				printf("<BR />\n");
@@ -1453,13 +1457,14 @@ void show_host_info(void) {
 			printf("\"event_handler_enabled\": %s,\n", (temp_hoststatus->event_handler_enabled == TRUE) ? "true" : "false");
 			printf("\"flap_detection_enabled\": %s\n", (temp_hoststatus->flap_detection_enabled == TRUE) ? "true" : "false");
 			if (is_authorized_for_read_only(&current_authdata) == FALSE) {
+
 				/* display comments */
-				printf(", \"comments\": [\n");
+				printf(",\n");
 				show_comments(HOST_COMMENT);
-				printf("], \"downtimes\": [\n");
+
 				/* display downtimes */
+				printf(",\n");
 				show_downtime(HOST_DOWNTIME);
-				printf("]\n");
 			}
 			printf(" }\n");
 		}
@@ -1867,13 +1872,14 @@ void show_service_info(void) {
 			printf("\"event_handler_enabled\": %s,\n", (temp_svcstatus->event_handler_enabled == TRUE) ? "true" : "false");
 			printf("\"flap_detection_enabled\": %s\n", (temp_svcstatus->flap_detection_enabled == TRUE) ? "true" : "false");
 			if (is_authorized_for_read_only(&current_authdata) == FALSE) {
+
 				/* display comments */
-				printf(", \"comments\": [\n");
+				printf(",\n");
 				show_comments(SERVICE_COMMENT);
-				printf("], \"downtimes\": [\n");
+
 				/* display downtimes */
+				printf(",\n");
 				show_downtime(SERVICE_DOWNTIME);
-				printf("]\n");
 			}
 			printf(" }\n");
 		}
@@ -2869,15 +2875,14 @@ void show_comments(int type) {
 	int json_start = TRUE;
 
 	/* define colspan */
-	if (display_type == DISPLAY_COMMENTS) {
+	if (display_type == DISPLAY_COMMENTS)
 		colspan = (type != SERVICE_COMMENT) ? 9 : 10;
-	}
 
 	if (content_type == JSON_CONTENT) {
-		if (display_type == DISPLAY_COMMENTS && type == HOST_COMMENT)
-			printf("\"comments\": [\n");
-		if (display_type == DISPLAY_COMMENTS && type == SERVICE_COMMENT)
-			json_start = FALSE;
+		if (type == HOST_COMMENT)
+			printf("\"host_comments\": [\n");
+		if (type == SERVICE_COMMENT)
+			printf("\"service_comments\": [\n");
 	} else if (content_type == CSV_CONTENT) {
 		/* csv header */
 		if (display_type == DISPLAY_COMMENTS && type == HOST_COMMENT) {
@@ -3001,7 +3006,6 @@ void show_comments(int type) {
 				printf("\"host_name\": \"%s\", ", json_encode(temp_host->name));
 				if (type == SERVICE_COMMENT)
 					printf("\"service_description\": \"%s\", ", json_encode(temp_service->description));
-				printf("\"comment_type\": \"%s\", ", (type == HOST_COMMENT) ? "HOST" : "SERVICE");
 			}
 			printf("\"entry_time\": \"%s\", ", date_time);
 			printf("\"author\": \"%s\", ", json_encode(temp_comment->author));
@@ -3057,8 +3061,8 @@ void show_comments(int type) {
 		}
 		printf("</TABLE></FORM></DIV>\n");
 	}
-	if (content_type == JSON_CONTENT && display_type == DISPLAY_COMMENTS && type == SERVICE_COMMENT)
-		printf("\n]\n");
+	if (content_type == JSON_CONTENT)
+		printf("]");
 
 	return;
 }
@@ -3080,15 +3084,14 @@ void show_downtime(int type) {
 	int json_start = TRUE;
 
 	/* define colspan */
-	if (display_type == DISPLAY_DOWNTIME) {
+	if (display_type == DISPLAY_DOWNTIME)
 		colspan = (type != SERVICE_DOWNTIME) ? 11 : 12;
-	}
 
 	if (content_type == JSON_CONTENT) {
-		if (display_type == DISPLAY_DOWNTIME && type == HOST_DOWNTIME)
-			printf("\"downtimes\": [\n");
-		if (display_type == DISPLAY_DOWNTIME && type == SERVICE_DOWNTIME)
-			json_start = FALSE;
+		if (type == HOST_DOWNTIME)
+			printf("\"host_downtimes\": [\n");
+		if (type == SERVICE_DOWNTIME)
+			printf("\"service_downtimes\": [\n");
 	} else if (content_type == CSV_CONTENT) {
 		/* csv header */
 		if (display_type == DISPLAY_DOWNTIME && type == HOST_DOWNTIME) {
@@ -3196,7 +3199,6 @@ void show_downtime(int type) {
 				printf("\"host_name\": \"%s\", ", json_encode(temp_host->name));
 				if (type == SERVICE_DOWNTIME)
 					printf("\"service_description\": \"%s\", ", json_encode(temp_service->description));
-				printf("\"downtime_type\": \"%s\", ", (type == HOST_DOWNTIME) ? "HOST" : "SERVICE");
 			}
 		} else if (content_type == CSV_CONTENT) {
 			if (display_type == DISPLAY_DOWNTIME) {
@@ -3321,8 +3323,8 @@ void show_downtime(int type) {
 		}
 		printf("</TABLE></FORM></DIV>\n");
 	}
-	if (content_type == JSON_CONTENT && display_type == DISPLAY_DOWNTIME && type == SERVICE_DOWNTIME)
-		printf("\n]\n");
+	if (content_type == JSON_CONTENT)
+		printf("]");
 
 	return;
 }
diff --git a/include/cgiutils.h b/include/cgiutils.h
index b4082e5..b32a847 100644
--- a/include/cgiutils.h
+++ b/include/cgiutils.h
@@ -524,7 +524,7 @@ extern "C" {
 
 /************************** JSON OUTPUT VERSION ************************/
 
-#define JSON_OUTPUT_VERSION "1.6.0"
+#define JSON_OUTPUT_VERSION "1.7.0"
 
 
 /************************** BUFFER  ***************************************/





More information about the icinga-checkins mailing list