diff -ur nagios-2.6.original/base/config.c nagios-2.6.with_object_dump/base/config.c --- nagios-2.6.original/base/config.c 2005-12-26 23:18:14.000000000 +0000 +++ nagios-2.6.with_object_dump/base/config.c 2007-01-16 11:22:41.289362775 +0000 @@ -79,6 +79,7 @@ extern int verify_config; extern int test_scheduling; +extern int dump_object_data; extern double sleep_time; extern int interval_length; @@ -178,6 +179,7 @@ int result=OK; int options; int cache=FALSE; + int dump_object=FALSE; #ifdef DEBUG0 printf("read_all_config_data() start\n"); @@ -186,11 +188,14 @@ options=READ_ALL_OBJECT_DATA; /* cache object definitions if we're up and running */ - if(verify_config==FALSE && test_scheduling==FALSE) + if(verify_config==FALSE && test_scheduling==FALSE && dump_object_data==FALSE) cache=TRUE; + if(dump_object_data==TRUE) + dump_object=TRUE; + /* read in all host configuration data from external sources */ - result=read_object_config_data(main_config_file,options,cache); + result=read_object_config_data(main_config_file,options,cache,dump_object); if(result!=OK) return ERROR; diff -ur nagios-2.6.original/base/nagios.c nagios-2.6.with_object_dump/base/nagios.c --- nagios-2.6.original/base/nagios.c 2006-11-28 02:29:04.000000000 +0000 +++ nagios-2.6.with_object_dump/base/nagios.c 2007-01-16 11:22:06.097276187 +0000 @@ -147,6 +147,7 @@ int verify_config=FALSE; int test_scheduling=FALSE; +int dump_object_data=FALSE; int daemon_mode=FALSE; int daemon_dumps_core=TRUE; @@ -232,6 +233,7 @@ {"license",no_argument,0,'V'}, {"verify",no_argument,0,'v'}, {"daemon",no_argument,0,'d'}, + {"object-dump",no_argument,0,'o'}, {0,0,0,0} }; #endif @@ -245,9 +247,9 @@ while(1){ #ifdef HAVE_GETOPT_H - c=getopt_long(argc,argv,"+hVvds",long_options,&option_index); + c=getopt_long(argc,argv,"+hVvdso",long_options,&option_index); #else - c=getopt(argc,argv,"+hVvds"); + c=getopt(argc,argv,"+hVvdso"); #endif if(c==-1 || c==EOF) @@ -276,6 +278,10 @@ daemon_mode=TRUE; break; + case 'o': /* object-dump mode */ + dump_object_data=TRUE; + break; + default: break; } @@ -443,6 +449,35 @@ exit(result); } + /* We're just dumping object data */ + else if(dump_object_data==TRUE){ + + /* reset program variables */ + reset_variables(); + + /* read in the configuration files (main config file, resource and object config files) */ + if((result=read_main_config_file(config_file))==OK){ + + /* drop privileges */ + if((result=drop_privileges(nagios_user,nagios_group))==ERROR) + printf("Failed to drop privileges. Aborting."); + else + /* read object config files */ + result=read_all_object_data(config_file); + } + + printf("result=%d\n", result); + + /* clean up after ourselves */ + cleanup(); + + /* free config_file */ + free(config_file); + + /* exit */ + exit(result); + } + /* we're just testing scheduling... */ else if(test_scheduling==TRUE){ diff -ur nagios-2.6.original/common/objects.c nagios-2.6.with_object_dump/common/objects.c --- nagios-2.6.original/common/objects.c 2007-01-16 11:31:19.921222083 +0000 +++ nagios-2.6.with_object_dump/common/objects.c 2007-01-16 11:23:53.536228615 +0000 @@ -84,7 +84,7 @@ /* read all host configuration data from external source */ -int read_object_config_data(char *main_config_file,int options,int cache){ +int read_object_config_data(char *main_config_file,int options,int cache,int dump_objects){ int result=OK; #ifdef DEBUG0 @@ -94,7 +94,7 @@ /********* IMPLEMENTATION-SPECIFIC INPUT FUNCTION ********/ #ifdef USE_XODTEMPLATE /* read in data from all text host config files (template-based) */ - result=xodtemplate_read_config_data(main_config_file,options,cache); + result=xodtemplate_read_config_data(main_config_file,options,cache,dump_objects); if(result!=OK) return ERROR; #endif diff -ur nagios-2.6.original/include/objects.h nagios-2.6.with_object_dump/include/objects.h --- nagios-2.6.original/include/objects.h 2007-01-16 11:31:19.932226175 +0000 +++ nagios-2.6.with_object_dump/include/objects.h 2007-01-16 11:23:33.212671063 +0000 @@ -528,7 +528,7 @@ /**** Top-level input functions ****/ -int read_object_config_data(char *,int,int); /* reads all external configuration data of specific types */ +int read_object_config_data(char *,int,int,int); /* reads all external configuration data of specific types */ /**** Object Creation Functions ****/ contact *add_contact(char *,char *,char *,char *,char **,char *,char *,int,int,int,int,int,int,int,int,int,int,int); /* adds a contact definition */ diff -ur nagios-2.6.original/xdata/xodtemplate.c nagios-2.6.with_object_dump/xdata/xodtemplate.c --- nagios-2.6.original/xdata/xodtemplate.c 2007-01-16 11:31:19.945231011 +0000 +++ nagios-2.6.with_object_dump/xdata/xodtemplate.c 2007-01-16 11:26:49.049495271 +0000 @@ -103,7 +103,7 @@ /******************************************************************/ /* process all config files - both core and CGIs pass in name of main config file */ -int xodtemplate_read_config_data(char *main_config_file,int options,int cache){ +int xodtemplate_read_config_data(char *main_config_file,int options,int cache,int dump_objects){ #ifdef NSCORE char config_file[MAX_FILENAME_LENGTH]; char *input=NULL; @@ -256,8 +256,11 @@ result=xodtemplate_sort_objects(); /* cache object definitions */ - if(result==OK && cache==TRUE) - xodtemplate_cache_objects(xodtemplate_cache_file); + if(result==OK) + if (cache==TRUE) + xodtemplate_cache_objects(xodtemplate_cache_file); + else if (dump_objects==TRUE) + xodtemplate_cache_objects(""); #endif /* register objects */ @@ -9316,13 +9319,17 @@ time(¤t_time); /* open the cache file for writing */ - fp=fopen(cache_file,"w"); - if(fp==NULL){ - snprintf(temp_buffer,sizeof(temp_buffer)-1,"Warning: Could not open object cache file '%s' for writing!\n",cache_file); - temp_buffer[sizeof(temp_buffer)-1]='\x0'; - write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_WARNING,TRUE); - return ERROR; - } + if (cache_file != "") { + fp=fopen(cache_file,"w"); + if(fp==NULL){ + snprintf(temp_buffer,sizeof(temp_buffer)-1,"Warning: Could not open object cache file '%s' for writing!\n",cache_file); + temp_buffer[sizeof(temp_buffer)-1]='\x0'; + write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_WARNING,TRUE); + return ERROR; + } + } + else + fp=stdout; /* write header to cache file */ fprintf(fp,"########################################\n"); @@ -9810,7 +9817,8 @@ fprintf(fp,"\t}\n\n"); } - fclose(fp); + if (cache_file != "") + fclose(fp); #ifdef DEBUG0 printf("xodtemplate_cache_objects() end\n"); diff -ur nagios-2.6.original/xdata/xodtemplate.h nagios-2.6.with_object_dump/xdata/xodtemplate.h --- nagios-2.6.original/xdata/xodtemplate.h 2007-01-16 11:31:19.948232127 +0000 +++ nagios-2.6.with_object_dump/xdata/xodtemplate.h 2007-01-16 11:25:00.552149267 +0000 @@ -541,7 +541,7 @@ /********* FUNCTION DEFINITIONS **********/ -int xodtemplate_read_config_data(char *,int,int); /* top-level routine processes all config files */ +int xodtemplate_read_config_data(char *,int,int,int); /* top-level routine processes all config files */ int xodtemplate_grab_config_info(char *); /* grabs variables from main config file */ int xodtemplate_process_config_file(char *,int); /* process data in a specific config file */ int xodtemplate_process_config_dir(char *,int); /* process all files in a specific config directory */ --- nagios-2.6.original/cgi/cgiutils.c 2006-11-13 18:40:34.000000000 +0000 +++ nagios-2.6.with_object_dump/cgi/cgiutils.c 2007-01-16 11:38:47.917364012 +0000 @@ -611,7 +611,7 @@ return OK; /* read in all external config data of the desired type(s) */ - result=read_object_config_data(config_file,options,FALSE); + result=read_object_config_data(config_file,options,FALSE,FALSE); /* mark what items we've read in... */ if(options & READ_HOSTS)