[icinga-checkins] icinga.org: icinga-core/dev/ido: idoutils: fix long output data causes wrong data in database refs #2342

git at icinga.org git at icinga.org
Thu Jan 10 20:07:29 CET 2013


Module: icinga-core
Branch: dev/ido
Commit: 00aebd0fd6c2c067b7f8ddd4ac45e94ae50abfa7
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=00aebd0fd6c2c067b7f8ddd4ac45e94ae50abfa7

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Wed Jan  2 20:55:51 2013 +0100

idoutils: fix long output data causes wrong data in database refs #2342

well, well, well. the original fix for truncating the data for mysql
output was a good idea either way. but the root cause for the data
irritation itsself did happen sooner.

ido2db just treats the data it gets in a sequential way. from within the
debug logs remarked in #2342 it's easy to see that the data is truncated
the wrong way, leaving out essential protocol (idomod->ido2db)
information which then causes wrong data insert/update queries in
ido2db.

idomod has a funny method of handling data truncation: first, it creates
a string containing all the protocol information, and cuts that to
IDOMOD_MAX_BUFLEN if too large. the protocol information in the end gets
lost, and so does the data on the other side.

fix for now is to limit long_output/perf_data in advance.

---

 module/idoutils/include/idomod.h |    3 +-
 module/idoutils/src/idomod.c     |   54 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 1 deletions(-)

diff --git a/module/idoutils/include/idomod.h b/module/idoutils/include/idomod.h
index e59ba6d..07cf1e0 100644
--- a/module/idoutils/include/idomod.h
+++ b/module/idoutils/include/idomod.h
@@ -14,7 +14,8 @@
 /* this is needed for access to daemon's internal data */
 #define NSCORE 1
 
-#define IDOMOD_MAX_BUFLEN   49152
+#define IDOMOD_MAX_BUFLEN   				49152
+#define IDOMOD_MAX_TEXT_LEN				32768
 
 /************** structures *******************/
 
diff --git a/module/idoutils/src/idomod.c b/module/idoutils/src/idomod.c
index 30bd6d1..0cee33d 100644
--- a/module/idoutils/src/idomod.c
+++ b/module/idoutils/src/idomod.c
@@ -1800,6 +1800,18 @@ int idomod_broker_data(int event_type, void *data) {
 		es[6] = ido_escape_buffer(scdata->long_output);
 		es[7] = ido_escape_buffer(scdata->perf_data);
 
+		if(es[6] != NULL) {
+			if(strlen(es[6]) > IDOMOD_MAX_TEXT_LEN) {
+				es[6][IDOMOD_MAX_TEXT_LEN] = '\0';
+			}
+		}
+
+		if(es[7] != NULL) {
+			if(strlen(es[7]) > IDOMOD_MAX_TEXT_LEN) {
+				es[7][IDOMOD_MAX_TEXT_LEN] = '\0';
+			}
+		}
+
 		snprintf(temp_buffer, IDOMOD_MAX_BUFLEN - 1
 		         , "\n%d:\n%d=%d\n%d=%d\n%d=%d\n%d=%ld.%ld\n%d=%s\n%d=%s\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%s\n%d=%s\n%d=%s\n%d=%ld.%ld\n%d=%ld.%ld\n%d=%d\n%d=%.5lf\n%d=%.5lf\n%d=%d\n%d=%s\n%d=%s\n%d=%s\n%d\n\n"
 		         , IDO_API_SERVICECHECKDATA
@@ -1878,6 +1890,18 @@ int idomod_broker_data(int event_type, void *data) {
 		es[5] = ido_escape_buffer(hcdata->long_output);
 		es[6] = ido_escape_buffer(hcdata->perf_data);
 
+		if(es[5] != NULL) {
+			if(strlen(es[5]) > IDOMOD_MAX_TEXT_LEN) {
+				es[5][IDOMOD_MAX_TEXT_LEN] = '\0';
+			}
+		}
+
+		if(es[6] != NULL) {
+			if(strlen(es[6]) > IDOMOD_MAX_TEXT_LEN) {
+				es[6][IDOMOD_MAX_TEXT_LEN] = '\0';
+			}
+		}
+
 		snprintf(temp_buffer, IDOMOD_MAX_BUFLEN - 1
 		         , "\n%d:\n%d=%d\n%d=%d\n%d=%d\n%d=%ld.%ld\n%d=%s\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%s\n%d=%s\n%d=%s\n%d=%ld.%ld\n%d=%ld.%ld\n%d=%d\n%d=%.5lf\n%d=%.5lf\n%d=%d\n%d=%s\n%d=%s\n%d=%s\n%d\n\n"
 		         , IDO_API_HOSTCHECKDATA
@@ -2182,6 +2206,18 @@ int idomod_broker_data(int event_type, void *data) {
 		es[5] = ido_escape_buffer(temp_host->host_check_command);
 		es[6] = ido_escape_buffer(temp_host->check_period);
 
+		if(es[2] != NULL) {
+			if(strlen(es[2]) > IDOMOD_MAX_TEXT_LEN) {
+				es[2][IDOMOD_MAX_TEXT_LEN] = '\0';
+			}
+		}
+
+		if(es[3] != NULL) {
+			if(strlen(es[3]) > IDOMOD_MAX_TEXT_LEN) {
+				es[3][IDOMOD_MAX_TEXT_LEN] = '\0';
+			}
+		}
+
 		retry_interval = temp_host->retry_interval;
 
 		snprintf(temp_buffer, IDOMOD_MAX_BUFLEN - 1
@@ -2341,6 +2377,18 @@ int idomod_broker_data(int event_type, void *data) {
 		es[6] = ido_escape_buffer(temp_service->service_check_command);
 		es[7] = ido_escape_buffer(temp_service->check_period);
 
+		if(es[3] != NULL) {
+			if(strlen(es[3]) > IDOMOD_MAX_TEXT_LEN) {
+				es[3][IDOMOD_MAX_TEXT_LEN] = '\0';
+			}
+		}
+
+		if(es[4] != NULL) {
+			if(strlen(es[4]) > IDOMOD_MAX_TEXT_LEN) {
+				es[4][IDOMOD_MAX_TEXT_LEN] = '\0';
+			}
+		}
+
 		snprintf(temp_buffer, IDOMOD_MAX_BUFLEN - 1
 		         , "\n%d:\n%d=%d\n%d=%d\n%d=%d\n%d=%ld.%ld\n%d=%s\n%d=%s\n%d=%s\n%d=%s\n%d=%s\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%lu\n%d=%lu\n%d=%d\n%d=%lu\n%d=%lu\n%d=%d\n%d=%lu\n%d=%lu\n%d=%lu\n%d=%lu\n%d=%d\n%d=%lu\n%d=%lu\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%.5lf\n%d=%.5lf\n%d=%.5lf\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%lu\n%d=%s\n%d=%s\n%d=%lf\n%d=%lf\n%d=%s\n"
 		         , IDO_API_SERVICESTATUSDATA
@@ -3042,6 +3090,12 @@ int idomod_broker_data(int event_type, void *data) {
 		es[2] = ido_escape_buffer(schangedata->output);
 		es[3] = ido_escape_buffer(schangedata->long_output);
 
+		if(es[3] != NULL) {
+			if(strlen(es[3]) > IDOMOD_MAX_TEXT_LEN) {
+				es[3][IDOMOD_MAX_TEXT_LEN] = '\0';
+			}
+		}
+
 		snprintf(temp_buffer, IDOMOD_MAX_BUFLEN - 1
 		         , "\n%d:\n%d=%d\n%d=%d\n%d=%d\n%d=%ld.%ld\n%d=%d\n%d=%s\n%d=%s\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%d\n%d=%s\n%d=%s\n%d\n\n"
 		         , IDO_API_STATECHANGEDATA





More information about the icinga-checkins mailing list