Page 1 of 1

[Nagios-devel] [PATCH] Let the gui use resource macros

Posted: Tue Mar 31, 2009 12:19 pm
by Guest
This is a multi-part message in MIME format.
--------------010409040908010205040701
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Make resource ($USERx$) macros available in the GUI

The patch is rather simple. We just let the read_main_config_file()
function in cgi/cgiutils.c grok the "resource_file" variable and
move the function read_resource_file() from base/config.c to
common/macros.c so that it's linked into the cgi's as well as the
core daemon.

Signed-off-by: Andreas Ericsson

The attached patch is also available in the gui/resource-macros branch
of git://git.op5.org/nagios.git. To merge it, use the following command:

git pull git://git.op5.org/nagios.git gui/resource-macros

A customer requested this functionality, and since it was so simple
to arrange it was a nobrainer really.

Also attached as a /usr/bin/patch compatible unified diff that applies
cleanly on top of latest cvs head.

--
Andreas Ericsson [email protected]
OP5 AB www.op5.se
Tel: +46 8-230225 Fax: +46 8-230231

Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.

--------------010409040908010205040701
Content-Type: text/x-patch;
name="gui-resource-macros.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="gui-resource-macros.patch"

diff --git a/base/config.c b/base/config.c
index 537dadd..4de7b56 100644
--- a/base/config.c
+++ b/base/config.c
@@ -1388,99 +1388,6 @@ int read_main_config_file(char *main_config_file){



-/* processes macros in resource file */
-int read_resource_file(char *resource_file){
- char *input=NULL;
- char *variable=NULL;
- char *value=NULL;
- char *temp_ptr=NULL;
- mmapfile *thefile=NULL;
- int current_line=1;
- int error=FALSE;
- int user_index=0;
-
- if((thefile=mmap_fopen(resource_file))==NULL){
- logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Cannot open resource file '%s' for reading!",resource_file);
- return ERROR;
- }
-
- /* process all lines in the resource file */
- while(1){
-
- /* free memory */
- my_free(input);
- my_free(variable);
- my_free(value);
-
- /* read the next line */
- if((input=mmap_fgets_multiline(thefile))==NULL)
- break;
-
- current_line=thefile->current_line;
-
- /* skip blank lines and comments */
- if(input[0]=='#' || input[0]=='\x0' || input[0]=='\n' || input[0]=='\r')
- continue;
-
- strip(input);
-
- /* get the variable name */
- if((temp_ptr=my_strtok(input,"="))==NULL){
- logit(NSLOG_CONFIG_ERROR,TRUE,"Error: NULL variable - Line %d of resource file '%s'",current_line,resource_file);
- error=TRUE;
- break;
- }
- if((variable=(char *)strdup(temp_ptr))==NULL){
- error=TRUE;
- break;
- }
-
- /* get the value */
- if((temp_ptr=my_strtok(NULL,"\n"))==NULL){
- logit(NSLOG_CONFIG_ERROR,TRUE,"Error: NULL variable value - Line %d of resource file '%s'",current_line,resource_file);
- error=TRUE;
- break;
- }
- if((value=(char *)strdup(temp_ptr))==NULL){
- error=TRUE;
- break;
- }
-
- /* what should we do with the variable/value pair? */
-
- /* check for macro declarations */
- if(variable[0]=='$' && variable[strlen(variable)-1]=='$'){
-
- /* $USERx$ macro declarations */
- if(strstr(variable,"$USER")==variable && strlen(variable)>5){
- user_index=atoi(variable+5)-1;
- if(user_index>=0 && user_index<MAX_USER_MACROS){
- my_free(macro_user[user_index]);
- macro_user[user_index]=(char *)strdup(value);
- }
- }
- }
- }
-
- /* free leftover memory and close the file */
- my_free(input);
- mmap_fclose(thefile);
-
- /* free memory */
- my_free(variable);
- my_free(value);
-
- if(error==TRUE)
- return ERROR;
-
- return OK;
- }
-
-
-
-
-
-
/****************************************************************/
/**************** CONFIG VERIFICATION FUNCTIONS *****************/
/****************************************************************/


...[email truncated]...


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