[Nagios-checkins] nagios/xdata xcddefault.c,1.11,1.12 xdddefault.c,1.9,1.10 xodtemplate.c,1.80,1.81
Nagios network monitoring software is enterprise server monitoring
Brought to you by:
egalstad,
sawolf-nagios
Update of /cvsroot/nagios/nagios/xdata In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30725/xdata Modified Files: xcddefault.c xdddefault.c xodtemplate.c xpddefault.c xpddefault.h xrddefault.c xsddefault.c Removed Files: xpdfile.c xpdfile.h Log Message: Unification of performance data processing methods Index: xpddefault.h =================================================================== RCS file: /cvsroot/nagios/nagios/xdata/xpddefault.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** xpddefault.h 15 Aug 2003 01:34:10 -0000 1.4 --- xpddefault.h 3 Sep 2004 00:10:48 -0000 1.5 *************** *** 3,8 **** * XPDDEFAULT.H - Include file for default performance data routines * ! * Copyright (c) 2001-2003 Ethan Galstad (na...@na...) ! * Last Modified: 08-14-2003 * * License: --- 3,8 ---- * XPDDEFAULT.H - Include file for default performance data routines * ! * Copyright (c) 2001-2004 Ethan Galstad (na...@na...) ! * Last Modified: 09-02-2004 * * License: *************** *** 33,34 **** --- 33,51 ---- int xpddefault_update_service_performance_data(service *); int xpddefault_update_host_performance_data(host *); + + int xpddefault_run_service_performance_data_command(service *); + int xpddefault_run_host_performance_data_command(host *); + + int xpddefault_update_service_performance_data_file(service *); + int xpddefault_update_host_performance_data_file(host *); + + int xpddefault_preprocess_file_templates(char *); + + int xpddefault_open_host_perfdata_file(void); + int xpddefault_open_service_perfdata_file(void); + int xpddefault_close_host_perfdata_file(void); + int xpddefault_close_service_perfdata_file(void); + + int xpddefault_process_host_perfdata_file(void); + int xpddefault_process_service_perfdata_file(void); + Index: xodtemplate.c =================================================================== RCS file: /cvsroot/nagios/nagios/xdata/xodtemplate.c,v retrieving revision 1.80 retrieving revision 1.81 diff -C2 -d -r1.80 -r1.81 *** xodtemplate.c 12 Aug 2004 22:59:41 -0000 1.80 --- xodtemplate.c 3 Sep 2004 00:10:47 -0000 1.81 *************** *** 4,8 **** * * Copyright (c) 2001-2004 Ethan Galstad (na...@na...) ! * Last Modified: 08-12-2004 * * Description: --- 4,8 ---- * * Copyright (c) 2001-2004 Ethan Galstad (na...@na...) ! * Last Modified: 08-13-2004 * * Description: *************** *** 73,76 **** --- 73,77 ---- extern int use_regexp_matches; extern int use_true_regexp_matching; + extern char *macro_x[MACRO_X_COUNT]; #endif *************** *** 118,122 **** /* get variables from main config file */ xodtemplate_grab_config_info(main_config_file); ! /* open the main config file for reading (we need to find all the config files to read) */ fp=fopen(main_config_file,"r"); --- 119,123 ---- /* get variables from main config file */ xodtemplate_grab_config_info(main_config_file); ! /* open the main config file for reading (we need to find all the config files to read) */ fp=fopen(main_config_file,"r"); *************** *** 311,314 **** --- 312,323 ---- fclose(fp); + #ifdef NSCORE + /* save the object cache file macro */ + if(macro_x[MACRO_OBJECTCACHEFILE]!=NULL) + free(macro_x[MACRO_OBJECTCACHEFILE]); + macro_x[MACRO_OBJECTCACHEFILE]=(char *)strdup(xodtemplate_cache_file); + if(macro_x[MACRO_OBJECTCACHEFILE]!=NULL) + strip(macro_x[MACRO_OBJECTCACHEFILE]); + #endif #ifdef DEBUGO --- xpdfile.h DELETED --- Index: xdddefault.c =================================================================== RCS file: /cvsroot/nagios/nagios/xdata/xdddefault.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** xdddefault.c 15 Aug 2003 01:34:10 -0000 1.9 --- xdddefault.c 3 Sep 2004 00:10:47 -0000 1.10 *************** *** 3,8 **** * XDDDEFAULT.C - Default scheduled downtime data routines for Nagios * ! * Copyright (c) 2001-2003 Ethan Galstad (na...@na...) ! * Last Modified: 08-14-2003 * * License: --- 3,8 ---- * XDDDEFAULT.C - Default scheduled downtime data routines for Nagios * ! * Copyright (c) 2001-2004 Ethan Galstad (na...@na...) ! * Last Modified: 08-13-2004 * * License: *************** *** 53,56 **** --- 53,57 ---- unsigned long current_downtime_id=0; extern scheduled_downtime *scheduled_downtime_list; + extern char *macro_x[MACRO_X_COUNT]; #endif *************** *** 138,141 **** --- 139,151 ---- return ERROR; + #ifdef NSCORE + /* save the downtime data file macro */ + if(macro_x[MACRO_DOWNTIMEDATAFILE]!=NULL) + free(macro_x[MACRO_DOWNTIMEDATAFILE]); + macro_x[MACRO_DOWNTIMEDATAFILE]=(char *)strdup(xdddefault_downtime_file); + if(macro_x[MACRO_DOWNTIMEDATAFILE]!=NULL) + strip(macro_x[MACRO_DOWNTIMEDATAFILE]); + #endif + return OK; } Index: xrddefault.c =================================================================== RCS file: /cvsroot/nagios/nagios/xdata/xrddefault.c,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** xrddefault.c 23 Nov 2003 01:36:04 -0000 1.21 --- xrddefault.c 3 Sep 2004 00:10:48 -0000 1.22 *************** *** 3,8 **** * XRDDEFAULT.C - Default external state retention routines for Nagios * ! * Copyright (c) 1999-2003 Ethan Galstad (na...@na...) ! * Last Modified: 11-22-2003 * * License: --- 3,8 ---- * XRDDEFAULT.C - Default external state retention routines for Nagios * ! * Copyright (c) 1999-2004 Ethan Galstad (na...@na...) ! * Last Modified: 08-13-2004 * * License: *************** *** 45,48 **** --- 45,50 ---- extern char *global_service_event_handler; + extern char *macro_x[MACRO_X_COUNT]; + extern int enable_notifications; extern int execute_service_checks; *************** *** 124,127 **** --- 126,136 ---- fclose(fp); + /* save the retention file macro */ + if(macro_x[MACRO_RETENTIONDATAFILE]!=NULL) + free(macro_x[MACRO_RETENTIONDATAFILE]); + macro_x[MACRO_RETENTIONDATAFILE]=(char *)strdup(xrddefault_retention_file); + if(macro_x[MACRO_RETENTIONDATAFILE]!=NULL) + strip(macro_x[MACRO_RETENTIONDATAFILE]); + return OK; } Index: xpddefault.c =================================================================== RCS file: /cvsroot/nagios/nagios/xdata/xpddefault.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** xpddefault.c 30 Jan 2004 03:35:57 -0000 1.10 --- xpddefault.c 3 Sep 2004 00:10:48 -0000 1.11 *************** *** 4,8 **** * * Copyright (c) 2000-2004 Ethan Galstad (na...@na...) ! * Last Modified: 01-29-2004 * * License: --- 4,8 ---- * * Copyright (c) 2000-2004 Ethan Galstad (na...@na...) ! * Last Modified: 09-02-2004 * * License: *************** *** 38,50 **** ! extern char *macro_host_state; ! extern char *macro_service_state; ! extern char *macro_state_type; ! int xpddefault_perfdata_timeout; ! char *xpddefault_host_perfdata_command=NULL; ! char *xpddefault_service_perfdata_command=NULL; --- 38,65 ---- + int xpddefault_perfdata_timeout; ! char *xpddefault_host_perfdata_command=NULL; ! char *xpddefault_service_perfdata_command=NULL; ! char *xpddefault_host_perfdata_file_template=NULL; ! char *xpddefault_service_perfdata_file_template=NULL; ! char *xpddefault_host_perfdata_file=NULL; ! char *xpddefault_service_perfdata_file=NULL; ! ! int xpddefault_host_perfdata_file_append=TRUE; ! int xpddefault_service_perfdata_file_append=TRUE; ! ! unsigned long xpddefault_host_perfdata_file_processing_interval=0L; ! unsigned long xpddefault_service_perfdata_file_processing_interval=0L; ! ! char *xpddefault_host_perfdata_file_processing_command; ! char *xpddefault_service_perfdata_file_processing_command; ! ! FILE *xpddefault_host_perfdata_fp=NULL; ! FILE *xpddefault_service_perfdata_fp=NULL; ! ! extern char *macro_x[MACRO_X_COUNT]; *************** *** 60,63 **** --- 75,81 ---- char temp_buffer[MAX_INPUT_BUFFER]; char *temp_command_name; + time_t current_time; + + time(¤t_time); /* default values */ *************** *** 65,72 **** --- 83,108 ---- xpddefault_host_perfdata_command=NULL; xpddefault_service_perfdata_command=NULL; + xpddefault_host_perfdata_file_template=NULL; + xpddefault_service_perfdata_file_template=NULL; + xpddefault_host_perfdata_file=NULL; + xpddefault_service_perfdata_file=NULL; + xpddefault_host_perfdata_fp=NULL; + xpddefault_service_perfdata_fp=NULL; + xpddefault_host_perfdata_file_processing_interval=0L; + xpddefault_service_perfdata_file_processing_interval=0L; + xpddefault_host_perfdata_file_processing_command=NULL; + xpddefault_service_perfdata_file_processing_command=NULL; /* grab config info from main config file */ xpddefault_grab_config_info(config_file); + /* process special chars in templates */ + xpddefault_preprocess_file_templates(xpddefault_host_perfdata_file_template); + xpddefault_preprocess_file_templates(xpddefault_service_perfdata_file_template); + + /* open the performance data files */ + xpddefault_open_host_perfdata_file(); + xpddefault_open_service_perfdata_file(); + /* verify that performance data commands are valid */ if(xpddefault_host_perfdata_command!=NULL){ *************** *** 102,105 **** --- 138,181 ---- } } + if(xpddefault_host_perfdata_file_processing_command!=NULL){ + + strncpy(temp_buffer,xpddefault_host_perfdata_file_processing_command,sizeof(temp_buffer)); + temp_buffer[sizeof(temp_buffer)-1]='\x0'; + + /* get the command name, leave any arguments behind */ + temp_command_name=my_strtok(temp_buffer,"!"); + + if(find_command(temp_command_name)==NULL){ + snprintf(buffer,sizeof(buffer),"Warning: Host performance file processing command '%s' was not found - host performance data file will not be processed!\n",temp_command_name); + buffer[sizeof(buffer)-1]='\x0'; + write_to_logs_and_console(buffer,NSLOG_RUNTIME_WARNING,TRUE); + free(xpddefault_host_perfdata_file_processing_command); + xpddefault_host_perfdata_file_processing_command=NULL; + } + } + if(xpddefault_service_perfdata_file_processing_command!=NULL){ + + strncpy(temp_buffer,xpddefault_service_perfdata_file_processing_command,sizeof(temp_buffer)); + temp_buffer[sizeof(temp_buffer)-1]='\x0'; + + /* get the command name, leave any arguments behind */ + temp_command_name=my_strtok(temp_buffer,"!"); + + if(find_command(temp_command_name)==NULL){ + snprintf(buffer,sizeof(buffer),"Warning: Service performance file processing command '%s' was not found - service performance data file will not be processed!\n",temp_command_name); + buffer[sizeof(buffer)-1]='\x0'; + write_to_logs_and_console(buffer,NSLOG_RUNTIME_WARNING,TRUE); + free(xpddefault_service_perfdata_file_processing_command); + xpddefault_service_perfdata_file_processing_command=NULL; + } + } + + /* periodically process the host perfdata file */ + if(xpddefault_host_perfdata_file_processing_interval>0 && xpddefault_host_perfdata_file_processing_command!=NULL) + schedule_new_event(EVENT_USER_FUNCTION,TRUE,current_time+xpddefault_host_perfdata_file_processing_interval,TRUE,xpddefault_host_perfdata_file_processing_interval,NULL,TRUE,xpddefault_process_host_perfdata_file,NULL); + + /* periodically process the service perfdata file */ + if(xpddefault_service_perfdata_file_processing_interval>0 && xpddefault_service_perfdata_file_processing_command!=NULL) + schedule_new_event(EVENT_USER_FUNCTION,TRUE,current_time+xpddefault_service_perfdata_file_processing_interval,TRUE,xpddefault_service_perfdata_file_processing_interval,NULL,TRUE,xpddefault_process_service_perfdata_file,NULL); return OK; *************** *** 157,161 **** strip(value); ! if(!strcmp(variable,"perfdata_timeout") || !strcmp(variable,"xpddefault_perfdata_timeout")){ strip(value); xpddefault_perfdata_timeout=atoi(value); --- 233,237 ---- strip(value); ! if(!strcmp(variable,"perfdata_timeout")){ strip(value); xpddefault_perfdata_timeout=atoi(value); *************** *** 166,193 **** } } - else if(!strcmp(variable,"host_perfdata_command") || !strcmp(variable,"xpddefault_host_perfdata_command")){ - xpddefault_host_perfdata_command=(char *)malloc(strlen(value)+1); - if(xpddefault_host_perfdata_command==NULL){ - error=TRUE; - break; - } ! strcpy(xpddefault_host_perfdata_command,value); ! strip(xpddefault_host_perfdata_command); } - else if(!strcmp(variable,"service_perfdata_command") || !strcmp(variable,"xpddefault_service_perfdata_command")){ - xpddefault_service_perfdata_command=(char *)malloc(strlen(value)+1); - if(xpddefault_service_perfdata_command==NULL){ - error=TRUE; - break; - } ! strcpy(xpddefault_service_perfdata_command,value); ! strip(xpddefault_service_perfdata_command); } } fclose(fp); return OK; } --- 242,307 ---- } } ! else if(!strcmp(variable,"host_perfdata_command")) ! xpddefault_host_perfdata_command=strdup(value); ! ! else if(!strcmp(variable,"service_perfdata_command")) ! xpddefault_service_perfdata_command=strdup(value); ! ! else if(!strcmp(variable,"host_perfdata_file_template")) ! xpddefault_host_perfdata_file_template=strdup(value); ! ! else if(!strcmp(variable,"service_perfdata_file_template")) ! xpddefault_service_perfdata_file_template=strdup(value); ! ! else if(!strcmp(variable,"host_perfdata_file")) ! xpddefault_host_perfdata_file=strdup(value); ! ! else if(!strcmp(variable,"service_perfdata_file")) ! xpddefault_service_perfdata_file=strdup(value); ! ! else if(!strcmp(variable,"host_perfdata_file_mode")){ ! if(!strstr(value,"w")) ! xpddefault_host_perfdata_file_append=FALSE; ! else ! xpddefault_host_perfdata_file_append=TRUE; } ! else if(!strcmp(variable,"service_perfdata_file_mode")){ ! if(!strstr(value,"w")) ! xpddefault_service_perfdata_file_append=FALSE; ! else ! xpddefault_service_perfdata_file_append=TRUE; } + + else if(!strcmp(variable,"host_perfdata_file_processing_interval")) + xpddefault_host_perfdata_file_processing_interval=strtoul(value,NULL,0); + + else if(!strcmp(variable,"service_perfdata_file_processing_interval")) + xpddefault_service_perfdata_file_processing_interval=strtoul(value,NULL,0); + + else if(!strcmp(variable,"host_perfdata_file_processing_command")) + xpddefault_host_perfdata_file_processing_command=strdup(value); + + else if(!strcmp(variable,"service_perfdata_file_processing_command")) + xpddefault_service_perfdata_file_processing_command=strdup(value); } fclose(fp); + /* save the host perf data file macro */ + if(macro_x[MACRO_HOSTPERFDATAFILE]!=NULL) + free(macro_x[MACRO_HOSTPERFDATAFILE]); + macro_x[MACRO_HOSTPERFDATAFILE]=(char *)strdup(xpddefault_host_perfdata_file); + if(macro_x[MACRO_HOSTPERFDATAFILE]!=NULL) + strip(macro_x[MACRO_HOSTPERFDATAFILE]); + + /* save the service perf data file macro */ + if(macro_x[MACRO_SERVICEPERFDATAFILE]!=NULL) + free(macro_x[MACRO_SERVICEPERFDATAFILE]); + macro_x[MACRO_SERVICEPERFDATAFILE]=(char *)strdup(xpddefault_service_perfdata_file); + if(macro_x[MACRO_SERVICEPERFDATAFILE]!=NULL) + strip(macro_x[MACRO_SERVICEPERFDATAFILE]); + return OK; } *************** *** 200,203 **** --- 314,327 ---- free(xpddefault_host_perfdata_command); free(xpddefault_service_perfdata_command); + free(xpddefault_host_perfdata_file_template); + free(xpddefault_service_perfdata_file_template); + free(xpddefault_host_perfdata_file); + free(xpddefault_service_perfdata_file); + free(xpddefault_host_perfdata_file_processing_command); + free(xpddefault_service_perfdata_file_processing_command); + + /* close the files */ + xpddefault_close_host_perfdata_file(); + xpddefault_close_service_perfdata_file(); return OK; *************** *** 214,217 **** --- 338,374 ---- /* updates service performance data */ int xpddefault_update_service_performance_data(service *svc){ + + /* run the performance data command */ + xpddefault_run_service_performance_data_command(svc); + + /* update the performance data file */ + xpddefault_update_service_performance_data_file(svc); + + return OK; + } + + + /* updates host performance data */ + int xpddefault_update_host_performance_data(host *hst){ + + /* run the performance data command */ + xpddefault_run_host_performance_data_command(hst); + + /* update the performance data file */ + xpddefault_update_host_performance_data_file(hst); + + return OK; + } + + + + + /******************************************************************/ + /************** PERFORMANCE DATA COMMAND FUNCTIONS ****************/ + /******************************************************************/ + + + /* runs the service performance data command */ + int xpddefault_run_service_performance_data_command(service *svc){ char raw_command_line[MAX_INPUT_BUFFER]; char processed_command_line[MAX_INPUT_BUFFER]; *************** *** 223,230 **** int macro_options=STRIP_ILLEGAL_MACRO_CHARS|ESCAPE_MACRO_CHARS; - #ifdef DEBUG0 - printf("xpddefault_update_service_performance_data() start\n"); - #endif - /* we don't have a command */ if(xpddefault_service_perfdata_command==NULL) --- 380,383 ---- *************** *** 264,277 **** } - #ifdef DEBUG0 - printf("xpddefault_update_service_performance_data() end\n"); - #endif - return result; } ! /* updates host performance data */ ! int xpddefault_update_host_performance_data(host *hst){ char raw_command_line[MAX_INPUT_BUFFER]; char processed_command_line[MAX_INPUT_BUFFER]; --- 417,426 ---- } return result; } ! /* runs the host performance data command */ ! int xpddefault_run_host_performance_data_command(host *hst){ char raw_command_line[MAX_INPUT_BUFFER]; char processed_command_line[MAX_INPUT_BUFFER]; *************** *** 282,289 **** int macro_options=STRIP_ILLEGAL_MACRO_CHARS|ESCAPE_MACRO_CHARS; - #ifdef DEBUG0 - printf("xpddefault_update_host_performance_data() start\n"); - #endif - /* we don't have a command */ if(xpddefault_host_perfdata_command==NULL) --- 431,434 ---- *************** *** 319,326 **** } ! #ifdef DEBUG0 ! printf("xpddefault_update_host_performance_data() end\n"); #endif return result; } --- 464,768 ---- } ! return result; ! } ! ! ! ! /******************************************************************/ ! /**************** FILE PERFORMANCE DATA FUNCTIONS *****************/ ! /******************************************************************/ ! ! /* open the host performance data file for writing */ ! int xpddefault_open_host_perfdata_file(void){ ! char buffer[MAX_INPUT_BUFFER]; ! ! if(xpddefault_host_perfdata_file!=NULL){ ! ! xpddefault_host_perfdata_fp=fopen(xpddefault_host_perfdata_file,(xpddefault_host_perfdata_file_append==TRUE)?"a":"w"); ! ! if(xpddefault_host_perfdata_fp==NULL){ ! snprintf(buffer,sizeof(buffer),"Warning: File '%s' could not be opened - host performance data will not be written to file!\n",xpddefault_host_perfdata_file); ! buffer[sizeof(buffer)-1]='\x0'; ! write_to_logs_and_console(buffer,NSLOG_RUNTIME_WARNING,TRUE); ! return ERROR; ! } ! } ! ! return OK; ! } ! ! ! /* open the service performance data file for writing */ ! int xpddefault_open_service_perfdata_file(void){ ! char buffer[MAX_INPUT_BUFFER]; ! ! if(xpddefault_service_perfdata_file!=NULL){ ! ! xpddefault_service_perfdata_fp=fopen(xpddefault_service_perfdata_file,(xpddefault_service_perfdata_file_append==TRUE)?"a":"w"); ! ! if(xpddefault_service_perfdata_fp==NULL){ ! snprintf(buffer,sizeof(buffer),"Warning: File '%s' could not be opened - service performance data will not be written to file!\n",xpddefault_service_perfdata_file); ! buffer[sizeof(buffer)-1]='\x0'; ! write_to_logs_and_console(buffer,NSLOG_RUNTIME_WARNING,TRUE); ! return ERROR; ! } ! } ! ! return OK; ! } ! ! ! /* close the host performance data file */ ! int xpddefault_close_host_perfdata_file(void){ ! ! if(xpddefault_host_perfdata_fp!=NULL) ! fclose(xpddefault_host_perfdata_fp); ! ! return OK; ! } ! ! ! /* close the service performance data file */ ! int xpddefault_close_service_perfdata_file(void){ ! ! if(xpddefault_service_perfdata_fp!=NULL) ! fclose(xpddefault_service_perfdata_fp); ! ! return OK; ! } ! ! ! /* processes delimiter characters in templates */ ! int xpddefault_preprocess_file_templates(char *template){ ! char *tempbuf; ! int x=0; ! int y=0; ! ! if(template==NULL) ! return OK; ! ! /* allocate temporary buffer */ ! tempbuf=(char *)malloc(strlen(template)+1); ! if(tempbuf==NULL) ! return ERROR; ! strcpy(tempbuf,""); ! ! for(x=0,y=0;x<strlen(template);x++,y++){ ! if(template[x]=='\\'){ ! if(template[x+1]=='t'){ ! tempbuf[y]='\t'; ! x++; ! } ! else if(template[x+1]=='r'){ ! tempbuf[y]='\r'; ! x++; ! } ! else if(template[x+1]=='n'){ ! tempbuf[y]='\n'; ! x++; ! } ! else ! tempbuf[y]=template[x]; ! } ! else ! tempbuf[y]=template[x]; ! } ! tempbuf[y]='\x0'; ! ! strcpy(template,tempbuf); ! free(tempbuf); ! ! return OK; ! } ! ! ! /* updates service performance data file */ ! int xpddefault_update_service_performance_data_file(service *svc){ ! char raw_output[MAX_INPUT_BUFFER]; ! char processed_output[MAX_INPUT_BUFFER]; ! host *temp_host; ! int result=OK; ! ! /* we don't have a file to write to*/ ! if(xpddefault_service_perfdata_fp==NULL) ! return OK; ! ! /* find the associated host */ ! temp_host=find_host(svc->host_name); ! ! /* update service macros */ ! clear_volatile_macros(); ! grab_host_macros(temp_host); ! grab_service_macros(svc); ! ! /* get the raw line to write */ ! strncpy(raw_output,xpddefault_service_perfdata_file_template,sizeof(raw_output)); ! raw_output[sizeof(raw_output)-1]='\x0'; ! ! #ifdef DEBUG3 ! printf("\tRaw service performance data output: %s\n",raw_output); ! #endif ! ! /* process any macros in the raw output line */ ! process_macros(raw_output,processed_output,(int)sizeof(processed_output),0); ! ! #ifdef DEBUG3 ! printf("\tProcessed service performance data output: %s\n",processed_output); #endif + /* write the processed output line containing performance data to the service perfdata file */ + fputs(processed_output,xpddefault_service_perfdata_fp); + fputs("\n",xpddefault_service_perfdata_fp); + fflush(xpddefault_service_perfdata_fp); + return result; } + + + /* updates host performance data file */ + int xpddefault_update_host_performance_data_file(host *hst){ + char raw_output[MAX_INPUT_BUFFER]; + char processed_output[MAX_INPUT_BUFFER]; + int result=OK; + + /* we don't have a host perfdata file */ + if(xpddefault_host_perfdata_fp==NULL) + return OK; + + /* update host macros */ + clear_volatile_macros(); + grab_host_macros(hst); + + /* get the raw output */ + strncpy(raw_output,xpddefault_host_perfdata_file_template,sizeof(raw_output)); + raw_output[sizeof(raw_output)-1]='\x0'; + + #ifdef DEBUG3 + printf("\tRaw host performance output: %s\n",raw_output); + #endif + + /* process any macros in the raw output */ + process_macros(raw_output,processed_output,(int)sizeof(processed_output),0); + + #ifdef DEBUG3 + printf("\tProcessed host performance data output: %s\n",processed_output); + #endif + + /* write the processed output line containing performance data to the host perfdata file */ + fputs(processed_output,xpddefault_host_perfdata_fp); + fputs("\n",xpddefault_host_perfdata_fp); + fflush(xpddefault_host_perfdata_fp); + + return result; + } + + + /* periodically process the host perf data file */ + int xpddefault_process_host_perfdata_file(void){ + char raw_command_line[MAX_INPUT_BUFFER]; + char processed_command_line[MAX_INPUT_BUFFER]; + char temp_buffer[MAX_INPUT_BUFFER]; + host *temp_host; + int early_timeout=FALSE; + double exectime; + int result=OK; + int macro_options=STRIP_ILLEGAL_MACRO_CHARS|ESCAPE_MACRO_CHARS; + + /* we don't have a command */ + if(xpddefault_host_perfdata_file_processing_command==NULL) + return OK; + + /* close the performance data files */ + xpddefault_close_host_perfdata_file(); + xpddefault_close_service_perfdata_file(); + + /* update macros */ + clear_volatile_macros(); + + /* get the raw command line */ + get_raw_command_line(xpddefault_host_perfdata_file_processing_command,raw_command_line,sizeof(raw_command_line),macro_options); + strip(raw_command_line); + + #ifdef DEBUG3 + printf("\tRaw host performance data file processing command line: %s\n",raw_command_line); + #endif + + /* process any macros in the raw command line */ + process_macros(raw_command_line,processed_command_line,(int)sizeof(processed_command_line),macro_options); + + #ifdef DEBUG3 + printf("\tProcessed host performance data file processing command line: %s\n",processed_command_line); + #endif + + /* run the command */ + my_system(processed_command_line,xpddefault_perfdata_timeout,&early_timeout,&exectime,NULL,0); + + /* check to see if the command timed out */ + if(early_timeout==TRUE){ + snprintf(temp_buffer,sizeof(temp_buffer),"Warning: Host performance data file processing command '%s' timed out after %d seconds\n",processed_command_line,xpddefault_perfdata_timeout); + temp_buffer[sizeof(temp_buffer)-1]='\x0'; + write_to_logs_and_console(temp_buffer,NSLOG_RUNTIME_WARNING,TRUE); + } + + /* re-open the performance data files */ + xpddefault_open_service_perfdata_file(); + xpddefault_open_host_perfdata_file(); + + return result; + } + + + /* periodically process the service perf data file */ + int xpddefault_process_service_perfdata_file(void){ + char raw_command_line[MAX_INPUT_BUFFER]; + char processed_command_line[MAX_INPUT_BUFFER]; + char temp_buffer[MAX_INPUT_BUFFER]; + host *temp_host; + int early_timeout=FALSE; + double exectime; + int result=OK; + int macro_options=STRIP_ILLEGAL_MACRO_CHARS|ESCAPE_MACRO_CHARS; + + /* we don't have a command */ + if(xpddefault_service_perfdata_file_processing_command==NULL) + return OK; + + /* close the performance data files */ + xpddefault_close_host_perfdata_file(); + xpddefault_close_service_perfdata_file(); + + /* update macros */ + clear_volatile_macros(); + + /* get the raw command line */ + get_raw_command_line(xpddefault_service_perfdata_file_processing_command,raw_command_line,sizeof(raw_command_line),macro_options); + strip(raw_command_line); + + #ifdef DEBUG3 + printf("\tRaw service performance data file processing command line: %s\n",raw_command_line); + #endif + + /* process any macros in the raw command line */ + process_macros(raw_command_line,processed_command_line,(int)sizeof(processed_command_line),macro_options); + + #ifdef DEBUG3 + printf("\tProcessed service performance data file processing command line: %s\n",processed_command_line); + #endif + + /* run the command */ + my_system(processed_command_line,xpddefault_perfdata_timeout,&early_timeout,&exectime,NULL,0); + + /* check to see if the command timed out */ + if(early_timeout==TRUE){ + snprintf(temp_buffer,sizeof(temp_buffer),"Warning: Service performance data file processing command '%s' timed out after %d seconds\n",processed_command_line,xpddefault_perfdata_timeout); + temp_buffer[sizeof(temp_buffer)-1]='\x0'; + write_to_logs_and_console(temp_buffer,NSLOG_RUNTIME_WARNING,TRUE); + } + + /* re-open the performance data files */ + xpddefault_open_service_perfdata_file(); + xpddefault_open_host_perfdata_file(); + + return result; + } + Index: xsddefault.c =================================================================== RCS file: /cvsroot/nagios/nagios/xdata/xsddefault.c,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** xsddefault.c 5 Jan 2004 02:45:35 -0000 1.20 --- xsddefault.c 3 Sep 2004 00:10:48 -0000 1.21 *************** *** 4,8 **** * * Copyright (c) 2000-2004 Ethan Galstad (na...@na...) ! * Last Modified: 01-05-2004 * * License: --- 4,8 ---- * * Copyright (c) 2000-2004 Ethan Galstad (na...@na...) ! * Last Modified: 08-13-2004 * * License: *************** *** 84,87 **** --- 84,89 ---- extern int aggregate_status_updates; + extern char *macro_x[MACRO_X_COUNT]; + extern host *host_list; extern service *service_list; *************** *** 184,187 **** --- 186,198 ---- return ERROR; + #ifdef NSCORE + /* save the status file macro */ + if(macro_x[MACRO_STATUSDATAFILE]!=NULL) + free(macro_x[MACRO_STATUSDATAFILE]); + macro_x[MACRO_STATUSDATAFILE]=(char *)strdup(xsddefault_status_log); + if(macro_x[MACRO_STATUSDATAFILE]!=NULL) + strip(macro_x[MACRO_STATUSDATAFILE]); + #endif + return OK; } --- xpdfile.c DELETED --- Index: xcddefault.c =================================================================== RCS file: /cvsroot/nagios/nagios/xdata/xcddefault.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** xcddefault.c 28 Aug 2003 04:07:36 -0000 1.11 --- xcddefault.c 3 Sep 2004 00:10:47 -0000 1.12 *************** *** 3,8 **** * XCDDEFAULT.C - Default external comment data routines for Nagios * ! * Copyright (c) 2000-2003 Ethan Galstad (na...@na...) ! * Last Modified: 08-26-2003 * * License: --- 3,8 ---- * XCDDEFAULT.C - Default external comment data routines for Nagios * ! * Copyright (c) 2000-2004 Ethan Galstad (na...@na...) ! * Last Modified: 08-13-2004 * * License: *************** *** 51,54 **** --- 51,55 ---- unsigned long current_comment_id=0; extern comment *comment_list; + extern char *macro_x[MACRO_X_COUNT]; #endif *************** *** 135,138 **** --- 136,148 ---- return ERROR; + #ifdef NSCORE + /* save the comment data file macro */ + if(macro_x[MACRO_COMMENTDATAFILE]!=NULL) + free(macro_x[MACRO_COMMENTDATAFILE]); + macro_x[MACRO_COMMENTDATAFILE]=(char *)strdup(xcddefault_comment_file); + if(macro_x[MACRO_COMMENTDATAFILE]!=NULL) + strip(macro_x[MACRO_COMMENTDATAFILE]); + #endif + return OK; } |