[icinga-checkins] icinga.org: icinga-core/next: fix faulty macro cleaning, replacing spaces with pluses where they shouldn't be cleaned (refs #3397)

git at icinga.org git at icinga.org
Wed Oct 24 23:57:58 CEST 2012


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

Author: Michael Friedrich <michael.friedrich at gmail.com>
Date:   Wed Oct 24 23:52:15 2012 +0200

fix faulty macro cleaning, replacing spaces with pluses where they shouldn't be cleaned (refs #3397)

leftover from the macro speedup rewrite - the 0 initialize was missing,
and under random circumstances the previous value was taken, making it
impossible to determine which macros to clean, and which not (as this is
now computed when initializing the macros, and not when grabbing their
values).

added a testcase as well.

---

 common/macros.c    |   42 ++++++++++++++++++++++++-----
 tests/etc/3397.cfg |   73 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 107 insertions(+), 8 deletions(-)

diff --git a/common/macros.c b/common/macros.c
index 29c0737..4463ab2 100644
--- a/common/macros.c
+++ b/common/macros.c
@@ -204,7 +204,7 @@ int process_macros_r(icinga_macros *mac, char *input_buffer, char **output_buffe
 
 			/* an error occurred - we couldn't parse the macro, so continue on */
 			if (result == ERROR) {
-				log_debug_info(DEBUGL_MACROS, 0, " WARNING: An error occurred processing macro '%s'!\n", temp_buffer);
+				logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning: An error occurred processing macro '%s'!\n", temp_buffer);
 				if (free_macro == TRUE)
 					my_free(selected_macro);
 			}
@@ -2700,13 +2700,39 @@ int init_macros(void) {
 		macro_keys[x].code = x;
 		macro_keys[x].name = macro_x_names[x];
 
-		/* host/service output/perfdata and author/comment macros should get cleaned */
-		if ((x >= 16 && x <= 19) || (x >= 49 && x <= 52) || (x >= 99 && x <= 100) || (x >= 124 && x <= 127)) {
-			macro_keys[x].clean_options = (STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS);
-		}
-		/* url macros should get cleaned */
-		if ((x >= 125 && x <= 126) || (x >= 128 && x <= 129) || (x >= 77 && x <= 78) || (x >= 74 && x <= 75)) {
-			macro_keys[x].clean_options = URL_ENCODE_MACRO_CHARS;
+		switch (x) {
+			/* host/service output/perfdata and author/comment macros should get cleaned */
+			case MACRO_HOSTOUTPUT:
+			case MACRO_SERVICEOUTPUT:
+			case MACRO_HOSTPERFDATA:
+			case MACRO_SERVICEPERFDATA:
+			case MACRO_HOSTACKAUTHOR:
+			case MACRO_HOSTACKCOMMENT:
+			case MACRO_SERVICEACKAUTHOR:
+			case MACRO_SERVICEACKCOMMENT:
+			case MACRO_LONGHOSTOUTPUT:
+			case MACRO_LONGSERVICEOUTPUT:
+			case MACRO_HOSTGROUPNOTES:
+			case MACRO_SERVICEGROUPNOTES:
+				macro_keys[x].clean_options = (STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS);
+				break;
+
+			/* url macros should get cleaned */
+			case MACRO_HOSTACTIONURL:
+			case MACRO_HOSTNOTESURL:
+			case MACRO_SERVICEACTIONURL:
+			case MACRO_SERVICENOTESURL:
+			case MACRO_HOSTGROUPNOTESURL:
+			case MACRO_HOSTGROUPACTIONURL:
+			case MACRO_SERVICEGROUPNOTESURL:
+			case MACRO_SERVICEGROUPACTIONURL:
+				macro_keys[x].clean_options = URL_ENCODE_MACRO_CHARS;
+				break;
+
+			/* by default, we do not clean anything */
+			default:
+				macro_keys[x].clean_options = 0;
+				break;
 		}
 	}
 
diff --git a/tests/etc/3397.cfg b/tests/etc/3397.cfg
new file mode 100644
index 0000000..bf68c33
--- /dev/null
+++ b/tests/etc/3397.cfg
@@ -0,0 +1,73 @@
+#############################################################################################
+# ICINGA TEST CONFIG BY ISSUES
+# (c) 2009-2012 Icinga Development Team and Community Contributors
+#
+# #3397
+# faulty macro cleaning, replacing spaces with pluses where they shouldn't be cleaned
+#############################################################################################
+
+define command {
+        command_name    		3397check_macro_clean
+        command_line    		/bin/echo "svc: $SERVICEDESC$ dur: $SERVICEDURATION$"
+}
+
+define host{
+        name                            3397linux-server
+        use                             generic-host
+        check_period                    24x7
+        check_interval                  5
+        retry_interval                  1
+        max_check_attempts              10
+        check_command                   testconfig-check-host-alive
+        notification_period             workhours
+        notification_interval           120
+        notification_options            d,u,r
+        contact_groups                  testconfig-group-admin
+	register                        0
+}
+
+
+define host{
+        use                     	3397linux-server
+        host_name               	3397localhost
+        alias                   	3397localhost
+        address                 	127.0.0.1
+        address6                	::1
+        }
+
+
+define  service {
+        name                            3397generic-macro-check
+        is_volatile                     0
+	check_command			3397check_macro_clean
+        max_check_attempts              2
+        normal_check_interval           2
+        retry_check_interval            1
+        active_checks_enabled           1
+        passive_checks_enabled          1
+        check_period                    24x7
+        parallelize_check               1
+        obsess_over_service             1
+        check_freshness                 0
+        event_handler_enabled           1
+        flap_detection_enabled          1
+        process_perf_data               1
+        retain_status_information       1
+        retain_nonstatus_information    1
+        contact_groups                  abc
+        notification_interval           120
+        notification_period             24x7
+        notification_options            w,u,c,r,f
+        notifications_enabled           1
+        register                        0
+}
+
+define  service {
+        use                             3397generic-macro-check
+        host_name                       3397localhost
+        contact_groups                 	testconfig-group-admin
+        service_description             3397 macro clean
+}
+
+
+





More information about the icinga-checkins mailing list