Nagios Core Version 3.5.1
So I have done some modifying of the status.c file in the past and some other small stuff recently. For example, I included the LONGSERVICEOUTPUT macro in the Status Information column of Nagios' Services page of the Web GUI. I did this because I had a few service checks that I wanted to have their 2nd+ lines included as well... Now I wanted to try something different and was hoping someone could give me a hand.
What I want to do now is see if I can get access to the User-defined macros stored in the resource.cfg file inside the status.c code. We do NOT use any passwords or any sensitive data inside this file so I wouldn't be worried about a password getting out there or anything like that. Would this be something that would be possible without a great deal of work? I have done C++ programming in the past and have kind of just finagled my way through using C to modify the .c/.cgi files.
I was wondering if there is a way to simply include access to this file so I could capture the $USER#$ macros.
Looking through the other .c files I can see these files below using the macros in resource.cfg, but I couldn't figure out how to include it in status.c and USE it within the code:
*I found this stuff below inside the other .c files, but I'm not sure how I could utilize it in status.c?
### FROM: include/nagios.h
Code: Select all
############################# Line 434 #############################
int read_resource_file(char *); /* processes macros in resource file */
Code: Select all
############################# Starting at Line 328 #############################
if(!strcmp(variable, "resource_file")) {
/* save the macro */
my_free(mac->x[MACRO_RESOURCEFILE]);
mac->x[MACRO_RESOURCEFILE] = (char *)strdup(value);
/* process the resource file */
read_resource_file(value);
}
################################ Lines 1418 to 1503 ################################
/* 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;
}
Any thoughts or suggestions at all would be greatly appreciated!
Thanks in Advance,
Matt