Undefined custom macros remain unparsed

matthias eble matthias.eble at mailing.kaufland-informationssysteme.com
Wed Apr 8 16:54:33 CEST 2009


Hi List,

currently Nagios doesn't touch macro strings ($...$) if they are
undefined. Neither custom nor for default macros get interpreted so that
the original $...$ string remains the same.
 
To me $_HOSTUNDEFINEDMACRO$ should evaluate to an empty string rather
than being left untouched. Especially when used in commands, the
$_HOSTUNDEFINEDMACRO part gets interpreted by the shell (usually empty)
and the trailing $ is displayed plainly.

Following patch is made against 3.0.5 but applies cleanly to latest git
snapshot from git.nagiosprojects.org. It changes the behavior for custom
macros.

Does anyone see any reasons why this should not be changed?

Matthias

--- nagios-3.0.5/common/macros.c	2008-06-23 22:47:47.000000000 +0200
+++ nagios-3.0.5/common/macros.c.new	2009-04-08 15:00:17.000000000 +0200
@@ -2374,8 +2374,9 @@
 int grab_custom_object_macro(char *macro_name, customvariablesmember
*vars, char **output){
 	customvariablesmember *temp_customvariablesmember=NULL;
 	int result=ERROR;
+	int found=0;
 
-	if(macro_name==NULL || vars==NULL || output==NULL)
+	if(macro_name==NULL || output==NULL) 
 		return ERROR;
 
 	/* get the custom variable */
@@ -2385,13 +2386,18 @@
 			continue;
 
 		if(!strcmp(macro_name,temp_customvariablesmember->variable_name)){
-			if(temp_customvariablesmember->variable_value)
+			if(temp_customvariablesmember->variable_value){
 				*output=(char *)strdup(temp_customvariablesmember->variable_value);
+				found = 1;
+			}
 			result=OK;
 			break;
 			}
 	        }
-
+	if(!found) {
+		*output=(char *)strdup("");
+		result=OK;
+	}
 	return result;
 	}
 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: macro.patch
Type: text/x-patch
Size: 937 bytes
Desc: not available
URL: <https://www.monitoring-lists.org/archive/developers/attachments/20090408/fd3d132a/attachment.bin>
-------------- next part --------------
------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
-------------- next part --------------
_______________________________________________
Nagios-devel mailing list
Nagios-devel at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-devel


More information about the Developers mailing list