Page 1 of 1

[Nagios-devel] Undefined custom macros remain unparsed

Posted: Wed Apr 08, 2009 2:27 pm
by Guest

--=-L4FgmQX80nAxloH1CQI0
Content-Transfer-Encoding: 7bit
Content-Type: text/plain

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;
}



--=-L4FgmQX80nAxloH1CQI0
Content-Transfer-Encoding: 7bit
Content-Type: text/x-patch; name=macro.patch; charset=UTF-8
Content-Disposition: attachment; filename=macro.patch

--- 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;
}


--=-L4FgmQX80nAxloH1CQI0--






This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]