~ubuntu-branches/ubuntu/raring/nagios3/raring

« back to all changes in this revision

Viewing changes to xdata/xsddefault.c

  • Committer: Package Import Robot
  • Author(s): Alexander Wirt
  • Date: 2012-06-16 09:05:19 UTC
  • mfrom: (8.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20120616090519-1okxgkbe21vumokr
Tags: 3.4.1-1
* [28e077b] Imported Upstream version 3.3.1
* [d5314e0] don't call updatepo in clean target
* [45b3eb9] Don't remove config foo
* [54e3dff] Don't fix permissions in cgi postinst
* [d7be9db] Build-depend on libpng-dev (Closes: #662441)
* [4c47006] Add dutch po translation (Closes: #654855)
* [2b6573b] Refresh 10_p1_pl_shebang.dpatch
* [316fd7a] Update 40_fix_spurious_dollar_signs_added_to_command_lines
* [5ff2780] Refresh 55_strip_logarchivepath.dpatch
* [811d269] Refresh 60_fix_p1.pl_patch_mini_epn.dpatch
* [39a1e9c] Remove now unneeded patch 98_fix_XSS_CVE-2011-2179
* [785a4e8] Remove unneded patch 99_fix_XSS_CVE-2011-1523
* [6ce98ef] Remove unneeded patchs from 00list
* [1d18266] Imported Upstream version 3.4.0
* [05584c8] Refresh patches
* [58098cd] Imported Upstream version 3.4.1
* [3e9e07a] Bump standards version
* [fe991e2] wrap-and-sort
* [1ba78f7] Also create /var/run/nagios in cgi package (Closes: #626854)

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
extern int external_command_buffer_slots;
104
104
extern circular_buffer external_command_buffer;
105
105
 
106
 
extern char *macro_x[MACRO_X_COUNT];
107
 
 
108
106
extern host *host_list;
109
107
extern service *service_list;
110
108
extern contact *contact_list;
128
126
#endif
129
127
 
130
128
 
131
 
char *xsddefault_status_log=NULL;
132
 
char *xsddefault_temp_file=NULL;
 
129
char *xsddefault_status_log = NULL;
 
130
char *xsddefault_temp_file = NULL;
133
131
 
134
132
 
135
133
 
138
136
/******************************************************************/
139
137
 
140
138
/* grab configuration information */
141
 
int xsddefault_grab_config_info(char *config_file){
142
 
        char *input=NULL;
 
139
int xsddefault_grab_config_info(char *config_file) {
 
140
        char *input = NULL;
143
141
        mmapfile *thefile;
144
142
#ifdef NSCGI
145
 
        char *input2=NULL;
 
143
        char *input2 = NULL;
146
144
        mmapfile *thefile2;
147
145
        char *temp_buffer;
 
146
#else
 
147
        nagios_macros *mac;
148
148
#endif
149
149
 
150
150
 
151
151
        /*** CORE PASSES IN MAIN CONFIG FILE, CGIS PASS IN CGI CONFIG FILE! ***/
152
152
 
153
153
        /* open the config file for reading */
154
 
        if((thefile=mmap_fopen(config_file))==NULL)
 
154
        if((thefile = mmap_fopen(config_file)) == NULL)
155
155
                return ERROR;
156
156
 
157
157
        /* read in all lines from the main config file */
158
 
        while(1){
 
158
        while(1) {
159
159
 
160
160
                /* free memory */
161
161
                my_free(input);
162
162
 
163
163
                /* read the next line */
164
 
                if((input=mmap_fgets_multiline(thefile))==NULL)
 
164
                if((input = mmap_fgets_multiline(thefile)) == NULL)
165
165
                        break;
166
166
 
167
167
                strip(input);
168
168
 
169
169
                /* skip blank lines and comments */
170
 
                if(input[0]=='#' || input[0]=='\x0')
 
170
                if(input[0] == '#' || input[0] == '\x0')
171
171
                        continue;
172
172
 
173
173
#ifdef NSCGI
174
174
                /* CGI needs to find and read contents of main config file, since it was passed the name of the CGI config file */
175
 
                if(strstr(input,"main_config_file")==input){
 
175
                if(strstr(input, "main_config_file") == input) {
176
176
 
177
 
                        temp_buffer=strtok(input,"=");
178
 
                        temp_buffer=strtok(NULL,"\n");
179
 
                        if(temp_buffer==NULL)
 
177
                        temp_buffer = strtok(input, "=");
 
178
                        temp_buffer = strtok(NULL, "\n");
 
179
                        if(temp_buffer == NULL)
180
180
                                continue;
181
181
 
182
 
                        if((thefile2=mmap_fopen(temp_buffer))==NULL)
 
182
                        if((thefile2 = mmap_fopen(temp_buffer)) == NULL)
183
183
                                continue;
184
184
 
185
185
                        /* read in all lines from the main config file */
186
 
                        while(1){
 
186
                        while(1) {
187
187
 
188
188
                                /* free memory */
189
189
                                my_free(input2);
190
190
 
191
191
                                /* read the next line */
192
 
                                if((input2=mmap_fgets_multiline(thefile2))==NULL)
 
192
                                if((input2 = mmap_fgets_multiline(thefile2)) == NULL)
193
193
                                        break;
194
194
 
195
195
                                strip(input2);
196
196
 
197
197
                                /* skip blank lines and comments */
198
 
                                if(input2[0]=='#' || input2[0]=='\x0')
 
198
                                if(input2[0] == '#' || input2[0] == '\x0')
199
199
                                        continue;
200
200
 
201
201
                                xsddefault_grab_config_directives(input2);
202
 
                                }
 
202
                                }
203
203
 
204
204
                        /* free memory and close the file */
205
205
                        my_free(input2);
206
206
                        mmap_fclose(thefile2);
207
 
                        }
 
207
                        }
208
208
#endif
209
209
 
210
210
#ifdef NSCORE
211
211
                /* core reads variables directly from the main config file */
212
212
                xsddefault_grab_config_directives(input);
213
213
#endif
214
 
                }
 
214
                }
215
215
 
216
216
        /* free memory and close the file */
217
217
        my_free(input);
218
218
        mmap_fclose(thefile);
219
219
 
220
220
        /* initialize locations if necessary */
221
 
        if(xsddefault_status_log==NULL)
222
 
                xsddefault_status_log=(char *)strdup(DEFAULT_STATUS_FILE);
223
 
        if(xsddefault_temp_file==NULL)
224
 
                xsddefault_temp_file=(char *)strdup(DEFAULT_TEMP_FILE);
 
221
        if(xsddefault_status_log == NULL)
 
222
                xsddefault_status_log = (char *)strdup(DEFAULT_STATUS_FILE);
 
223
        if(xsddefault_temp_file == NULL)
 
224
                xsddefault_temp_file = (char *)strdup(DEFAULT_TEMP_FILE);
225
225
 
226
226
        /* make sure we have what we need */
227
 
        if(xsddefault_status_log==NULL)
 
227
        if(xsddefault_status_log == NULL)
228
228
                return ERROR;
229
 
        if(xsddefault_temp_file==NULL)
 
229
        if(xsddefault_temp_file == NULL)
230
230
                return ERROR;
231
231
 
232
232
#ifdef NSCORE
 
233
        mac = get_global_macros();
233
234
        /* save the status file macro */
234
 
        my_free(macro_x[MACRO_STATUSDATAFILE]);
235
 
        if((macro_x[MACRO_STATUSDATAFILE]=(char *)strdup(xsddefault_status_log)))
236
 
                strip(macro_x[MACRO_STATUSDATAFILE]);
 
235
        my_free(mac->x[MACRO_STATUSDATAFILE]);
 
236
        if((mac->x[MACRO_STATUSDATAFILE] = (char *)strdup(xsddefault_status_log)))
 
237
                strip(mac->x[MACRO_STATUSDATAFILE]);
237
238
#endif
238
239
 
239
240
        return OK;
240
 
        }
 
241
        }
241
242
 
242
243
 
243
244
/* processes a single directive */
244
 
int xsddefault_grab_config_directives(char *input){
245
 
        char *temp_ptr=NULL;
246
 
        char *varname=NULL;
247
 
        char *varvalue=NULL;
 
245
int xsddefault_grab_config_directives(char *input) {
 
246
        char *temp_ptr = NULL;
 
247
        char *varname = NULL;
 
248
        char *varvalue = NULL;
248
249
 
249
250
        /* get the variable name */
250
 
        if((temp_ptr=my_strtok(input,"="))==NULL)
 
251
        if((temp_ptr = my_strtok(input, "=")) == NULL)
251
252
                return ERROR;
252
 
        if((varname=(char *)strdup(temp_ptr))==NULL)
 
253
        if((varname = (char *)strdup(temp_ptr)) == NULL)
253
254
                return ERROR;
254
255
 
255
256
        /* get the variable value */
256
 
        if((temp_ptr=my_strtok(NULL,"\n"))==NULL){
257
 
                my_free(varname);
258
 
                return ERROR;
259
 
                }
260
 
        if((varvalue=(char *)strdup(temp_ptr))==NULL){
261
 
                my_free(varname);
262
 
                return ERROR;
263
 
                }
 
257
        if((temp_ptr = my_strtok(NULL, "\n")) == NULL) {
 
258
                my_free(varname);
 
259
                return ERROR;
 
260
                }
 
261
        if((varvalue = (char *)strdup(temp_ptr)) == NULL) {
 
262
                my_free(varname);
 
263
                return ERROR;
 
264
                }
264
265
 
265
266
        /* status log definition */
266
 
        if(!strcmp(varname,"status_file") || !strcmp(varname,"xsddefault_status_log"))
267
 
                xsddefault_status_log=(char *)strdup(temp_ptr);
 
267
        if(!strcmp(varname, "status_file") || !strcmp(varname, "xsddefault_status_log"))
 
268
                xsddefault_status_log = (char *)strdup(temp_ptr);
268
269
 
269
270
        /* temp file definition */
270
 
        else if(!strcmp(varname,"temp_file"))
271
 
                xsddefault_temp_file=(char *)strdup(temp_ptr);
 
271
        else if(!strcmp(varname, "temp_file"))
 
272
                xsddefault_temp_file = (char *)strdup(temp_ptr);
272
273
 
273
274
        /* free memory */
274
275
        my_free(varname);
275
276
        my_free(varvalue);
276
277
 
277
278
        return OK;
278
 
        }
 
279
        }
279
280
 
280
281
 
281
282
 
287
288
 
288
289
 
289
290
/* initialize status data */
290
 
int xsddefault_initialize_status_data(char *config_file){
 
291
int xsddefault_initialize_status_data(char *config_file) {
291
292
        int result;
292
293
 
293
294
        /* grab configuration data */
294
 
        result=xsddefault_grab_config_info(config_file);
295
 
        if(result==ERROR)
 
295
        result = xsddefault_grab_config_info(config_file);
 
296
        if(result == ERROR)
296
297
                return ERROR;
297
298
 
298
299
        /* delete the old status log (it might not exist) */
300
301
                unlink(xsddefault_status_log);
301
302
 
302
303
        return OK;
303
 
        }
 
304
        }
304
305
 
305
306
 
306
307
/* cleanup status data before terminating */
307
 
int xsddefault_cleanup_status_data(char *config_file, int delete_status_data){
 
308
int xsddefault_cleanup_status_data(char *config_file, int delete_status_data) {
308
309
 
309
310
        /* delete the status log */
310
 
        if(delete_status_data==TRUE && xsddefault_status_log){
 
311
        if(delete_status_data == TRUE && xsddefault_status_log) {
311
312
                if(unlink(xsddefault_status_log))
312
313
                        return ERROR;
313
 
                }
 
314
                }
314
315
 
315
316
        /* free memory */
316
317
        my_free(xsddefault_status_log);
317
318
        my_free(xsddefault_temp_file);
318
319
 
319
320
        return OK;
320
 
        }
 
321
        }
321
322
 
322
323
 
323
324
/******************************************************************/
325
326
/******************************************************************/
326
327
 
327
328
/* write all status data to file */
328
 
int xsddefault_save_status_data(void){
329
 
        char *temp_file=NULL;
330
 
        customvariablesmember *temp_customvariablesmember=NULL;
331
 
        host *temp_host=NULL;
332
 
        service *temp_service=NULL;
333
 
        contact *temp_contact=NULL;
334
 
        comment *temp_comment=NULL;
335
 
        scheduled_downtime *temp_downtime=NULL;
 
329
int xsddefault_save_status_data(void) {
 
330
        char *temp_file = NULL;
 
331
        customvariablesmember *temp_customvariablesmember = NULL;
 
332
        host *temp_host = NULL;
 
333
        service *temp_service = NULL;
 
334
        contact *temp_contact = NULL;
 
335
        comment *temp_comment = NULL;
 
336
        scheduled_downtime *temp_downtime = NULL;
336
337
        time_t current_time;
337
 
        int fd=0;
338
 
        FILE *fp=NULL;
339
 
        int used_external_command_buffer_slots=0;
340
 
        int high_external_command_buffer_slots=0;
341
 
        int result=OK;
 
338
        int fd = 0;
 
339
        FILE *fp = NULL;
 
340
        int used_external_command_buffer_slots = 0;
 
341
        int high_external_command_buffer_slots = 0;
 
342
        int result = OK;
342
343
 
343
 
        log_debug_info(DEBUGL_FUNCTIONS,0,"save_status_data()\n");
 
344
        log_debug_info(DEBUGL_FUNCTIONS, 0, "save_status_data()\n");
344
345
 
345
346
        /* open a safe temp file for output */
346
 
        if(xsddefault_temp_file==NULL)
347
 
                return ERROR;
348
 
        asprintf(&temp_file,"%sXXXXXX",xsddefault_temp_file);
349
 
        if(temp_file==NULL)
350
 
                return ERROR;
351
 
 
352
 
        log_debug_info(DEBUGL_STATUSDATA,2,"Writing status data to temp file '%s'\n",temp_file);
353
 
 
354
 
        if((fd=mkstemp(temp_file))==-1){
 
347
        if(xsddefault_temp_file == NULL)
 
348
                return ERROR;
 
349
        asprintf(&temp_file, "%sXXXXXX", xsddefault_temp_file);
 
350
        if(temp_file == NULL)
 
351
                return ERROR;
 
352
 
 
353
        log_debug_info(DEBUGL_STATUSDATA, 2, "Writing status data to temp file '%s'\n", temp_file);
 
354
 
 
355
        if((fd = mkstemp(temp_file)) == -1) {
355
356
 
356
357
                /* log an error */
357
 
#ifdef NSCORE
358
 
                logit(NSLOG_RUNTIME_ERROR,TRUE,"Error: Unable to create temp file for writing status data!\n");
359
 
#endif
 
358
                logit(NSLOG_RUNTIME_ERROR, TRUE, "Error: Unable to create temp file for writing status data: %s\n", strerror(errno));
360
359
 
361
360
                /* free memory */
362
361
                my_free(temp_file);
363
362
 
364
363
                return ERROR;
365
 
                }
366
 
        fp=(FILE *)fdopen(fd,"w");
367
 
        if(fp==NULL){
 
364
                }
 
365
        fp = (FILE *)fdopen(fd, "w");
 
366
        if(fp == NULL) {
368
367
 
369
368
                close(fd);
370
369
                unlink(temp_file);
371
370
 
372
371
                /* log an error */
373
 
#ifdef NSCORE
374
 
                logit(NSLOG_RUNTIME_ERROR,TRUE,"Error: Unable to open temp file '%s' for writing status data!\n",temp_file);
375
 
#endif
 
372
                logit(NSLOG_RUNTIME_ERROR, TRUE, "Error: Unable to open temp file '%s' for writing status data: %s\n", temp_file, strerror(errno));
376
373
 
377
374
                /* free memory */
378
375
                my_free(temp_file);
379
376
 
380
377
                return ERROR;
381
 
                }
 
378
                }
382
379
 
383
380
        /* get number of items in the command buffer */
384
 
        if(check_external_commands==TRUE){
 
381
        if(check_external_commands == TRUE) {
385
382
                pthread_mutex_lock(&external_command_buffer.buffer_lock);
386
 
                used_external_command_buffer_slots=external_command_buffer.items;
387
 
                high_external_command_buffer_slots=external_command_buffer.high;
 
383
                used_external_command_buffer_slots = external_command_buffer.items;
 
384
                high_external_command_buffer_slots = external_command_buffer.high;
388
385
                pthread_mutex_unlock(&external_command_buffer.buffer_lock);
389
386
                }
390
 
        else{
391
 
                used_external_command_buffer_slots=0;
392
 
                high_external_command_buffer_slots=0;
 
387
        else {
 
388
                used_external_command_buffer_slots = 0;
 
389
                high_external_command_buffer_slots = 0;
393
390
                }
394
391
 
395
392
        /* generate check statistics */
396
393
        generate_check_stats();
397
394
 
398
395
        /* write version info to status file */
399
 
        fprintf(fp,"########################################\n");
400
 
        fprintf(fp,"#          NAGIOS STATUS FILE\n");
401
 
        fprintf(fp,"#\n");
402
 
        fprintf(fp,"# THIS FILE IS AUTOMATICALLY GENERATED\n");
403
 
        fprintf(fp,"# BY NAGIOS.  DO NOT MODIFY THIS FILE!\n");
404
 
        fprintf(fp,"########################################\n\n");
 
396
        fprintf(fp, "########################################\n");
 
397
        fprintf(fp, "#          NAGIOS STATUS FILE\n");
 
398
        fprintf(fp, "#\n");
 
399
        fprintf(fp, "# THIS FILE IS AUTOMATICALLY GENERATED\n");
 
400
        fprintf(fp, "# BY NAGIOS.  DO NOT MODIFY THIS FILE!\n");
 
401
        fprintf(fp, "########################################\n\n");
405
402
 
406
403
        time(&current_time);
407
404
 
408
405
        /* write file info */
409
 
        fprintf(fp,"info {\n");
410
 
        fprintf(fp,"\tcreated=%lu\n",current_time);
411
 
        fprintf(fp,"\tversion=%s\n",PROGRAM_VERSION);
412
 
        fprintf(fp,"\tlast_update_check=%lu\n",last_update_check);
413
 
        fprintf(fp,"\tupdate_available=%d\n",update_available);
414
 
        fprintf(fp,"\tlast_version=%s\n",(last_program_version==NULL)?"":last_program_version);
415
 
        fprintf(fp,"\tnew_version=%s\n",(new_program_version==NULL)?"":new_program_version);
416
 
        fprintf(fp,"\t}\n\n");
 
406
        fprintf(fp, "info {\n");
 
407
        fprintf(fp, "\tcreated=%lu\n", current_time);
 
408
        fprintf(fp, "\tversion=%s\n", PROGRAM_VERSION);
 
409
        fprintf(fp, "\tlast_update_check=%lu\n", last_update_check);
 
410
        fprintf(fp, "\tupdate_available=%d\n", update_available);
 
411
        fprintf(fp, "\tlast_version=%s\n", (last_program_version == NULL) ? "" : last_program_version);
 
412
        fprintf(fp, "\tnew_version=%s\n", (new_program_version == NULL) ? "" : new_program_version);
 
413
        fprintf(fp, "\t}\n\n");
417
414
 
418
415
        /* save program status data */
419
 
        fprintf(fp,"programstatus {\n");
420
 
        fprintf(fp,"\tmodified_host_attributes=%lu\n",modified_host_process_attributes);
421
 
        fprintf(fp,"\tmodified_service_attributes=%lu\n",modified_service_process_attributes);
422
 
        fprintf(fp,"\tnagios_pid=%d\n",nagios_pid);
423
 
        fprintf(fp,"\tdaemon_mode=%d\n",daemon_mode);
424
 
        fprintf(fp,"\tprogram_start=%lu\n",program_start);
425
 
        fprintf(fp,"\tlast_command_check=%lu\n",last_command_check);
426
 
        fprintf(fp,"\tlast_log_rotation=%lu\n",last_log_rotation);
427
 
        fprintf(fp,"\tenable_notifications=%d\n",enable_notifications);
428
 
        fprintf(fp,"\tactive_service_checks_enabled=%d\n",execute_service_checks);
429
 
        fprintf(fp,"\tpassive_service_checks_enabled=%d\n",accept_passive_service_checks);
430
 
        fprintf(fp,"\tactive_host_checks_enabled=%d\n",execute_host_checks);
431
 
        fprintf(fp,"\tpassive_host_checks_enabled=%d\n",accept_passive_host_checks);
432
 
        fprintf(fp,"\tenable_event_handlers=%d\n",enable_event_handlers);
433
 
        fprintf(fp,"\tobsess_over_services=%d\n",obsess_over_services);
434
 
        fprintf(fp,"\tobsess_over_hosts=%d\n",obsess_over_hosts);
435
 
        fprintf(fp,"\tcheck_service_freshness=%d\n",check_service_freshness);
436
 
        fprintf(fp,"\tcheck_host_freshness=%d\n",check_host_freshness);
437
 
        fprintf(fp,"\tenable_flap_detection=%d\n",enable_flap_detection);
438
 
        fprintf(fp,"\tenable_failure_prediction=%d\n",enable_failure_prediction);
439
 
        fprintf(fp,"\tprocess_performance_data=%d\n",process_performance_data);
440
 
        fprintf(fp,"\tglobal_host_event_handler=%s\n",(global_host_event_handler==NULL)?"":global_host_event_handler);
441
 
        fprintf(fp,"\tglobal_service_event_handler=%s\n",(global_service_event_handler==NULL)?"":global_service_event_handler);
442
 
        fprintf(fp,"\tnext_comment_id=%lu\n",next_comment_id);
443
 
        fprintf(fp,"\tnext_downtime_id=%lu\n",next_downtime_id);
444
 
        fprintf(fp,"\tnext_event_id=%lu\n",next_event_id);
445
 
        fprintf(fp,"\tnext_problem_id=%lu\n",next_problem_id);
446
 
        fprintf(fp,"\tnext_notification_id=%lu\n",next_notification_id);
447
 
        fprintf(fp,"\ttotal_external_command_buffer_slots=%d\n",external_command_buffer_slots);
448
 
        fprintf(fp,"\tused_external_command_buffer_slots=%d\n",used_external_command_buffer_slots);
449
 
        fprintf(fp,"\thigh_external_command_buffer_slots=%d\n",high_external_command_buffer_slots);
450
 
        fprintf(fp,"\tactive_scheduled_host_check_stats=%d,%d,%d\n",check_statistics[ACTIVE_SCHEDULED_HOST_CHECK_STATS].minute_stats[0],check_statistics[ACTIVE_SCHEDULED_HOST_CHECK_STATS].minute_stats[1],check_statistics[ACTIVE_SCHEDULED_HOST_CHECK_STATS].minute_stats[2]);
451
 
        fprintf(fp,"\tactive_ondemand_host_check_stats=%d,%d,%d\n",check_statistics[ACTIVE_ONDEMAND_HOST_CHECK_STATS].minute_stats[0],check_statistics[ACTIVE_ONDEMAND_HOST_CHECK_STATS].minute_stats[1],check_statistics[ACTIVE_ONDEMAND_HOST_CHECK_STATS].minute_stats[2]);
452
 
        fprintf(fp,"\tpassive_host_check_stats=%d,%d,%d\n",check_statistics[PASSIVE_HOST_CHECK_STATS].minute_stats[0],check_statistics[PASSIVE_HOST_CHECK_STATS].minute_stats[1],check_statistics[PASSIVE_HOST_CHECK_STATS].minute_stats[2]);
453
 
        fprintf(fp,"\tactive_scheduled_service_check_stats=%d,%d,%d\n",check_statistics[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS].minute_stats[0],check_statistics[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS].minute_stats[1],check_statistics[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS].minute_stats[2]);
454
 
        fprintf(fp,"\tactive_ondemand_service_check_stats=%d,%d,%d\n",check_statistics[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS].minute_stats[0],check_statistics[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS].minute_stats[1],check_statistics[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS].minute_stats[2]);
455
 
        fprintf(fp,"\tpassive_service_check_stats=%d,%d,%d\n",check_statistics[PASSIVE_SERVICE_CHECK_STATS].minute_stats[0],check_statistics[PASSIVE_SERVICE_CHECK_STATS].minute_stats[1],check_statistics[PASSIVE_SERVICE_CHECK_STATS].minute_stats[2]);
456
 
        fprintf(fp,"\tcached_host_check_stats=%d,%d,%d\n",check_statistics[ACTIVE_CACHED_HOST_CHECK_STATS].minute_stats[0],check_statistics[ACTIVE_CACHED_HOST_CHECK_STATS].minute_stats[1],check_statistics[ACTIVE_CACHED_HOST_CHECK_STATS].minute_stats[2]);
457
 
        fprintf(fp,"\tcached_service_check_stats=%d,%d,%d\n",check_statistics[ACTIVE_CACHED_SERVICE_CHECK_STATS].minute_stats[0],check_statistics[ACTIVE_CACHED_SERVICE_CHECK_STATS].minute_stats[1],check_statistics[ACTIVE_CACHED_SERVICE_CHECK_STATS].minute_stats[2]);
458
 
        fprintf(fp,"\texternal_command_stats=%d,%d,%d\n",check_statistics[EXTERNAL_COMMAND_STATS].minute_stats[0],check_statistics[EXTERNAL_COMMAND_STATS].minute_stats[1],check_statistics[EXTERNAL_COMMAND_STATS].minute_stats[2]);
 
416
        fprintf(fp, "programstatus {\n");
 
417
        fprintf(fp, "\tmodified_host_attributes=%lu\n", modified_host_process_attributes);
 
418
        fprintf(fp, "\tmodified_service_attributes=%lu\n", modified_service_process_attributes);
 
419
        fprintf(fp, "\tnagios_pid=%d\n", nagios_pid);
 
420
        fprintf(fp, "\tdaemon_mode=%d\n", daemon_mode);
 
421
        fprintf(fp, "\tprogram_start=%lu\n", program_start);
 
422
        fprintf(fp, "\tlast_command_check=%lu\n", last_command_check);
 
423
        fprintf(fp, "\tlast_log_rotation=%lu\n", last_log_rotation);
 
424
        fprintf(fp, "\tenable_notifications=%d\n", enable_notifications);
 
425
        fprintf(fp, "\tactive_service_checks_enabled=%d\n", execute_service_checks);
 
426
        fprintf(fp, "\tpassive_service_checks_enabled=%d\n", accept_passive_service_checks);
 
427
        fprintf(fp, "\tactive_host_checks_enabled=%d\n", execute_host_checks);
 
428
        fprintf(fp, "\tpassive_host_checks_enabled=%d\n", accept_passive_host_checks);
 
429
        fprintf(fp, "\tenable_event_handlers=%d\n", enable_event_handlers);
 
430
        fprintf(fp, "\tobsess_over_services=%d\n", obsess_over_services);
 
431
        fprintf(fp, "\tobsess_over_hosts=%d\n", obsess_over_hosts);
 
432
        fprintf(fp, "\tcheck_service_freshness=%d\n", check_service_freshness);
 
433
        fprintf(fp, "\tcheck_host_freshness=%d\n", check_host_freshness);
 
434
        fprintf(fp, "\tenable_flap_detection=%d\n", enable_flap_detection);
 
435
        fprintf(fp, "\tenable_failure_prediction=%d\n", enable_failure_prediction);
 
436
        fprintf(fp, "\tprocess_performance_data=%d\n", process_performance_data);
 
437
        fprintf(fp, "\tglobal_host_event_handler=%s\n", (global_host_event_handler == NULL) ? "" : global_host_event_handler);
 
438
        fprintf(fp, "\tglobal_service_event_handler=%s\n", (global_service_event_handler == NULL) ? "" : global_service_event_handler);
 
439
        fprintf(fp, "\tnext_comment_id=%lu\n", next_comment_id);
 
440
        fprintf(fp, "\tnext_downtime_id=%lu\n", next_downtime_id);
 
441
        fprintf(fp, "\tnext_event_id=%lu\n", next_event_id);
 
442
        fprintf(fp, "\tnext_problem_id=%lu\n", next_problem_id);
 
443
        fprintf(fp, "\tnext_notification_id=%lu\n", next_notification_id);
 
444
        fprintf(fp, "\ttotal_external_command_buffer_slots=%d\n", external_command_buffer_slots);
 
445
        fprintf(fp, "\tused_external_command_buffer_slots=%d\n", used_external_command_buffer_slots);
 
446
        fprintf(fp, "\thigh_external_command_buffer_slots=%d\n", high_external_command_buffer_slots);
 
447
        fprintf(fp, "\tactive_scheduled_host_check_stats=%d,%d,%d\n", check_statistics[ACTIVE_SCHEDULED_HOST_CHECK_STATS].minute_stats[0], check_statistics[ACTIVE_SCHEDULED_HOST_CHECK_STATS].minute_stats[1], check_statistics[ACTIVE_SCHEDULED_HOST_CHECK_STATS].minute_stats[2]);
 
448
        fprintf(fp, "\tactive_ondemand_host_check_stats=%d,%d,%d\n", check_statistics[ACTIVE_ONDEMAND_HOST_CHECK_STATS].minute_stats[0], check_statistics[ACTIVE_ONDEMAND_HOST_CHECK_STATS].minute_stats[1], check_statistics[ACTIVE_ONDEMAND_HOST_CHECK_STATS].minute_stats[2]);
 
449
        fprintf(fp, "\tpassive_host_check_stats=%d,%d,%d\n", check_statistics[PASSIVE_HOST_CHECK_STATS].minute_stats[0], check_statistics[PASSIVE_HOST_CHECK_STATS].minute_stats[1], check_statistics[PASSIVE_HOST_CHECK_STATS].minute_stats[2]);
 
450
        fprintf(fp, "\tactive_scheduled_service_check_stats=%d,%d,%d\n", check_statistics[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS].minute_stats[0], check_statistics[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS].minute_stats[1], check_statistics[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS].minute_stats[2]);
 
451
        fprintf(fp, "\tactive_ondemand_service_check_stats=%d,%d,%d\n", check_statistics[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS].minute_stats[0], check_statistics[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS].minute_stats[1], check_statistics[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS].minute_stats[2]);
 
452
        fprintf(fp, "\tpassive_service_check_stats=%d,%d,%d\n", check_statistics[PASSIVE_SERVICE_CHECK_STATS].minute_stats[0], check_statistics[PASSIVE_SERVICE_CHECK_STATS].minute_stats[1], check_statistics[PASSIVE_SERVICE_CHECK_STATS].minute_stats[2]);
 
453
        fprintf(fp, "\tcached_host_check_stats=%d,%d,%d\n", check_statistics[ACTIVE_CACHED_HOST_CHECK_STATS].minute_stats[0], check_statistics[ACTIVE_CACHED_HOST_CHECK_STATS].minute_stats[1], check_statistics[ACTIVE_CACHED_HOST_CHECK_STATS].minute_stats[2]);
 
454
        fprintf(fp, "\tcached_service_check_stats=%d,%d,%d\n", check_statistics[ACTIVE_CACHED_SERVICE_CHECK_STATS].minute_stats[0], check_statistics[ACTIVE_CACHED_SERVICE_CHECK_STATS].minute_stats[1], check_statistics[ACTIVE_CACHED_SERVICE_CHECK_STATS].minute_stats[2]);
 
455
        fprintf(fp, "\texternal_command_stats=%d,%d,%d\n", check_statistics[EXTERNAL_COMMAND_STATS].minute_stats[0], check_statistics[EXTERNAL_COMMAND_STATS].minute_stats[1], check_statistics[EXTERNAL_COMMAND_STATS].minute_stats[2]);
459
456
 
460
 
        fprintf(fp,"\tparallel_host_check_stats=%d,%d,%d\n",check_statistics[PARALLEL_HOST_CHECK_STATS].minute_stats[0],check_statistics[PARALLEL_HOST_CHECK_STATS].minute_stats[1],check_statistics[PARALLEL_HOST_CHECK_STATS].minute_stats[2]);
461
 
        fprintf(fp,"\tserial_host_check_stats=%d,%d,%d\n",check_statistics[SERIAL_HOST_CHECK_STATS].minute_stats[0],check_statistics[SERIAL_HOST_CHECK_STATS].minute_stats[1],check_statistics[SERIAL_HOST_CHECK_STATS].minute_stats[2]);
462
 
        fprintf(fp,"\t}\n\n");
 
457
        fprintf(fp, "\tparallel_host_check_stats=%d,%d,%d\n", check_statistics[PARALLEL_HOST_CHECK_STATS].minute_stats[0], check_statistics[PARALLEL_HOST_CHECK_STATS].minute_stats[1], check_statistics[PARALLEL_HOST_CHECK_STATS].minute_stats[2]);
 
458
        fprintf(fp, "\tserial_host_check_stats=%d,%d,%d\n", check_statistics[SERIAL_HOST_CHECK_STATS].minute_stats[0], check_statistics[SERIAL_HOST_CHECK_STATS].minute_stats[1], check_statistics[SERIAL_HOST_CHECK_STATS].minute_stats[2]);
 
459
        fprintf(fp, "\t}\n\n");
463
460
 
464
461
 
465
462
        /* save host status data */
466
 
        for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
467
 
 
468
 
                fprintf(fp,"hoststatus {\n");
469
 
                fprintf(fp,"\thost_name=%s\n",temp_host->name);
470
 
 
471
 
                fprintf(fp,"\tmodified_attributes=%lu\n",temp_host->modified_attributes);
472
 
                fprintf(fp,"\tcheck_command=%s\n",(temp_host->host_check_command==NULL)?"":temp_host->host_check_command);
473
 
                fprintf(fp,"\tcheck_period=%s\n",(temp_host->check_period==NULL)?"":temp_host->check_period);
474
 
                fprintf(fp,"\tnotification_period=%s\n",(temp_host->notification_period==NULL)?"":temp_host->notification_period);
475
 
                fprintf(fp,"\tcheck_interval=%f\n",temp_host->check_interval);
476
 
                fprintf(fp,"\tretry_interval=%f\n",temp_host->retry_interval);
477
 
                fprintf(fp,"\tevent_handler=%s\n",(temp_host->event_handler==NULL)?"":temp_host->event_handler);
478
 
 
479
 
                fprintf(fp,"\thas_been_checked=%d\n",temp_host->has_been_checked);
480
 
                fprintf(fp,"\tshould_be_scheduled=%d\n",temp_host->should_be_scheduled);
481
 
                fprintf(fp,"\tcheck_execution_time=%.3f\n",temp_host->execution_time);
482
 
                fprintf(fp,"\tcheck_latency=%.3f\n",temp_host->latency);
483
 
                fprintf(fp,"\tcheck_type=%d\n",temp_host->check_type);
484
 
                fprintf(fp,"\tcurrent_state=%d\n",temp_host->current_state);
485
 
                fprintf(fp,"\tlast_hard_state=%d\n",temp_host->last_hard_state);
486
 
                fprintf(fp,"\tlast_event_id=%lu\n",temp_host->last_event_id);
487
 
                fprintf(fp,"\tcurrent_event_id=%lu\n",temp_host->current_event_id);
488
 
                fprintf(fp,"\tcurrent_problem_id=%lu\n",temp_host->current_problem_id);
489
 
                fprintf(fp,"\tlast_problem_id=%lu\n",temp_host->last_problem_id);
490
 
                fprintf(fp,"\tplugin_output=%s\n",(temp_host->plugin_output==NULL)?"":temp_host->plugin_output);
491
 
                fprintf(fp,"\tlong_plugin_output=%s\n",(temp_host->long_plugin_output==NULL)?"":temp_host->long_plugin_output);
492
 
                fprintf(fp,"\tperformance_data=%s\n",(temp_host->perf_data==NULL)?"":temp_host->perf_data);
493
 
                fprintf(fp,"\tlast_check=%lu\n",temp_host->last_check);
494
 
                fprintf(fp,"\tnext_check=%lu\n",temp_host->next_check);
495
 
                fprintf(fp,"\tcheck_options=%d\n",temp_host->check_options);
496
 
                fprintf(fp,"\tcurrent_attempt=%d\n",temp_host->current_attempt);
497
 
                fprintf(fp,"\tmax_attempts=%d\n",temp_host->max_attempts);
498
 
                fprintf(fp,"\tstate_type=%d\n",temp_host->state_type);
499
 
                fprintf(fp,"\tlast_state_change=%lu\n",temp_host->last_state_change);
500
 
                fprintf(fp,"\tlast_hard_state_change=%lu\n",temp_host->last_hard_state_change);
501
 
                fprintf(fp,"\tlast_time_up=%lu\n",temp_host->last_time_up);
502
 
                fprintf(fp,"\tlast_time_down=%lu\n",temp_host->last_time_down);
503
 
                fprintf(fp,"\tlast_time_unreachable=%lu\n",temp_host->last_time_unreachable);
504
 
                fprintf(fp,"\tlast_notification=%lu\n",temp_host->last_host_notification);
505
 
                fprintf(fp,"\tnext_notification=%lu\n",temp_host->next_host_notification);
506
 
                fprintf(fp,"\tno_more_notifications=%d\n",temp_host->no_more_notifications);
507
 
                fprintf(fp,"\tcurrent_notification_number=%d\n",temp_host->current_notification_number);
508
 
                fprintf(fp,"\tcurrent_notification_id=%lu\n",temp_host->current_notification_id);
509
 
                fprintf(fp,"\tnotifications_enabled=%d\n",temp_host->notifications_enabled);
510
 
                fprintf(fp,"\tproblem_has_been_acknowledged=%d\n",temp_host->problem_has_been_acknowledged);
511
 
                fprintf(fp,"\tacknowledgement_type=%d\n",temp_host->acknowledgement_type);
512
 
                fprintf(fp,"\tactive_checks_enabled=%d\n",temp_host->checks_enabled);
513
 
                fprintf(fp,"\tpassive_checks_enabled=%d\n",temp_host->accept_passive_host_checks);
514
 
                fprintf(fp,"\tevent_handler_enabled=%d\n",temp_host->event_handler_enabled);
515
 
                fprintf(fp,"\tflap_detection_enabled=%d\n",temp_host->flap_detection_enabled);
516
 
                fprintf(fp,"\tfailure_prediction_enabled=%d\n",temp_host->failure_prediction_enabled);
517
 
                fprintf(fp,"\tprocess_performance_data=%d\n",temp_host->process_performance_data);
518
 
                fprintf(fp,"\tobsess_over_host=%d\n",temp_host->obsess_over_host);
519
 
                fprintf(fp,"\tlast_update=%lu\n",current_time);
520
 
                fprintf(fp,"\tis_flapping=%d\n",temp_host->is_flapping);
521
 
                fprintf(fp,"\tpercent_state_change=%.2f\n",temp_host->percent_state_change);
522
 
                fprintf(fp,"\tscheduled_downtime_depth=%d\n",temp_host->scheduled_downtime_depth);
 
463
        for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
 
464
 
 
465
                fprintf(fp, "hoststatus {\n");
 
466
                fprintf(fp, "\thost_name=%s\n", temp_host->name);
 
467
 
 
468
                fprintf(fp, "\tmodified_attributes=%lu\n", temp_host->modified_attributes);
 
469
                fprintf(fp, "\tcheck_command=%s\n", (temp_host->host_check_command == NULL) ? "" : temp_host->host_check_command);
 
470
                fprintf(fp, "\tcheck_period=%s\n", (temp_host->check_period == NULL) ? "" : temp_host->check_period);
 
471
                fprintf(fp, "\tnotification_period=%s\n", (temp_host->notification_period == NULL) ? "" : temp_host->notification_period);
 
472
                fprintf(fp, "\tcheck_interval=%f\n", temp_host->check_interval);
 
473
                fprintf(fp, "\tretry_interval=%f\n", temp_host->retry_interval);
 
474
                fprintf(fp, "\tevent_handler=%s\n", (temp_host->event_handler == NULL) ? "" : temp_host->event_handler);
 
475
 
 
476
                fprintf(fp, "\thas_been_checked=%d\n", temp_host->has_been_checked);
 
477
                fprintf(fp, "\tshould_be_scheduled=%d\n", temp_host->should_be_scheduled);
 
478
                fprintf(fp, "\tcheck_execution_time=%.3f\n", temp_host->execution_time);
 
479
                fprintf(fp, "\tcheck_latency=%.3f\n", temp_host->latency);
 
480
                fprintf(fp, "\tcheck_type=%d\n", temp_host->check_type);
 
481
                fprintf(fp, "\tcurrent_state=%d\n", temp_host->current_state);
 
482
                fprintf(fp, "\tlast_hard_state=%d\n", temp_host->last_hard_state);
 
483
                fprintf(fp, "\tlast_event_id=%lu\n", temp_host->last_event_id);
 
484
                fprintf(fp, "\tcurrent_event_id=%lu\n", temp_host->current_event_id);
 
485
                fprintf(fp, "\tcurrent_problem_id=%lu\n", temp_host->current_problem_id);
 
486
                fprintf(fp, "\tlast_problem_id=%lu\n", temp_host->last_problem_id);
 
487
                fprintf(fp, "\tplugin_output=%s\n", (temp_host->plugin_output == NULL) ? "" : temp_host->plugin_output);
 
488
                fprintf(fp, "\tlong_plugin_output=%s\n", (temp_host->long_plugin_output == NULL) ? "" : temp_host->long_plugin_output);
 
489
                fprintf(fp, "\tperformance_data=%s\n", (temp_host->perf_data == NULL) ? "" : temp_host->perf_data);
 
490
                fprintf(fp, "\tlast_check=%lu\n", temp_host->last_check);
 
491
                fprintf(fp, "\tnext_check=%lu\n", temp_host->next_check);
 
492
                fprintf(fp, "\tcheck_options=%d\n", temp_host->check_options);
 
493
                fprintf(fp, "\tcurrent_attempt=%d\n", temp_host->current_attempt);
 
494
                fprintf(fp, "\tmax_attempts=%d\n", temp_host->max_attempts);
 
495
                fprintf(fp, "\tstate_type=%d\n", temp_host->state_type);
 
496
                fprintf(fp, "\tlast_state_change=%lu\n", temp_host->last_state_change);
 
497
                fprintf(fp, "\tlast_hard_state_change=%lu\n", temp_host->last_hard_state_change);
 
498
                fprintf(fp, "\tlast_time_up=%lu\n", temp_host->last_time_up);
 
499
                fprintf(fp, "\tlast_time_down=%lu\n", temp_host->last_time_down);
 
500
                fprintf(fp, "\tlast_time_unreachable=%lu\n", temp_host->last_time_unreachable);
 
501
                fprintf(fp, "\tlast_notification=%lu\n", temp_host->last_host_notification);
 
502
                fprintf(fp, "\tnext_notification=%lu\n", temp_host->next_host_notification);
 
503
                fprintf(fp, "\tno_more_notifications=%d\n", temp_host->no_more_notifications);
 
504
                fprintf(fp, "\tcurrent_notification_number=%d\n", temp_host->current_notification_number);
 
505
                fprintf(fp, "\tcurrent_notification_id=%lu\n", temp_host->current_notification_id);
 
506
                fprintf(fp, "\tnotifications_enabled=%d\n", temp_host->notifications_enabled);
 
507
                fprintf(fp, "\tproblem_has_been_acknowledged=%d\n", temp_host->problem_has_been_acknowledged);
 
508
                fprintf(fp, "\tacknowledgement_type=%d\n", temp_host->acknowledgement_type);
 
509
                fprintf(fp, "\tactive_checks_enabled=%d\n", temp_host->checks_enabled);
 
510
                fprintf(fp, "\tpassive_checks_enabled=%d\n", temp_host->accept_passive_host_checks);
 
511
                fprintf(fp, "\tevent_handler_enabled=%d\n", temp_host->event_handler_enabled);
 
512
                fprintf(fp, "\tflap_detection_enabled=%d\n", temp_host->flap_detection_enabled);
 
513
                fprintf(fp, "\tfailure_prediction_enabled=%d\n", temp_host->failure_prediction_enabled);
 
514
                fprintf(fp, "\tprocess_performance_data=%d\n", temp_host->process_performance_data);
 
515
                fprintf(fp, "\tobsess_over_host=%d\n", temp_host->obsess_over_host);
 
516
                fprintf(fp, "\tlast_update=%lu\n", current_time);
 
517
                fprintf(fp, "\tis_flapping=%d\n", temp_host->is_flapping);
 
518
                fprintf(fp, "\tpercent_state_change=%.2f\n", temp_host->percent_state_change);
 
519
                fprintf(fp, "\tscheduled_downtime_depth=%d\n", temp_host->scheduled_downtime_depth);
523
520
                /*
524
521
                fprintf(fp,"\tstate_history=");
525
522
                for(x=0;x<MAX_STATE_HISTORY_ENTRIES;x++)
527
524
                fprintf(fp,"\n");
528
525
                */
529
526
                /* custom variables */
530
 
                for(temp_customvariablesmember=temp_host->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){
 
527
                for(temp_customvariablesmember = temp_host->custom_variables; temp_customvariablesmember != NULL; temp_customvariablesmember = temp_customvariablesmember->next) {
531
528
                        if(temp_customvariablesmember->variable_name)
532
 
                                fprintf(fp,"\t_%s=%d;%s\n",temp_customvariablesmember->variable_name,temp_customvariablesmember->has_been_modified,(temp_customvariablesmember->variable_value==NULL)?"":temp_customvariablesmember->variable_value);
533
 
                        }
534
 
                fprintf(fp,"\t}\n\n");
535
 
                }
 
529
                                fprintf(fp, "\t_%s=%d;%s\n", temp_customvariablesmember->variable_name, temp_customvariablesmember->has_been_modified, (temp_customvariablesmember->variable_value == NULL) ? "" : temp_customvariablesmember->variable_value);
 
530
                        }
 
531
                fprintf(fp, "\t}\n\n");
 
532
                }
536
533
 
537
534
        /* save service status data */
538
 
        for(temp_service=service_list;temp_service!=NULL;temp_service=temp_service->next){
539
 
 
540
 
                fprintf(fp,"servicestatus {\n");
541
 
                fprintf(fp,"\thost_name=%s\n",temp_service->host_name);
542
 
 
543
 
                fprintf(fp,"\tservice_description=%s\n",temp_service->description);
544
 
                fprintf(fp,"\tmodified_attributes=%lu\n",temp_service->modified_attributes);
545
 
                fprintf(fp,"\tcheck_command=%s\n",(temp_service->service_check_command==NULL)?"":temp_service->service_check_command);
546
 
                fprintf(fp,"\tcheck_period=%s\n",(temp_service->check_period==NULL)?"":temp_service->check_period);
547
 
                fprintf(fp,"\tnotification_period=%s\n",(temp_service->notification_period==NULL)?"":temp_service->notification_period);
548
 
                fprintf(fp,"\tcheck_interval=%f\n",temp_service->check_interval);
549
 
                fprintf(fp,"\tretry_interval=%f\n",temp_service->retry_interval);
550
 
                fprintf(fp,"\tevent_handler=%s\n",(temp_service->event_handler==NULL)?"":temp_service->event_handler);
551
 
 
552
 
                fprintf(fp,"\thas_been_checked=%d\n",temp_service->has_been_checked);
553
 
                fprintf(fp,"\tshould_be_scheduled=%d\n",temp_service->should_be_scheduled);
554
 
                fprintf(fp,"\tcheck_execution_time=%.3f\n",temp_service->execution_time);
555
 
                fprintf(fp,"\tcheck_latency=%.3f\n",temp_service->latency);
556
 
                fprintf(fp,"\tcheck_type=%d\n",temp_service->check_type);
557
 
                fprintf(fp,"\tcurrent_state=%d\n",temp_service->current_state);
558
 
                fprintf(fp,"\tlast_hard_state=%d\n",temp_service->last_hard_state);
559
 
                fprintf(fp,"\tlast_event_id=%lu\n",temp_service->last_event_id);
560
 
                fprintf(fp,"\tcurrent_event_id=%lu\n",temp_service->current_event_id);
561
 
                fprintf(fp,"\tcurrent_problem_id=%lu\n",temp_service->current_problem_id);
562
 
                fprintf(fp,"\tlast_problem_id=%lu\n",temp_service->last_problem_id);
563
 
                fprintf(fp,"\tcurrent_attempt=%d\n",temp_service->current_attempt);
564
 
                fprintf(fp,"\tmax_attempts=%d\n",temp_service->max_attempts);
565
 
                fprintf(fp,"\tstate_type=%d\n",temp_service->state_type);
566
 
                fprintf(fp,"\tlast_state_change=%lu\n",temp_service->last_state_change);
567
 
                fprintf(fp,"\tlast_hard_state_change=%lu\n",temp_service->last_hard_state_change);
568
 
                fprintf(fp,"\tlast_time_ok=%lu\n",temp_service->last_time_ok);
569
 
                fprintf(fp,"\tlast_time_warning=%lu\n",temp_service->last_time_warning);
570
 
                fprintf(fp,"\tlast_time_unknown=%lu\n",temp_service->last_time_unknown);
571
 
                fprintf(fp,"\tlast_time_critical=%lu\n",temp_service->last_time_critical);
572
 
                fprintf(fp,"\tplugin_output=%s\n",(temp_service->plugin_output==NULL)?"":temp_service->plugin_output);
573
 
                fprintf(fp,"\tlong_plugin_output=%s\n",(temp_service->long_plugin_output==NULL)?"":temp_service->long_plugin_output);
574
 
                fprintf(fp,"\tperformance_data=%s\n",(temp_service->perf_data==NULL)?"":temp_service->perf_data);
575
 
                fprintf(fp,"\tlast_check=%lu\n",temp_service->last_check);
576
 
                fprintf(fp,"\tnext_check=%lu\n",temp_service->next_check);
577
 
                fprintf(fp,"\tcheck_options=%d\n",temp_service->check_options);
578
 
                fprintf(fp,"\tcurrent_notification_number=%d\n",temp_service->current_notification_number);
579
 
                fprintf(fp,"\tcurrent_notification_id=%lu\n",temp_service->current_notification_id);
580
 
                fprintf(fp,"\tlast_notification=%lu\n",temp_service->last_notification);
581
 
                fprintf(fp,"\tnext_notification=%lu\n",temp_service->next_notification);
582
 
                fprintf(fp,"\tno_more_notifications=%d\n",temp_service->no_more_notifications);
583
 
                fprintf(fp,"\tnotifications_enabled=%d\n",temp_service->notifications_enabled);
584
 
                fprintf(fp,"\tactive_checks_enabled=%d\n",temp_service->checks_enabled);
585
 
                fprintf(fp,"\tpassive_checks_enabled=%d\n",temp_service->accept_passive_service_checks);
586
 
                fprintf(fp,"\tevent_handler_enabled=%d\n",temp_service->event_handler_enabled);
587
 
                fprintf(fp,"\tproblem_has_been_acknowledged=%d\n",temp_service->problem_has_been_acknowledged);
588
 
                fprintf(fp,"\tacknowledgement_type=%d\n",temp_service->acknowledgement_type);
589
 
                fprintf(fp,"\tflap_detection_enabled=%d\n",temp_service->flap_detection_enabled);
590
 
                fprintf(fp,"\tfailure_prediction_enabled=%d\n",temp_service->failure_prediction_enabled);
591
 
                fprintf(fp,"\tprocess_performance_data=%d\n",temp_service->process_performance_data);
592
 
                fprintf(fp,"\tobsess_over_service=%d\n",temp_service->obsess_over_service);
593
 
                fprintf(fp,"\tlast_update=%lu\n",current_time);
594
 
                fprintf(fp,"\tis_flapping=%d\n",temp_service->is_flapping);
595
 
                fprintf(fp,"\tpercent_state_change=%.2f\n",temp_service->percent_state_change);
596
 
                fprintf(fp,"\tscheduled_downtime_depth=%d\n",temp_service->scheduled_downtime_depth);
 
535
        for(temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) {
 
536
 
 
537
                fprintf(fp, "servicestatus {\n");
 
538
                fprintf(fp, "\thost_name=%s\n", temp_service->host_name);
 
539
 
 
540
                fprintf(fp, "\tservice_description=%s\n", temp_service->description);
 
541
                fprintf(fp, "\tmodified_attributes=%lu\n", temp_service->modified_attributes);
 
542
                fprintf(fp, "\tcheck_command=%s\n", (temp_service->service_check_command == NULL) ? "" : temp_service->service_check_command);
 
543
                fprintf(fp, "\tcheck_period=%s\n", (temp_service->check_period == NULL) ? "" : temp_service->check_period);
 
544
                fprintf(fp, "\tnotification_period=%s\n", (temp_service->notification_period == NULL) ? "" : temp_service->notification_period);
 
545
                fprintf(fp, "\tcheck_interval=%f\n", temp_service->check_interval);
 
546
                fprintf(fp, "\tretry_interval=%f\n", temp_service->retry_interval);
 
547
                fprintf(fp, "\tevent_handler=%s\n", (temp_service->event_handler == NULL) ? "" : temp_service->event_handler);
 
548
 
 
549
                fprintf(fp, "\thas_been_checked=%d\n", temp_service->has_been_checked);
 
550
                fprintf(fp, "\tshould_be_scheduled=%d\n", temp_service->should_be_scheduled);
 
551
                fprintf(fp, "\tcheck_execution_time=%.3f\n", temp_service->execution_time);
 
552
                fprintf(fp, "\tcheck_latency=%.3f\n", temp_service->latency);
 
553
                fprintf(fp, "\tcheck_type=%d\n", temp_service->check_type);
 
554
                fprintf(fp, "\tcurrent_state=%d\n", temp_service->current_state);
 
555
                fprintf(fp, "\tlast_hard_state=%d\n", temp_service->last_hard_state);
 
556
                fprintf(fp, "\tlast_event_id=%lu\n", temp_service->last_event_id);
 
557
                fprintf(fp, "\tcurrent_event_id=%lu\n", temp_service->current_event_id);
 
558
                fprintf(fp, "\tcurrent_problem_id=%lu\n", temp_service->current_problem_id);
 
559
                fprintf(fp, "\tlast_problem_id=%lu\n", temp_service->last_problem_id);
 
560
                fprintf(fp, "\tcurrent_attempt=%d\n", temp_service->current_attempt);
 
561
                fprintf(fp, "\tmax_attempts=%d\n", temp_service->max_attempts);
 
562
                fprintf(fp, "\tstate_type=%d\n", temp_service->state_type);
 
563
                fprintf(fp, "\tlast_state_change=%lu\n", temp_service->last_state_change);
 
564
                fprintf(fp, "\tlast_hard_state_change=%lu\n", temp_service->last_hard_state_change);
 
565
                fprintf(fp, "\tlast_time_ok=%lu\n", temp_service->last_time_ok);
 
566
                fprintf(fp, "\tlast_time_warning=%lu\n", temp_service->last_time_warning);
 
567
                fprintf(fp, "\tlast_time_unknown=%lu\n", temp_service->last_time_unknown);
 
568
                fprintf(fp, "\tlast_time_critical=%lu\n", temp_service->last_time_critical);
 
569
                fprintf(fp, "\tplugin_output=%s\n", (temp_service->plugin_output == NULL) ? "" : temp_service->plugin_output);
 
570
                fprintf(fp, "\tlong_plugin_output=%s\n", (temp_service->long_plugin_output == NULL) ? "" : temp_service->long_plugin_output);
 
571
                fprintf(fp, "\tperformance_data=%s\n", (temp_service->perf_data == NULL) ? "" : temp_service->perf_data);
 
572
                fprintf(fp, "\tlast_check=%lu\n", temp_service->last_check);
 
573
                fprintf(fp, "\tnext_check=%lu\n", temp_service->next_check);
 
574
                fprintf(fp, "\tcheck_options=%d\n", temp_service->check_options);
 
575
                fprintf(fp, "\tcurrent_notification_number=%d\n", temp_service->current_notification_number);
 
576
                fprintf(fp, "\tcurrent_notification_id=%lu\n", temp_service->current_notification_id);
 
577
                fprintf(fp, "\tlast_notification=%lu\n", temp_service->last_notification);
 
578
                fprintf(fp, "\tnext_notification=%lu\n", temp_service->next_notification);
 
579
                fprintf(fp, "\tno_more_notifications=%d\n", temp_service->no_more_notifications);
 
580
                fprintf(fp, "\tnotifications_enabled=%d\n", temp_service->notifications_enabled);
 
581
                fprintf(fp, "\tactive_checks_enabled=%d\n", temp_service->checks_enabled);
 
582
                fprintf(fp, "\tpassive_checks_enabled=%d\n", temp_service->accept_passive_service_checks);
 
583
                fprintf(fp, "\tevent_handler_enabled=%d\n", temp_service->event_handler_enabled);
 
584
                fprintf(fp, "\tproblem_has_been_acknowledged=%d\n", temp_service->problem_has_been_acknowledged);
 
585
                fprintf(fp, "\tacknowledgement_type=%d\n", temp_service->acknowledgement_type);
 
586
                fprintf(fp, "\tflap_detection_enabled=%d\n", temp_service->flap_detection_enabled);
 
587
                fprintf(fp, "\tfailure_prediction_enabled=%d\n", temp_service->failure_prediction_enabled);
 
588
                fprintf(fp, "\tprocess_performance_data=%d\n", temp_service->process_performance_data);
 
589
                fprintf(fp, "\tobsess_over_service=%d\n", temp_service->obsess_over_service);
 
590
                fprintf(fp, "\tlast_update=%lu\n", current_time);
 
591
                fprintf(fp, "\tis_flapping=%d\n", temp_service->is_flapping);
 
592
                fprintf(fp, "\tpercent_state_change=%.2f\n", temp_service->percent_state_change);
 
593
                fprintf(fp, "\tscheduled_downtime_depth=%d\n", temp_service->scheduled_downtime_depth);
597
594
                /*
598
595
                fprintf(fp,"\tstate_history=");
599
596
                for(x=0;x<MAX_STATE_HISTORY_ENTRIES;x++)
601
598
                fprintf(fp,"\n");
602
599
                */
603
600
                /* custom variables */
604
 
                for(temp_customvariablesmember=temp_service->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){
 
601
                for(temp_customvariablesmember = temp_service->custom_variables; temp_customvariablesmember != NULL; temp_customvariablesmember = temp_customvariablesmember->next) {
605
602
                        if(temp_customvariablesmember->variable_name)
606
 
                                fprintf(fp,"\t_%s=%d;%s\n",temp_customvariablesmember->variable_name,temp_customvariablesmember->has_been_modified,(temp_customvariablesmember->variable_value==NULL)?"":temp_customvariablesmember->variable_value);
607
 
                        }
608
 
                fprintf(fp,"\t}\n\n");
609
 
                }
 
603
                                fprintf(fp, "\t_%s=%d;%s\n", temp_customvariablesmember->variable_name, temp_customvariablesmember->has_been_modified, (temp_customvariablesmember->variable_value == NULL) ? "" : temp_customvariablesmember->variable_value);
 
604
                        }
 
605
                fprintf(fp, "\t}\n\n");
 
606
                }
610
607
 
611
608
        /* save contact status data */
612
 
        for(temp_contact=contact_list;temp_contact!=NULL;temp_contact=temp_contact->next){
613
 
 
614
 
                fprintf(fp,"contactstatus {\n");
615
 
                fprintf(fp,"\tcontact_name=%s\n",temp_contact->name);
616
 
 
617
 
                fprintf(fp,"\tmodified_attributes=%lu\n",temp_contact->modified_attributes);
618
 
                fprintf(fp,"\tmodified_host_attributes=%lu\n",temp_contact->modified_host_attributes);
619
 
                fprintf(fp,"\tmodified_service_attributes=%lu\n",temp_contact->modified_service_attributes);
620
 
                fprintf(fp,"\thost_notification_period=%s\n",(temp_contact->host_notification_period==NULL)?"":temp_contact->host_notification_period);
621
 
                fprintf(fp,"\tservice_notification_period=%s\n",(temp_contact->service_notification_period==NULL)?"":temp_contact->service_notification_period);
622
 
 
623
 
                fprintf(fp,"\tlast_host_notification=%lu\n",temp_contact->last_host_notification);
624
 
                fprintf(fp,"\tlast_service_notification=%lu\n",temp_contact->last_service_notification);
625
 
                fprintf(fp,"\thost_notifications_enabled=%d\n",temp_contact->host_notifications_enabled);
626
 
                fprintf(fp,"\tservice_notifications_enabled=%d\n",temp_contact->service_notifications_enabled);
 
609
        for(temp_contact = contact_list; temp_contact != NULL; temp_contact = temp_contact->next) {
 
610
 
 
611
                fprintf(fp, "contactstatus {\n");
 
612
                fprintf(fp, "\tcontact_name=%s\n", temp_contact->name);
 
613
 
 
614
                fprintf(fp, "\tmodified_attributes=%lu\n", temp_contact->modified_attributes);
 
615
                fprintf(fp, "\tmodified_host_attributes=%lu\n", temp_contact->modified_host_attributes);
 
616
                fprintf(fp, "\tmodified_service_attributes=%lu\n", temp_contact->modified_service_attributes);
 
617
                fprintf(fp, "\thost_notification_period=%s\n", (temp_contact->host_notification_period == NULL) ? "" : temp_contact->host_notification_period);
 
618
                fprintf(fp, "\tservice_notification_period=%s\n", (temp_contact->service_notification_period == NULL) ? "" : temp_contact->service_notification_period);
 
619
 
 
620
                fprintf(fp, "\tlast_host_notification=%lu\n", temp_contact->last_host_notification);
 
621
                fprintf(fp, "\tlast_service_notification=%lu\n", temp_contact->last_service_notification);
 
622
                fprintf(fp, "\thost_notifications_enabled=%d\n", temp_contact->host_notifications_enabled);
 
623
                fprintf(fp, "\tservice_notifications_enabled=%d\n", temp_contact->service_notifications_enabled);
627
624
                /* custom variables */
628
 
                for(temp_customvariablesmember=temp_contact->custom_variables;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){
 
625
                for(temp_customvariablesmember = temp_contact->custom_variables; temp_customvariablesmember != NULL; temp_customvariablesmember = temp_customvariablesmember->next) {
629
626
                        if(temp_customvariablesmember->variable_name)
630
 
                                fprintf(fp,"\t_%s=%d;%s\n",temp_customvariablesmember->variable_name,temp_customvariablesmember->has_been_modified,(temp_customvariablesmember->variable_value==NULL)?"":temp_customvariablesmember->variable_value);
631
 
                        }
632
 
                fprintf(fp,"\t}\n\n");
633
 
                }
 
627
                                fprintf(fp, "\t_%s=%d;%s\n", temp_customvariablesmember->variable_name, temp_customvariablesmember->has_been_modified, (temp_customvariablesmember->variable_value == NULL) ? "" : temp_customvariablesmember->variable_value);
 
628
                        }
 
629
                fprintf(fp, "\t}\n\n");
 
630
                }
634
631
 
635
632
        /* save all comments */
636
 
        for(temp_comment=comment_list;temp_comment!=NULL;temp_comment=temp_comment->next){
 
633
        for(temp_comment = comment_list; temp_comment != NULL; temp_comment = temp_comment->next) {
637
634
 
638
 
                if(temp_comment->comment_type==HOST_COMMENT)
639
 
                        fprintf(fp,"hostcomment {\n");
 
635
                if(temp_comment->comment_type == HOST_COMMENT)
 
636
                        fprintf(fp, "hostcomment {\n");
640
637
                else
641
 
                        fprintf(fp,"servicecomment {\n");
642
 
                fprintf(fp,"\thost_name=%s\n",temp_comment->host_name);
643
 
                if(temp_comment->comment_type==SERVICE_COMMENT)
644
 
                        fprintf(fp,"\tservice_description=%s\n",temp_comment->service_description);
645
 
                fprintf(fp,"\tentry_type=%d\n",temp_comment->entry_type);
646
 
                fprintf(fp,"\tcomment_id=%lu\n",temp_comment->comment_id);
647
 
                fprintf(fp,"\tsource=%d\n",temp_comment->source);
648
 
                fprintf(fp,"\tpersistent=%d\n",temp_comment->persistent);
649
 
                fprintf(fp,"\tentry_time=%lu\n",temp_comment->entry_time);
650
 
                fprintf(fp,"\texpires=%d\n",temp_comment->expires);
651
 
                fprintf(fp,"\texpire_time=%lu\n",temp_comment->expire_time);
652
 
                fprintf(fp,"\tauthor=%s\n",temp_comment->author);
653
 
                fprintf(fp,"\tcomment_data=%s\n",temp_comment->comment_data);
654
 
                fprintf(fp,"\t}\n\n");
655
 
                }
 
638
                        fprintf(fp, "servicecomment {\n");
 
639
                fprintf(fp, "\thost_name=%s\n", temp_comment->host_name);
 
640
                if(temp_comment->comment_type == SERVICE_COMMENT)
 
641
                        fprintf(fp, "\tservice_description=%s\n", temp_comment->service_description);
 
642
                fprintf(fp, "\tentry_type=%d\n", temp_comment->entry_type);
 
643
                fprintf(fp, "\tcomment_id=%lu\n", temp_comment->comment_id);
 
644
                fprintf(fp, "\tsource=%d\n", temp_comment->source);
 
645
                fprintf(fp, "\tpersistent=%d\n", temp_comment->persistent);
 
646
                fprintf(fp, "\tentry_time=%lu\n", temp_comment->entry_time);
 
647
                fprintf(fp, "\texpires=%d\n", temp_comment->expires);
 
648
                fprintf(fp, "\texpire_time=%lu\n", temp_comment->expire_time);
 
649
                fprintf(fp, "\tauthor=%s\n", temp_comment->author);
 
650
                fprintf(fp, "\tcomment_data=%s\n", temp_comment->comment_data);
 
651
                fprintf(fp, "\t}\n\n");
 
652
                }
656
653
 
657
654
        /* save all downtime */
658
 
        for(temp_downtime=scheduled_downtime_list;temp_downtime!=NULL;temp_downtime=temp_downtime->next){
 
655
        for(temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
659
656
 
660
 
                if(temp_downtime->type==HOST_DOWNTIME)
661
 
                        fprintf(fp,"hostdowntime {\n");
 
657
                if(temp_downtime->type == HOST_DOWNTIME)
 
658
                        fprintf(fp, "hostdowntime {\n");
662
659
                else
663
 
                        fprintf(fp,"servicedowntime {\n");
664
 
                fprintf(fp,"\thost_name=%s\n",temp_downtime->host_name);
665
 
                if(temp_downtime->type==SERVICE_DOWNTIME)
666
 
                        fprintf(fp,"\tservice_description=%s\n",temp_downtime->service_description);
667
 
                fprintf(fp,"\tdowntime_id=%lu\n",temp_downtime->downtime_id);
668
 
                fprintf(fp,"\tentry_time=%lu\n",temp_downtime->entry_time);
669
 
                fprintf(fp,"\tstart_time=%lu\n",temp_downtime->start_time);
670
 
                fprintf(fp,"\tend_time=%lu\n",temp_downtime->end_time);
671
 
                fprintf(fp,"\ttriggered_by=%lu\n",temp_downtime->triggered_by);
672
 
                fprintf(fp,"\tfixed=%d\n",temp_downtime->fixed);
673
 
                fprintf(fp,"\tduration=%lu\n",temp_downtime->duration);
674
 
                fprintf(fp,"\tauthor=%s\n",temp_downtime->author);
675
 
                fprintf(fp,"\tcomment=%s\n",temp_downtime->comment);
676
 
                fprintf(fp,"\t}\n\n");
677
 
                }
 
660
                        fprintf(fp, "servicedowntime {\n");
 
661
                fprintf(fp, "\thost_name=%s\n", temp_downtime->host_name);
 
662
                if(temp_downtime->type == SERVICE_DOWNTIME)
 
663
                        fprintf(fp, "\tservice_description=%s\n", temp_downtime->service_description);
 
664
                fprintf(fp, "\tdowntime_id=%lu\n", temp_downtime->downtime_id);
 
665
                fprintf(fp, "\tentry_time=%lu\n", temp_downtime->entry_time);
 
666
                fprintf(fp, "\tstart_time=%lu\n", temp_downtime->start_time);
 
667
                fprintf(fp, "\tend_time=%lu\n", temp_downtime->end_time);
 
668
                fprintf(fp, "\ttriggered_by=%lu\n", temp_downtime->triggered_by);
 
669
                fprintf(fp, "\tfixed=%d\n", temp_downtime->fixed);
 
670
                fprintf(fp, "\tduration=%lu\n", temp_downtime->duration);
 
671
                fprintf(fp, "\tis_in_effect=%d\n", temp_downtime->is_in_effect);
 
672
                fprintf(fp, "\tauthor=%s\n", temp_downtime->author);
 
673
                fprintf(fp, "\tcomment=%s\n", temp_downtime->comment);
 
674
                fprintf(fp, "\t}\n\n");
 
675
                }
678
676
 
679
677
 
680
678
        /* reset file permissions */
681
 
        fchmod(fd,S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
 
679
        fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
682
680
 
683
681
        /* flush the file to disk */
684
682
        fflush(fp);
685
683
 
686
684
        /* close the temp file */
687
 
        result=fclose(fp);
 
685
        result = fclose(fp);
688
686
 
689
687
        /* fsync the file so that it is completely written out before moving it */
690
688
        fsync(fd);
691
689
 
692
690
        /* save/close was successful */
693
 
        if(result==0){
 
691
        if(result == 0) {
694
692
 
695
 
                result=OK;
 
693
                result = OK;
696
694
 
697
695
                /* move the temp file to the status log (overwrite the old status log) */
698
 
                if(my_rename(temp_file,xsddefault_status_log)){
 
696
                if(my_rename(temp_file, xsddefault_status_log)) {
699
697
                        unlink(temp_file);
700
 
#ifdef NSCORE
701
 
                        logit(NSLOG_RUNTIME_ERROR,TRUE,"Error: Unable to update status data file '%s': %s",xsddefault_status_log,strerror(errno));
702
 
#endif
703
 
                        result=ERROR;
 
698
                        logit(NSLOG_RUNTIME_ERROR, TRUE, "Error: Unable to update status data file '%s': %s", xsddefault_status_log, strerror(errno));
 
699
                        result = ERROR;
704
700
                        }
705
701
                }
706
702
 
707
703
        /* a problem occurred saving the file */
708
 
        else{
 
704
        else {
709
705
 
710
 
                result=ERROR;
 
706
                result = ERROR;
711
707
 
712
708
                /* remove temp file and log an error */
713
709
                unlink(temp_file);
714
 
                logit(NSLOG_RUNTIME_ERROR,TRUE,"Error: Unable to save status file: %s",strerror(errno));
715
 
                }
 
710
                logit(NSLOG_RUNTIME_ERROR, TRUE, "Error: Unable to save status file: %s", strerror(errno));
 
711
                }
716
712
 
717
713
        /* free memory */
718
714
        my_free(temp_file);
719
715
 
720
716
        return result;
721
 
        }
 
717
        }
722
718
 
723
719
#endif
724
720
 
731
727
/******************************************************************/
732
728
 
733
729
/* read all program, host, and service status information */
734
 
int xsddefault_read_status_data(char *config_file,int options){
 
730
int xsddefault_read_status_data(char *config_file, int options) {
735
731
#ifdef NO_MMAP
736
 
        char input[MAX_PLUGIN_OUTPUT_LENGTH]="";
737
 
        FILE *fp=NULL;
 
732
        char input[MAX_PLUGIN_OUTPUT_LENGTH] = "";
 
733
        FILE *fp = NULL;
738
734
#else
739
 
        char *input=NULL;
740
 
        mmapfile *thefile=NULL;
 
735
        char *input = NULL;
 
736
        mmapfile *thefile = NULL;
741
737
#endif
742
 
        int data_type=XSDDEFAULT_NO_DATA;
743
 
        hoststatus *temp_hoststatus=NULL;
744
 
        servicestatus *temp_servicestatus=NULL;
745
 
        char *var=NULL;
746
 
        char *val=NULL;
747
 
        char *ptr=NULL;
748
 
        int result=0;
 
738
        int data_type = XSDDEFAULT_NO_DATA;
 
739
        hoststatus *temp_hoststatus = NULL;
 
740
        servicestatus *temp_servicestatus = NULL;
 
741
        char *var = NULL;
 
742
        char *val = NULL;
 
743
        char *ptr = NULL;
 
744
        int result = 0;
749
745
        /* comment and downtime vars */
750
 
        unsigned long comment_id=0;
751
 
        int persistent=FALSE;
752
 
        int expires=FALSE;
753
 
        time_t expire_time=0L;
754
 
        int entry_type=USER_COMMENT;
755
 
        int source=COMMENTSOURCE_INTERNAL;
756
 
        time_t entry_time=0L;
757
 
        char *host_name=NULL;
758
 
        char *service_description=NULL;
759
 
        char *author=NULL;
760
 
        char *comment_data=NULL;
761
 
        unsigned long downtime_id=0;
762
 
        time_t start_time=0L;
763
 
        time_t end_time=0L;
764
 
        int fixed=FALSE;
765
 
        unsigned long triggered_by=0;
766
 
        unsigned long duration=0L;
767
 
        int x=0;
 
746
        unsigned long comment_id = 0;
 
747
        int persistent = FALSE;
 
748
        int expires = FALSE;
 
749
        time_t expire_time = 0L;
 
750
        int entry_type = USER_COMMENT;
 
751
        int source = COMMENTSOURCE_INTERNAL;
 
752
        time_t entry_time = 0L;
 
753
        char *host_name = NULL;
 
754
        char *service_description = NULL;
 
755
        char *author = NULL;
 
756
        char *comment_data = NULL;
 
757
        unsigned long downtime_id = 0;
 
758
        time_t start_time = 0L;
 
759
        time_t end_time = 0L;
 
760
        int fixed = FALSE;
 
761
        unsigned long triggered_by = 0;
 
762
        unsigned long duration = 0L;
 
763
        int x = 0;
 
764
        int is_in_effect = FALSE;
768
765
 
769
766
 
770
767
        /* initialize some vars */
771
 
        for(x=0;x<MAX_CHECK_STATS_TYPES;x++){
772
 
                program_stats[x][0]=0;
773
 
                program_stats[x][1]=0;
774
 
                program_stats[x][2]=0;
 
768
        for(x = 0; x < MAX_CHECK_STATS_TYPES; x++) {
 
769
                program_stats[x][0] = 0;
 
770
                program_stats[x][1] = 0;
 
771
                program_stats[x][2] = 0;
775
772
                }
776
773
 
777
774
        /* grab configuration data */
778
 
        result=xsddefault_grab_config_info(config_file);
779
 
        if(result==ERROR)
 
775
        result = xsddefault_grab_config_info(config_file);
 
776
        if(result == ERROR)
780
777
                return ERROR;
781
778
 
782
779
        /* open the status file for reading */
783
780
#ifdef NO_MMAP
784
 
        if((fp=fopen(xsddefault_status_log,"r"))==NULL)
 
781
        if((fp = fopen(xsddefault_status_log, "r")) == NULL)
785
782
                return ERROR;
786
783
#else
787
 
        if((thefile=mmap_fopen(xsddefault_status_log))==NULL)
 
784
        if((thefile = mmap_fopen(xsddefault_status_log)) == NULL)
788
785
                return ERROR;
789
786
#endif
790
787
 
791
788
        /* Big speedup when reading status.dat in bulk */
792
 
        defer_downtime_sorting=1;
793
 
        defer_comment_sorting=1;
 
789
        defer_downtime_sorting = 1;
 
790
        defer_comment_sorting = 1;
794
791
 
795
792
        /* read all lines in the status file */
796
 
        while(1){
 
793
        while(1) {
797
794
 
798
795
#ifdef NO_MMAP
799
 
                strcpy(input,"");
800
 
                if(fgets(input,sizeof(input),fp)==NULL)
 
796
                strcpy(input, "");
 
797
                if(fgets(input, sizeof(input), fp) == NULL)
801
798
                        break;
802
799
#else
803
800
                /* free memory */
804
801
                my_free(input);
805
802
 
806
803
                /* read the next line */
807
 
                if((input=mmap_fgets(thefile))==NULL)
 
804
                if((input = mmap_fgets(thefile)) == NULL)
808
805
                        break;
809
806
#endif
810
807
 
811
808
                strip(input);
812
809
 
813
810
                /* skip blank lines and comments */
814
 
                if(input[0]=='#' || input[0]=='\x0')
 
811
                if(input[0] == '#' || input[0] == '\x0')
815
812
                        continue;
816
813
 
817
 
                else if(!strcmp(input,"info {"))
818
 
                        data_type=XSDDEFAULT_INFO_DATA;
819
 
                else if(!strcmp(input,"programstatus {"))
820
 
                        data_type=XSDDEFAULT_PROGRAMSTATUS_DATA;
821
 
                else if(!strcmp(input,"hoststatus {")){
822
 
                        data_type=XSDDEFAULT_HOSTSTATUS_DATA;
823
 
                        temp_hoststatus=(hoststatus *)malloc(sizeof(hoststatus));
824
 
                        if(temp_hoststatus){
825
 
                                temp_hoststatus->host_name=NULL;
826
 
                                temp_hoststatus->plugin_output=NULL;
827
 
                                temp_hoststatus->long_plugin_output=NULL;
828
 
                                temp_hoststatus->perf_data=NULL;
829
 
                                temp_hoststatus->check_options=0;
830
 
                                }
831
 
                        }
832
 
                else if(!strcmp(input,"servicestatus {")){
833
 
                        data_type=XSDDEFAULT_SERVICESTATUS_DATA;
834
 
                        temp_servicestatus=(servicestatus *)malloc(sizeof(servicestatus));
835
 
                        if(temp_servicestatus){
836
 
                                temp_servicestatus->host_name=NULL;
837
 
                                temp_servicestatus->description=NULL;
838
 
                                temp_servicestatus->plugin_output=NULL;
839
 
                                temp_servicestatus->long_plugin_output=NULL;
840
 
                                temp_servicestatus->perf_data=NULL;
841
 
                                temp_servicestatus->check_options=0;
842
 
                                }
843
 
                        }
844
 
                else if(!strcmp(input,"contactstatus {")){
845
 
                        data_type=XSDDEFAULT_CONTACTSTATUS_DATA;
 
814
                else if(!strcmp(input, "info {"))
 
815
                        data_type = XSDDEFAULT_INFO_DATA;
 
816
                else if(!strcmp(input, "programstatus {"))
 
817
                        data_type = XSDDEFAULT_PROGRAMSTATUS_DATA;
 
818
                else if(!strcmp(input, "hoststatus {")) {
 
819
                        data_type = XSDDEFAULT_HOSTSTATUS_DATA;
 
820
                        temp_hoststatus = (hoststatus *)calloc(1, sizeof(hoststatus));
 
821
                        }
 
822
                else if(!strcmp(input, "servicestatus {")) {
 
823
                        data_type = XSDDEFAULT_SERVICESTATUS_DATA;
 
824
                        temp_servicestatus = (servicestatus *)calloc(1, sizeof(servicestatus));
 
825
                        }
 
826
                else if(!strcmp(input, "contactstatus {")) {
 
827
                        data_type = XSDDEFAULT_CONTACTSTATUS_DATA;
846
828
                        /* unimplemented */
847
 
                        }
848
 
                else if(!strcmp(input,"hostcomment {"))
849
 
                        data_type=XSDDEFAULT_HOSTCOMMENT_DATA;
850
 
                else if(!strcmp(input,"servicecomment {"))
851
 
                        data_type=XSDDEFAULT_SERVICECOMMENT_DATA;
852
 
                else if(!strcmp(input,"hostdowntime {"))
853
 
                        data_type=XSDDEFAULT_HOSTDOWNTIME_DATA;
854
 
                else if(!strcmp(input,"servicedowntime {"))
855
 
                        data_type=XSDDEFAULT_SERVICEDOWNTIME_DATA;
856
 
 
857
 
                else if(!strcmp(input,"}")){
858
 
 
859
 
                        switch(data_type){
860
 
 
861
 
                        case XSDDEFAULT_INFO_DATA:
862
 
                                break;
863
 
 
864
 
                        case XSDDEFAULT_PROGRAMSTATUS_DATA:
865
 
                                break;
866
 
 
867
 
                        case XSDDEFAULT_HOSTSTATUS_DATA:
868
 
                                add_host_status(temp_hoststatus);
869
 
                                temp_hoststatus=NULL;
870
 
                                break;
871
 
 
872
 
                        case XSDDEFAULT_SERVICESTATUS_DATA:
873
 
                                add_service_status(temp_servicestatus);
874
 
                                temp_servicestatus=NULL;
875
 
                                break;
876
 
 
877
 
                        case XSDDEFAULT_CONTACTSTATUS_DATA:
878
 
                                /* unimplemented */
879
 
                                break;
880
 
 
881
 
                        case XSDDEFAULT_HOSTCOMMENT_DATA:
882
 
                        case XSDDEFAULT_SERVICECOMMENT_DATA:
883
 
 
884
 
                                /* add the comment */
885
 
                                add_comment((data_type==XSDDEFAULT_HOSTCOMMENT_DATA)?HOST_COMMENT:SERVICE_COMMENT,entry_type,host_name,service_description,entry_time,author,comment_data,comment_id,persistent,expires,expire_time,source);
886
 
 
887
 
                                /* free temp memory */
888
 
                                my_free(host_name);
889
 
                                my_free(service_description);
890
 
                                my_free(author);
891
 
                                my_free(comment_data);
892
 
 
893
 
                                /* reset defaults */
894
 
                                entry_type=USER_COMMENT;
895
 
                                comment_id=0;
896
 
                                source=COMMENTSOURCE_INTERNAL;
897
 
                                persistent=FALSE;
898
 
                                entry_time=0L;
899
 
                                expires=FALSE;
900
 
                                expire_time=0L;
901
 
 
902
 
                                break;
903
 
 
904
 
                        case XSDDEFAULT_HOSTDOWNTIME_DATA:
905
 
                        case XSDDEFAULT_SERVICEDOWNTIME_DATA:
906
 
 
907
 
                                /* add the downtime */
908
 
                                if(data_type==XSDDEFAULT_HOSTDOWNTIME_DATA)
909
 
                                        add_host_downtime(host_name,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,downtime_id);
910
 
                                else
911
 
                                        add_service_downtime(host_name,service_description,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,downtime_id);
912
 
 
913
 
                                /* free temp memory */
914
 
                                my_free(host_name);
915
 
                                my_free(service_description);
916
 
                                my_free(author);
917
 
                                my_free(comment_data);
918
 
 
919
 
                                /* reset defaults */
920
 
                                downtime_id=0;
921
 
                                entry_time=0L;
922
 
                                start_time=0L;
923
 
                                end_time=0L;
924
 
                                fixed=FALSE;
925
 
                                triggered_by=0;
926
 
                                duration=0L;
927
 
 
928
 
                                break;
929
 
 
930
 
                        default:
931
 
                                break;
932
 
                                }
933
 
 
934
 
                        data_type=XSDDEFAULT_NO_DATA;
935
 
                        }
936
 
 
937
 
                else if(data_type!=XSDDEFAULT_NO_DATA){
938
 
 
939
 
                        var=strtok(input,"=");
940
 
                        val=strtok(NULL,"\n");
941
 
                        if(val==NULL)
 
829
                        }
 
830
                else if(!strcmp(input, "hostcomment {"))
 
831
                        data_type = XSDDEFAULT_HOSTCOMMENT_DATA;
 
832
                else if(!strcmp(input, "servicecomment {"))
 
833
                        data_type = XSDDEFAULT_SERVICECOMMENT_DATA;
 
834
                else if(!strcmp(input, "hostdowntime {"))
 
835
                        data_type = XSDDEFAULT_HOSTDOWNTIME_DATA;
 
836
                else if(!strcmp(input, "servicedowntime {"))
 
837
                        data_type = XSDDEFAULT_SERVICEDOWNTIME_DATA;
 
838
 
 
839
                else if(!strcmp(input, "}")) {
 
840
 
 
841
                        switch(data_type) {
 
842
 
 
843
                                case XSDDEFAULT_INFO_DATA:
 
844
                                        break;
 
845
 
 
846
                                case XSDDEFAULT_PROGRAMSTATUS_DATA:
 
847
                                        break;
 
848
 
 
849
                                case XSDDEFAULT_HOSTSTATUS_DATA:
 
850
                                        add_host_status(temp_hoststatus);
 
851
                                        temp_hoststatus = NULL;
 
852
                                        break;
 
853
 
 
854
                                case XSDDEFAULT_SERVICESTATUS_DATA:
 
855
                                        add_service_status(temp_servicestatus);
 
856
                                        temp_servicestatus = NULL;
 
857
                                        break;
 
858
 
 
859
                                case XSDDEFAULT_CONTACTSTATUS_DATA:
 
860
                                        /* unimplemented */
 
861
                                        break;
 
862
 
 
863
                                case XSDDEFAULT_HOSTCOMMENT_DATA:
 
864
                                case XSDDEFAULT_SERVICECOMMENT_DATA:
 
865
 
 
866
                                        /* add the comment */
 
867
                                        add_comment((data_type == XSDDEFAULT_HOSTCOMMENT_DATA) ? HOST_COMMENT : SERVICE_COMMENT, entry_type, host_name, service_description, entry_time, author, comment_data, comment_id, persistent, expires, expire_time, source);
 
868
 
 
869
                                        /* free temp memory */
 
870
                                        my_free(host_name);
 
871
                                        my_free(service_description);
 
872
                                        my_free(author);
 
873
                                        my_free(comment_data);
 
874
 
 
875
                                        /* reset defaults */
 
876
                                        entry_type = USER_COMMENT;
 
877
                                        comment_id = 0;
 
878
                                        source = COMMENTSOURCE_INTERNAL;
 
879
                                        persistent = FALSE;
 
880
                                        entry_time = 0L;
 
881
                                        expires = FALSE;
 
882
                                        expire_time = 0L;
 
883
 
 
884
                                        break;
 
885
 
 
886
                                case XSDDEFAULT_HOSTDOWNTIME_DATA:
 
887
                                case XSDDEFAULT_SERVICEDOWNTIME_DATA:
 
888
 
 
889
                                        /* add the downtime */
 
890
                                        if(data_type == XSDDEFAULT_HOSTDOWNTIME_DATA)
 
891
                                                add_host_downtime(host_name, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect);
 
892
                                        else
 
893
                                                add_service_downtime(host_name, service_description, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect);
 
894
 
 
895
                                        /* free temp memory */
 
896
                                        my_free(host_name);
 
897
                                        my_free(service_description);
 
898
                                        my_free(author);
 
899
                                        my_free(comment_data);
 
900
 
 
901
                                        /* reset defaults */
 
902
                                        downtime_id = 0;
 
903
                                        entry_time = 0L;
 
904
                                        start_time = 0L;
 
905
                                        end_time = 0L;
 
906
                                        fixed = FALSE;
 
907
                                        triggered_by = 0;
 
908
                                        duration = 0L;
 
909
                                        is_in_effect = FALSE;
 
910
 
 
911
                                        break;
 
912
 
 
913
                                default:
 
914
                                        break;
 
915
                                }
 
916
 
 
917
                        data_type = XSDDEFAULT_NO_DATA;
 
918
                        }
 
919
 
 
920
                else if(data_type != XSDDEFAULT_NO_DATA) {
 
921
 
 
922
                        var = strtok(input, "=");
 
923
                        val = strtok(NULL, "\n");
 
924
                        if(val == NULL)
942
925
                                continue;
943
926
 
944
 
                        switch(data_type){
945
 
 
946
 
                        case XSDDEFAULT_INFO_DATA:
947
 
                                break;
948
 
 
949
 
                        case XSDDEFAULT_PROGRAMSTATUS_DATA:
950
 
                                /* NOTE: some vars are not read, as they are not used by the CGIs (modified attributes, event handler commands, etc.) */
951
 
                                if(!strcmp(var,"nagios_pid"))
952
 
                                        nagios_pid=atoi(val);
953
 
                                else if(!strcmp(var,"daemon_mode"))
954
 
                                        daemon_mode=(atoi(val)>0)?TRUE:FALSE;
955
 
                                else if(!strcmp(var,"program_start"))
956
 
                                        program_start=strtoul(val,NULL,10);
957
 
                                else if(!strcmp(var,"last_command_check"))
958
 
                                        last_command_check=strtoul(val,NULL,10);
959
 
                                else if(!strcmp(var,"last_log_rotation"))
960
 
                                        last_log_rotation=strtoul(val,NULL,10);
961
 
                                else if(!strcmp(var,"enable_notifications"))
962
 
                                        enable_notifications=(atoi(val)>0)?TRUE:FALSE;
963
 
                                else if(!strcmp(var,"active_service_checks_enabled"))
964
 
                                        execute_service_checks=(atoi(val)>0)?TRUE:FALSE;
965
 
                                else if(!strcmp(var,"passive_service_checks_enabled"))
966
 
                                        accept_passive_service_checks=(atoi(val)>0)?TRUE:FALSE;
967
 
                                else if(!strcmp(var,"active_host_checks_enabled"))
968
 
                                        execute_host_checks=(atoi(val)>0)?TRUE:FALSE;
969
 
                                else if(!strcmp(var,"passive_host_checks_enabled"))
970
 
                                        accept_passive_host_checks=(atoi(val)>0)?TRUE:FALSE;
971
 
                                else if(!strcmp(var,"enable_event_handlers"))
972
 
                                        enable_event_handlers=(atoi(val)>0)?TRUE:FALSE;
973
 
                                else if(!strcmp(var,"obsess_over_services"))
974
 
                                        obsess_over_services=(atoi(val)>0)?TRUE:FALSE;
975
 
                                else if(!strcmp(var,"obsess_over_hosts"))
976
 
                                        obsess_over_hosts=(atoi(val)>0)?TRUE:FALSE;
977
 
                                else if(!strcmp(var,"check_service_freshness"))
978
 
                                        check_service_freshness=(atoi(val)>0)?TRUE:FALSE;
979
 
                                else if(!strcmp(var,"check_host_freshness"))
980
 
                                        check_host_freshness=(atoi(val)>0)?TRUE:FALSE;
981
 
                                else if(!strcmp(var,"enable_flap_detection"))
982
 
                                        enable_flap_detection=(atoi(val)>0)?TRUE:FALSE;
983
 
                                else if(!strcmp(var,"enable_failure_prediction"))
984
 
                                        enable_failure_prediction=(atoi(val)>0)?TRUE:FALSE;
985
 
                                else if(!strcmp(var,"process_performance_data"))
986
 
                                        process_performance_data=(atoi(val)>0)?TRUE:FALSE;
987
 
 
988
 
                                else if (!strcmp(var,"total_external_command_buffer_slots"))
989
 
                                        buffer_stats[0][0]=atoi(val);
990
 
                                else if (!strcmp(var,"used_external_command_buffer_slots"))
991
 
                                        buffer_stats[0][1]=atoi(val);
992
 
                                else if (!strcmp(var,"high_external_command_buffer_slots"))
993
 
                                        buffer_stats[0][2]=atoi(val);
994
 
 
995
 
 
996
 
                                else if (strstr(var,"_stats")){
997
 
 
998
 
                                        x=-1;
999
 
                                        if(!strcmp(var,"active_scheduled_host_check_stats"))
1000
 
                                                x=ACTIVE_SCHEDULED_HOST_CHECK_STATS;
1001
 
                                        if(!strcmp(var,"active_ondemand_host_check_stats"))
1002
 
                                                x=ACTIVE_ONDEMAND_HOST_CHECK_STATS;
1003
 
                                        if(!strcmp(var,"passive_host_check_stats"))
1004
 
                                                x=PASSIVE_HOST_CHECK_STATS;
1005
 
                                        if(!strcmp(var,"active_scheduled_service_check_stats"))
1006
 
                                                x=ACTIVE_SCHEDULED_SERVICE_CHECK_STATS;
1007
 
                                        if(!strcmp(var,"active_ondemand_service_check_stats"))
1008
 
                                                x=ACTIVE_ONDEMAND_SERVICE_CHECK_STATS;
1009
 
                                        if(!strcmp(var,"passive_service_check_stats"))
1010
 
                                                x=PASSIVE_SERVICE_CHECK_STATS;
1011
 
                                        if(!strcmp(var,"cached_host_check_stats"))
1012
 
                                                x=ACTIVE_CACHED_HOST_CHECK_STATS;
1013
 
                                        if(!strcmp(var,"cached_service_check_stats"))
1014
 
                                                x=ACTIVE_CACHED_SERVICE_CHECK_STATS;
1015
 
                                        if(!strcmp(var,"external_command_stats"))
1016
 
                                                x=EXTERNAL_COMMAND_STATS;
1017
 
                                        if(!strcmp(var,"parallel_host_check_stats"))
1018
 
                                                x=PARALLEL_HOST_CHECK_STATS;
1019
 
                                        if(!strcmp(var,"serial_host_check_stats"))
1020
 
                                                x=SERIAL_HOST_CHECK_STATS;
1021
 
 
1022
 
                                        if(x>=0){
1023
 
                                                if((ptr=strtok(val,","))){
1024
 
                                                        program_stats[x][0]=atoi(ptr);
1025
 
                                                        if((ptr=strtok(NULL,","))){
1026
 
                                                                program_stats[x][1]=atoi(ptr);
1027
 
                                                                if((ptr=strtok(NULL,"\n")))
1028
 
                                                                        program_stats[x][2]=atoi(ptr);
 
927
                        switch(data_type) {
 
928
 
 
929
                                case XSDDEFAULT_INFO_DATA:
 
930
                                        break;
 
931
 
 
932
                                case XSDDEFAULT_PROGRAMSTATUS_DATA:
 
933
                                        /* NOTE: some vars are not read, as they are not used by the CGIs (modified attributes, event handler commands, etc.) */
 
934
                                        if(!strcmp(var, "nagios_pid"))
 
935
                                                nagios_pid = atoi(val);
 
936
                                        else if(!strcmp(var, "daemon_mode"))
 
937
                                                daemon_mode = (atoi(val) > 0) ? TRUE : FALSE;
 
938
                                        else if(!strcmp(var, "program_start"))
 
939
                                                program_start = strtoul(val, NULL, 10);
 
940
                                        else if(!strcmp(var, "last_command_check"))
 
941
                                                last_command_check = strtoul(val, NULL, 10);
 
942
                                        else if(!strcmp(var, "last_log_rotation"))
 
943
                                                last_log_rotation = strtoul(val, NULL, 10);
 
944
                                        else if(!strcmp(var, "enable_notifications"))
 
945
                                                enable_notifications = (atoi(val) > 0) ? TRUE : FALSE;
 
946
                                        else if(!strcmp(var, "active_service_checks_enabled"))
 
947
                                                execute_service_checks = (atoi(val) > 0) ? TRUE : FALSE;
 
948
                                        else if(!strcmp(var, "passive_service_checks_enabled"))
 
949
                                                accept_passive_service_checks = (atoi(val) > 0) ? TRUE : FALSE;
 
950
                                        else if(!strcmp(var, "active_host_checks_enabled"))
 
951
                                                execute_host_checks = (atoi(val) > 0) ? TRUE : FALSE;
 
952
                                        else if(!strcmp(var, "passive_host_checks_enabled"))
 
953
                                                accept_passive_host_checks = (atoi(val) > 0) ? TRUE : FALSE;
 
954
                                        else if(!strcmp(var, "enable_event_handlers"))
 
955
                                                enable_event_handlers = (atoi(val) > 0) ? TRUE : FALSE;
 
956
                                        else if(!strcmp(var, "obsess_over_services"))
 
957
                                                obsess_over_services = (atoi(val) > 0) ? TRUE : FALSE;
 
958
                                        else if(!strcmp(var, "obsess_over_hosts"))
 
959
                                                obsess_over_hosts = (atoi(val) > 0) ? TRUE : FALSE;
 
960
                                        else if(!strcmp(var, "check_service_freshness"))
 
961
                                                check_service_freshness = (atoi(val) > 0) ? TRUE : FALSE;
 
962
                                        else if(!strcmp(var, "check_host_freshness"))
 
963
                                                check_host_freshness = (atoi(val) > 0) ? TRUE : FALSE;
 
964
                                        else if(!strcmp(var, "enable_flap_detection"))
 
965
                                                enable_flap_detection = (atoi(val) > 0) ? TRUE : FALSE;
 
966
                                        else if(!strcmp(var, "enable_failure_prediction"))
 
967
                                                enable_failure_prediction = (atoi(val) > 0) ? TRUE : FALSE;
 
968
                                        else if(!strcmp(var, "process_performance_data"))
 
969
                                                process_performance_data = (atoi(val) > 0) ? TRUE : FALSE;
 
970
 
 
971
                                        else if(!strcmp(var, "total_external_command_buffer_slots"))
 
972
                                                buffer_stats[0][0] = atoi(val);
 
973
                                        else if(!strcmp(var, "used_external_command_buffer_slots"))
 
974
                                                buffer_stats[0][1] = atoi(val);
 
975
                                        else if(!strcmp(var, "high_external_command_buffer_slots"))
 
976
                                                buffer_stats[0][2] = atoi(val);
 
977
 
 
978
 
 
979
                                        else if(strstr(var, "_stats")) {
 
980
 
 
981
                                                x = -1;
 
982
                                                if(!strcmp(var, "active_scheduled_host_check_stats"))
 
983
                                                        x = ACTIVE_SCHEDULED_HOST_CHECK_STATS;
 
984
                                                if(!strcmp(var, "active_ondemand_host_check_stats"))
 
985
                                                        x = ACTIVE_ONDEMAND_HOST_CHECK_STATS;
 
986
                                                if(!strcmp(var, "passive_host_check_stats"))
 
987
                                                        x = PASSIVE_HOST_CHECK_STATS;
 
988
                                                if(!strcmp(var, "active_scheduled_service_check_stats"))
 
989
                                                        x = ACTIVE_SCHEDULED_SERVICE_CHECK_STATS;
 
990
                                                if(!strcmp(var, "active_ondemand_service_check_stats"))
 
991
                                                        x = ACTIVE_ONDEMAND_SERVICE_CHECK_STATS;
 
992
                                                if(!strcmp(var, "passive_service_check_stats"))
 
993
                                                        x = PASSIVE_SERVICE_CHECK_STATS;
 
994
                                                if(!strcmp(var, "cached_host_check_stats"))
 
995
                                                        x = ACTIVE_CACHED_HOST_CHECK_STATS;
 
996
                                                if(!strcmp(var, "cached_service_check_stats"))
 
997
                                                        x = ACTIVE_CACHED_SERVICE_CHECK_STATS;
 
998
                                                if(!strcmp(var, "external_command_stats"))
 
999
                                                        x = EXTERNAL_COMMAND_STATS;
 
1000
                                                if(!strcmp(var, "parallel_host_check_stats"))
 
1001
                                                        x = PARALLEL_HOST_CHECK_STATS;
 
1002
                                                if(!strcmp(var, "serial_host_check_stats"))
 
1003
                                                        x = SERIAL_HOST_CHECK_STATS;
 
1004
 
 
1005
                                                if(x >= 0) {
 
1006
                                                        if((ptr = strtok(val, ","))) {
 
1007
                                                                program_stats[x][0] = atoi(ptr);
 
1008
                                                                if((ptr = strtok(NULL, ","))) {
 
1009
                                                                        program_stats[x][1] = atoi(ptr);
 
1010
                                                                        if((ptr = strtok(NULL, "\n")))
 
1011
                                                                                program_stats[x][2] = atoi(ptr);
 
1012
                                                                        }
1029
1013
                                                                }
1030
1014
                                                        }
1031
1015
                                                }
1032
 
                                        }
1033
 
                                break;
1034
 
 
1035
 
                        case XSDDEFAULT_HOSTSTATUS_DATA:
1036
 
                                /* NOTE: some vars are not read, as they are not used by the CGIs (modified attributes, event handler commands, etc.) */
1037
 
                                if(temp_hoststatus!=NULL){
1038
 
                                        if(!strcmp(var,"host_name"))
1039
 
                                                temp_hoststatus->host_name=(char *)strdup(val);
1040
 
                                        else if(!strcmp(var,"has_been_checked"))
1041
 
                                                temp_hoststatus->has_been_checked=(atoi(val)>0)?TRUE:FALSE;
1042
 
                                        else if(!strcmp(var,"should_be_scheduled"))
1043
 
                                                temp_hoststatus->should_be_scheduled=(atoi(val)>0)?TRUE:FALSE;
1044
 
                                        else if(!strcmp(var,"check_execution_time"))
1045
 
                                                temp_hoststatus->execution_time=strtod(val,NULL);
1046
 
                                        else if(!strcmp(var,"check_latency"))
1047
 
                                                temp_hoststatus->latency=strtod(val,NULL);
1048
 
                                        else if(!strcmp(var,"check_type"))
1049
 
                                                temp_hoststatus->check_type=atoi(val);
1050
 
                                        else if(!strcmp(var,"current_state"))
1051
 
                                                temp_hoststatus->status=atoi(val);
1052
 
                                        else if(!strcmp(var,"last_hard_state"))
1053
 
                                                temp_hoststatus->last_hard_state=atoi(val);
1054
 
                                        else if(!strcmp(var,"plugin_output")){
1055
 
                                                temp_hoststatus->plugin_output=(char *)strdup(val);
1056
 
                                                unescape_newlines(temp_hoststatus->plugin_output);
1057
 
                                                }
1058
 
                                        else if(!strcmp(var,"long_plugin_output")){
1059
 
                                                temp_hoststatus->long_plugin_output=(char *)strdup(val);
1060
 
                                                unescape_newlines(temp_hoststatus->long_plugin_output);
1061
 
                                                }
1062
 
                                        else if(!strcmp(var,"performance_data"))
1063
 
                                                temp_hoststatus->perf_data=(char *)strdup(val);
1064
 
                                        else if(!strcmp(var,"current_attempt"))
1065
 
                                                temp_hoststatus->current_attempt=atoi(val);
1066
 
                                        else if(!strcmp(var,"max_attempts"))
1067
 
                                                temp_hoststatus->max_attempts=atoi(val);
1068
 
                                        else if(!strcmp(var,"last_check"))
1069
 
                                                temp_hoststatus->last_check=strtoul(val,NULL,10);
1070
 
                                        else if(!strcmp(var,"next_check"))
1071
 
                                                temp_hoststatus->next_check=strtoul(val,NULL,10);
1072
 
                                        else if(!strcmp(var,"check_options"))
1073
 
                                                temp_hoststatus->check_options=atoi(val);
1074
 
                                        else if(!strcmp(var,"current_attempt"))
1075
 
                                                temp_hoststatus->current_attempt=(atoi(val)>0)?TRUE:FALSE;
1076
 
                                        else if(!strcmp(var,"state_type"))
1077
 
                                                temp_hoststatus->state_type=atoi(val);
1078
 
                                        else if(!strcmp(var,"last_state_change"))
1079
 
                                                temp_hoststatus->last_state_change=strtoul(val,NULL,10);
1080
 
                                        else if(!strcmp(var,"last_hard_state_change"))
1081
 
                                                temp_hoststatus->last_hard_state_change=strtoul(val,NULL,10);
1082
 
                                        else if(!strcmp(var,"last_time_up"))
1083
 
                                                temp_hoststatus->last_time_up=strtoul(val,NULL,10);
1084
 
                                        else if(!strcmp(var,"last_time_down"))
1085
 
                                                temp_hoststatus->last_time_down=strtoul(val,NULL,10);
1086
 
                                        else if(!strcmp(var,"last_time_unreachable"))
1087
 
                                                temp_hoststatus->last_time_unreachable=strtoul(val,NULL,10);
1088
 
                                        else if(!strcmp(var,"last_notification"))
1089
 
                                                temp_hoststatus->last_notification=strtoul(val,NULL,10);
1090
 
                                        else if(!strcmp(var,"next_notification"))
1091
 
                                                temp_hoststatus->next_notification=strtoul(val,NULL,10);
1092
 
                                        else if(!strcmp(var,"no_more_notifications"))
1093
 
                                                temp_hoststatus->no_more_notifications=(atoi(val)>0)?TRUE:FALSE;
1094
 
                                        else if(!strcmp(var,"current_notification_number"))
1095
 
                                                temp_hoststatus->current_notification_number=atoi(val);
1096
 
                                        else if(!strcmp(var,"notifications_enabled"))
1097
 
                                                temp_hoststatus->notifications_enabled=(atoi(val)>0)?TRUE:FALSE;
1098
 
                                        else if(!strcmp(var,"problem_has_been_acknowledged"))
1099
 
                                                temp_hoststatus->problem_has_been_acknowledged=(atoi(val)>0)?TRUE:FALSE;
1100
 
                                        else if(!strcmp(var,"acknowledgement_type"))
1101
 
                                                temp_hoststatus->acknowledgement_type=atoi(val);
1102
 
                                        else if(!strcmp(var,"active_checks_enabled"))
1103
 
                                                temp_hoststatus->checks_enabled=(atoi(val)>0)?TRUE:FALSE;
1104
 
                                        else if(!strcmp(var,"passive_checks_enabled"))
1105
 
                                                temp_hoststatus->accept_passive_host_checks=(atoi(val)>0)?TRUE:FALSE;
1106
 
                                        else if(!strcmp(var,"event_handler_enabled"))
1107
 
                                                temp_hoststatus->event_handler_enabled=(atoi(val)>0)?TRUE:FALSE;
1108
 
                                        else if(!strcmp(var,"flap_detection_enabled"))
1109
 
                                                temp_hoststatus->flap_detection_enabled=(atoi(val)>0)?TRUE:FALSE;
1110
 
                                        else if(!strcmp(var,"failure_prediction_enabled"))
1111
 
                                                temp_hoststatus->failure_prediction_enabled=(atoi(val)>0)?TRUE:FALSE;
1112
 
                                        else if(!strcmp(var,"process_performance_data"))
1113
 
                                                temp_hoststatus->process_performance_data=(atoi(val)>0)?TRUE:FALSE;
1114
 
                                        else if(!strcmp(var,"obsess_over_host"))
1115
 
                                                temp_hoststatus->obsess_over_host=(atoi(val)>0)?TRUE:FALSE;
1116
 
                                        else if(!strcmp(var,"last_update"))
1117
 
                                                temp_hoststatus->last_update=strtoul(val,NULL,10);
1118
 
                                        else if(!strcmp(var,"is_flapping"))
1119
 
                                                temp_hoststatus->is_flapping=(atoi(val)>0)?TRUE:FALSE;
1120
 
                                        else if(!strcmp(var,"percent_state_change"))
1121
 
                                                temp_hoststatus->percent_state_change=strtod(val,NULL);
1122
 
                                        else if(!strcmp(var,"scheduled_downtime_depth"))
1123
 
                                                temp_hoststatus->scheduled_downtime_depth=atoi(val);
1124
 
                                        /*
1125
 
                                        else if(!strcmp(var,"state_history")){
1126
 
                                                temp_ptr=val;
1127
 
                                                for(x=0;x<MAX_STATE_HISTORY_ENTRIES;x++)
1128
 
                                                        temp_hoststatus->state_history[x]=atoi(my_strsep(&temp_ptr,","));
1129
 
                                                temp_hoststatus->state_history_index=0;
1130
 
                                                }
1131
 
                                        */
1132
 
                                        }
1133
 
                                break;
1134
 
 
1135
 
                        case XSDDEFAULT_SERVICESTATUS_DATA:
1136
 
                                /* NOTE: some vars are not read, as they are not used by the CGIs (modified attributes, event handler commands, etc.) */
1137
 
                                if(temp_servicestatus!=NULL){
1138
 
                                        if(!strcmp(var,"host_name"))
1139
 
                                                temp_servicestatus->host_name=(char *)strdup(val);
1140
 
                                        else if(!strcmp(var,"service_description"))
1141
 
                                                temp_servicestatus->description=(char *)strdup(val);
1142
 
                                        else if(!strcmp(var,"has_been_checked"))
1143
 
                                                temp_servicestatus->has_been_checked=(atoi(val)>0)?TRUE:FALSE;
1144
 
                                        else if(!strcmp(var,"should_be_scheduled"))
1145
 
                                                temp_servicestatus->should_be_scheduled=(atoi(val)>0)?TRUE:FALSE;
1146
 
                                        else if(!strcmp(var,"check_execution_time"))
1147
 
                                                temp_servicestatus->execution_time=strtod(val,NULL);
1148
 
                                        else if(!strcmp(var,"check_latency"))
1149
 
                                                temp_servicestatus->latency=strtod(val,NULL);
1150
 
                                        else if(!strcmp(var,"check_type"))
1151
 
                                                temp_servicestatus->check_type=atoi(val);
1152
 
                                        else if(!strcmp(var,"current_state"))
1153
 
                                                temp_servicestatus->status=atoi(val);
1154
 
                                        else if(!strcmp(var,"last_hard_state"))
1155
 
                                                temp_servicestatus->last_hard_state=atoi(val);
1156
 
                                        else if(!strcmp(var,"current_attempt"))
1157
 
                                                temp_servicestatus->current_attempt=atoi(val);
1158
 
                                        else if(!strcmp(var,"max_attempts"))
1159
 
                                                temp_servicestatus->max_attempts=atoi(val);
1160
 
                                        else if(!strcmp(var,"state_type"))
1161
 
                                                temp_servicestatus->state_type=atoi(val);
1162
 
                                        else if(!strcmp(var,"last_state_change"))
1163
 
                                                temp_servicestatus->last_state_change=strtoul(val,NULL,10);
1164
 
                                        else if(!strcmp(var,"last_hard_state_change"))
1165
 
                                                temp_servicestatus->last_hard_state_change=strtoul(val,NULL,10);
1166
 
                                        else if(!strcmp(var,"last_time_ok"))
1167
 
                                                temp_servicestatus->last_time_ok=strtoul(val,NULL,10);
1168
 
                                        else if(!strcmp(var,"last_time_warning"))
1169
 
                                                temp_servicestatus->last_time_warning=strtoul(val,NULL,10);
1170
 
                                        else if(!strcmp(var,"last_time_unknown"))
1171
 
                                                temp_servicestatus->last_time_unknown=strtoul(val,NULL,10);
1172
 
                                        else if(!strcmp(var,"last_time_critical"))
1173
 
                                                temp_servicestatus->last_time_critical=strtoul(val,NULL,10);
1174
 
                                        else if(!strcmp(var,"plugin_output")){
1175
 
                                                temp_servicestatus->plugin_output=(char *)strdup(val);
1176
 
                                                unescape_newlines(temp_servicestatus->plugin_output);
1177
 
                                                }
1178
 
                                        else if(!strcmp(var,"long_plugin_output")){
1179
 
                                                temp_servicestatus->long_plugin_output=(char *)strdup(val);
1180
 
                                                unescape_newlines(temp_servicestatus->long_plugin_output);
1181
 
                                                }
1182
 
                                        else if(!strcmp(var,"performance_data"))
1183
 
                                                temp_servicestatus->perf_data=(char *)strdup(val);
1184
 
                                        else if(!strcmp(var,"last_check"))
1185
 
                                                temp_servicestatus->last_check=strtoul(val,NULL,10);
1186
 
                                        else if(!strcmp(var,"next_check"))
1187
 
                                                temp_servicestatus->next_check=strtoul(val,NULL,10);
1188
 
                                        else if(!strcmp(var,"check_options"))
1189
 
                                                temp_servicestatus->check_options=atoi(val);
1190
 
                                        else if(!strcmp(var,"current_notification_number"))
1191
 
                                                temp_servicestatus->current_notification_number=atoi(val);
1192
 
                                        else if(!strcmp(var,"last_notification"))
1193
 
                                                temp_servicestatus->last_notification=strtoul(val,NULL,10);
1194
 
                                        else if(!strcmp(var,"next_notification"))
1195
 
                                                temp_servicestatus->next_notification=strtoul(val,NULL,10);
1196
 
                                        else if(!strcmp(var,"no_more_notifications"))
1197
 
                                                temp_servicestatus->no_more_notifications=(atoi(val)>0)?TRUE:FALSE;
1198
 
                                        else if(!strcmp(var,"notifications_enabled"))
1199
 
                                                temp_servicestatus->notifications_enabled=(atoi(val)>0)?TRUE:FALSE;
1200
 
                                        else if(!strcmp(var,"active_checks_enabled"))
1201
 
                                                temp_servicestatus->checks_enabled=(atoi(val)>0)?TRUE:FALSE;
1202
 
                                        else if(!strcmp(var,"passive_checks_enabled"))
1203
 
                                                temp_servicestatus->accept_passive_service_checks=(atoi(val)>0)?TRUE:FALSE;
1204
 
                                        else if(!strcmp(var,"event_handler_enabled"))
1205
 
                                                temp_servicestatus->event_handler_enabled=(atoi(val)>0)?TRUE:FALSE;
1206
 
                                        else if(!strcmp(var,"problem_has_been_acknowledged"))
1207
 
                                                temp_servicestatus->problem_has_been_acknowledged=(atoi(val)>0)?TRUE:FALSE;
1208
 
                                        else if(!strcmp(var,"acknowledgement_type"))
1209
 
                                                temp_servicestatus->acknowledgement_type=atoi(val);
1210
 
                                        else if(!strcmp(var,"flap_detection_enabled"))
1211
 
                                                temp_servicestatus->flap_detection_enabled=(atoi(val)>0)?TRUE:FALSE;
1212
 
                                        else if(!strcmp(var,"failure_prediction_enabled"))
1213
 
                                                temp_servicestatus->failure_prediction_enabled=(atoi(val)>0)?TRUE:FALSE;
1214
 
                                        else if(!strcmp(var,"process_performance_data"))
1215
 
                                                temp_servicestatus->process_performance_data=(atoi(val)>0)?TRUE:FALSE;
1216
 
                                        else if(!strcmp(var,"obsess_over_service"))
1217
 
                                                temp_servicestatus->obsess_over_service=(atoi(val)>0)?TRUE:FALSE;
1218
 
                                        else if(!strcmp(var,"last_update"))
1219
 
                                                temp_servicestatus->last_update=strtoul(val,NULL,10);
1220
 
                                        else if(!strcmp(var,"is_flapping"))
1221
 
                                                temp_servicestatus->is_flapping=(atoi(val)>0)?TRUE:FALSE;
1222
 
                                        else if(!strcmp(var,"percent_state_change"))
1223
 
                                                temp_servicestatus->percent_state_change=strtod(val,NULL);
1224
 
                                        else if(!strcmp(var,"scheduled_downtime_depth"))
1225
 
                                                temp_servicestatus->scheduled_downtime_depth=atoi(val);
1226
 
                                        /*
1227
 
                                        else if(!strcmp(var,"state_history")){
1228
 
                                                temp_ptr=val;
1229
 
                                                for(x=0;x<MAX_STATE_HISTORY_ENTRIES;x++)
1230
 
                                                        temp_servicestatus->state_history[x]=atoi(my_strsep(&temp_ptr,","));
1231
 
                                                temp_servicestatus->state_history_index=0;
1232
 
                                                }
1233
 
                                        */
1234
 
                                        }
1235
 
                                break;
1236
 
 
1237
 
                        case XSDDEFAULT_CONTACTSTATUS_DATA:
1238
 
                                /* unimplemented */
1239
 
                                break;
1240
 
 
1241
 
                        case XSDDEFAULT_HOSTCOMMENT_DATA:
1242
 
                        case XSDDEFAULT_SERVICECOMMENT_DATA:
1243
 
                                if(!strcmp(var,"host_name"))
1244
 
                                        host_name=(char *)strdup(val);
1245
 
                                else if(!strcmp(var,"service_description"))
1246
 
                                        service_description=(char *)strdup(val);
1247
 
                                else if(!strcmp(var,"entry_type"))
1248
 
                                        entry_type=atoi(val);
1249
 
                                else if(!strcmp(var,"comment_id"))
1250
 
                                        comment_id=strtoul(val,NULL,10);
1251
 
                                else if(!strcmp(var,"source"))
1252
 
                                        source=atoi(val);
1253
 
                                else if(!strcmp(var,"persistent"))
1254
 
                                        persistent=(atoi(val)>0)?TRUE:FALSE;
1255
 
                                else if(!strcmp(var,"entry_time"))
1256
 
                                        entry_time=strtoul(val,NULL,10);
1257
 
                                else if(!strcmp(var,"expires"))
1258
 
                                        expires=(atoi(val)>0)?TRUE:FALSE;
1259
 
                                else if(!strcmp(var,"expire_time"))
1260
 
                                        expire_time=strtoul(val,NULL,10);
1261
 
                                else if(!strcmp(var,"author"))
1262
 
                                        author=(char *)strdup(val);
1263
 
                                else if(!strcmp(var,"comment_data"))
1264
 
                                        comment_data=(char *)strdup(val);
1265
 
                                break;
1266
 
 
1267
 
                        case XSDDEFAULT_HOSTDOWNTIME_DATA:
1268
 
                        case XSDDEFAULT_SERVICEDOWNTIME_DATA:
1269
 
                                if(!strcmp(var,"host_name"))
1270
 
                                        host_name=(char *)strdup(val);
1271
 
                                else if(!strcmp(var,"service_description"))
1272
 
                                        service_description=(char *)strdup(val);
1273
 
                                else if(!strcmp(var,"downtime_id"))
1274
 
                                        downtime_id=strtoul(val,NULL,10);
1275
 
                                else if(!strcmp(var,"entry_time"))
1276
 
                                        entry_time=strtoul(val,NULL,10);
1277
 
                                else if(!strcmp(var,"start_time"))
1278
 
                                        start_time=strtoul(val,NULL,10);
1279
 
                                else if(!strcmp(var,"end_time"))
1280
 
                                        end_time=strtoul(val,NULL,10);
1281
 
                                else if(!strcmp(var,"fixed"))
1282
 
                                        fixed=(atoi(val)>0)?TRUE:FALSE;
1283
 
                                else if(!strcmp(var,"triggered_by"))
1284
 
                                        triggered_by=strtoul(val,NULL,10);
1285
 
                                else if(!strcmp(var,"duration"))
1286
 
                                        duration=strtoul(val,NULL,10);
1287
 
                                else if(!strcmp(var,"author"))
1288
 
                                        author=(char *)strdup(val);
1289
 
                                else if(!strcmp(var,"comment"))
1290
 
                                        comment_data=(char *)strdup(val);
1291
 
                                break;
1292
 
 
1293
 
                        default:
1294
 
                                break;
1295
 
                                }
1296
 
 
1297
 
                        }
1298
 
                }
 
1016
                                        break;
 
1017
 
 
1018
                                case XSDDEFAULT_HOSTSTATUS_DATA:
 
1019
                                        /* NOTE: some vars are not read, as they are not used by the CGIs (modified attributes, event handler commands, etc.) */
 
1020
                                        if(temp_hoststatus != NULL) {
 
1021
                                                if(!strcmp(var, "host_name"))
 
1022
                                                        temp_hoststatus->host_name = (char *)strdup(val);
 
1023
                                                else if(!strcmp(var, "has_been_checked"))
 
1024
                                                        temp_hoststatus->has_been_checked = (atoi(val) > 0) ? TRUE : FALSE;
 
1025
                                                else if(!strcmp(var, "should_be_scheduled"))
 
1026
                                                        temp_hoststatus->should_be_scheduled = (atoi(val) > 0) ? TRUE : FALSE;
 
1027
                                                else if(!strcmp(var, "check_execution_time"))
 
1028
                                                        temp_hoststatus->execution_time = strtod(val, NULL);
 
1029
                                                else if(!strcmp(var, "check_latency"))
 
1030
                                                        temp_hoststatus->latency = strtod(val, NULL);
 
1031
                                                else if(!strcmp(var, "check_type"))
 
1032
                                                        temp_hoststatus->check_type = atoi(val);
 
1033
                                                else if(!strcmp(var, "current_state"))
 
1034
                                                        temp_hoststatus->status = atoi(val);
 
1035
                                                else if(!strcmp(var, "last_hard_state"))
 
1036
                                                        temp_hoststatus->last_hard_state = atoi(val);
 
1037
                                                else if(!strcmp(var, "plugin_output")) {
 
1038
                                                        temp_hoststatus->plugin_output = (char *)strdup(val);
 
1039
                                                        unescape_newlines(temp_hoststatus->plugin_output);
 
1040
                                                        }
 
1041
                                                else if(!strcmp(var, "long_plugin_output")) {
 
1042
                                                        temp_hoststatus->long_plugin_output = (char *)strdup(val);
 
1043
                                                        unescape_newlines(temp_hoststatus->long_plugin_output);
 
1044
                                                        }
 
1045
                                                else if(!strcmp(var, "performance_data"))
 
1046
                                                        temp_hoststatus->perf_data = (char *)strdup(val);
 
1047
                                                else if(!strcmp(var, "current_attempt"))
 
1048
                                                        temp_hoststatus->current_attempt = atoi(val);
 
1049
                                                else if(!strcmp(var, "max_attempts"))
 
1050
                                                        temp_hoststatus->max_attempts = atoi(val);
 
1051
                                                else if(!strcmp(var, "last_check"))
 
1052
                                                        temp_hoststatus->last_check = strtoul(val, NULL, 10);
 
1053
                                                else if(!strcmp(var, "next_check"))
 
1054
                                                        temp_hoststatus->next_check = strtoul(val, NULL, 10);
 
1055
                                                else if(!strcmp(var, "check_options"))
 
1056
                                                        temp_hoststatus->check_options = atoi(val);
 
1057
                                                else if(!strcmp(var, "current_attempt"))
 
1058
                                                        temp_hoststatus->current_attempt = (atoi(val) > 0) ? TRUE : FALSE;
 
1059
                                                else if(!strcmp(var, "state_type"))
 
1060
                                                        temp_hoststatus->state_type = atoi(val);
 
1061
                                                else if(!strcmp(var, "last_state_change"))
 
1062
                                                        temp_hoststatus->last_state_change = strtoul(val, NULL, 10);
 
1063
                                                else if(!strcmp(var, "last_hard_state_change"))
 
1064
                                                        temp_hoststatus->last_hard_state_change = strtoul(val, NULL, 10);
 
1065
                                                else if(!strcmp(var, "last_time_up"))
 
1066
                                                        temp_hoststatus->last_time_up = strtoul(val, NULL, 10);
 
1067
                                                else if(!strcmp(var, "last_time_down"))
 
1068
                                                        temp_hoststatus->last_time_down = strtoul(val, NULL, 10);
 
1069
                                                else if(!strcmp(var, "last_time_unreachable"))
 
1070
                                                        temp_hoststatus->last_time_unreachable = strtoul(val, NULL, 10);
 
1071
                                                else if(!strcmp(var, "last_notification"))
 
1072
                                                        temp_hoststatus->last_notification = strtoul(val, NULL, 10);
 
1073
                                                else if(!strcmp(var, "next_notification"))
 
1074
                                                        temp_hoststatus->next_notification = strtoul(val, NULL, 10);
 
1075
                                                else if(!strcmp(var, "no_more_notifications"))
 
1076
                                                        temp_hoststatus->no_more_notifications = (atoi(val) > 0) ? TRUE : FALSE;
 
1077
                                                else if(!strcmp(var, "current_notification_number"))
 
1078
                                                        temp_hoststatus->current_notification_number = atoi(val);
 
1079
                                                else if(!strcmp(var, "notifications_enabled"))
 
1080
                                                        temp_hoststatus->notifications_enabled = (atoi(val) > 0) ? TRUE : FALSE;
 
1081
                                                else if(!strcmp(var, "problem_has_been_acknowledged"))
 
1082
                                                        temp_hoststatus->problem_has_been_acknowledged = (atoi(val) > 0) ? TRUE : FALSE;
 
1083
                                                else if(!strcmp(var, "acknowledgement_type"))
 
1084
                                                        temp_hoststatus->acknowledgement_type = atoi(val);
 
1085
                                                else if(!strcmp(var, "active_checks_enabled"))
 
1086
                                                        temp_hoststatus->checks_enabled = (atoi(val) > 0) ? TRUE : FALSE;
 
1087
                                                else if(!strcmp(var, "passive_checks_enabled"))
 
1088
                                                        temp_hoststatus->accept_passive_host_checks = (atoi(val) > 0) ? TRUE : FALSE;
 
1089
                                                else if(!strcmp(var, "event_handler_enabled"))
 
1090
                                                        temp_hoststatus->event_handler_enabled = (atoi(val) > 0) ? TRUE : FALSE;
 
1091
                                                else if(!strcmp(var, "flap_detection_enabled"))
 
1092
                                                        temp_hoststatus->flap_detection_enabled = (atoi(val) > 0) ? TRUE : FALSE;
 
1093
                                                else if(!strcmp(var, "failure_prediction_enabled"))
 
1094
                                                        temp_hoststatus->failure_prediction_enabled = (atoi(val) > 0) ? TRUE : FALSE;
 
1095
                                                else if(!strcmp(var, "process_performance_data"))
 
1096
                                                        temp_hoststatus->process_performance_data = (atoi(val) > 0) ? TRUE : FALSE;
 
1097
                                                else if(!strcmp(var, "obsess_over_host"))
 
1098
                                                        temp_hoststatus->obsess_over_host = (atoi(val) > 0) ? TRUE : FALSE;
 
1099
                                                else if(!strcmp(var, "last_update"))
 
1100
                                                        temp_hoststatus->last_update = strtoul(val, NULL, 10);
 
1101
                                                else if(!strcmp(var, "is_flapping"))
 
1102
                                                        temp_hoststatus->is_flapping = (atoi(val) > 0) ? TRUE : FALSE;
 
1103
                                                else if(!strcmp(var, "percent_state_change"))
 
1104
                                                        temp_hoststatus->percent_state_change = strtod(val, NULL);
 
1105
                                                else if(!strcmp(var, "scheduled_downtime_depth"))
 
1106
                                                        temp_hoststatus->scheduled_downtime_depth = atoi(val);
 
1107
                                                /*
 
1108
                                                else if(!strcmp(var,"state_history")){
 
1109
                                                        temp_ptr=val;
 
1110
                                                        for(x=0;x<MAX_STATE_HISTORY_ENTRIES;x++)
 
1111
                                                                temp_hoststatus->state_history[x]=atoi(my_strsep(&temp_ptr,","));
 
1112
                                                        temp_hoststatus->state_history_index=0;
 
1113
                                                        }
 
1114
                                                */
 
1115
                                                }
 
1116
                                        break;
 
1117
 
 
1118
                                case XSDDEFAULT_SERVICESTATUS_DATA:
 
1119
                                        /* NOTE: some vars are not read, as they are not used by the CGIs (modified attributes, event handler commands, etc.) */
 
1120
                                        if(temp_servicestatus != NULL) {
 
1121
                                                if(!strcmp(var, "host_name"))
 
1122
                                                        temp_servicestatus->host_name = (char *)strdup(val);
 
1123
                                                else if(!strcmp(var, "service_description"))
 
1124
                                                        temp_servicestatus->description = (char *)strdup(val);
 
1125
                                                else if(!strcmp(var, "has_been_checked"))
 
1126
                                                        temp_servicestatus->has_been_checked = (atoi(val) > 0) ? TRUE : FALSE;
 
1127
                                                else if(!strcmp(var, "should_be_scheduled"))
 
1128
                                                        temp_servicestatus->should_be_scheduled = (atoi(val) > 0) ? TRUE : FALSE;
 
1129
                                                else if(!strcmp(var, "check_execution_time"))
 
1130
                                                        temp_servicestatus->execution_time = strtod(val, NULL);
 
1131
                                                else if(!strcmp(var, "check_latency"))
 
1132
                                                        temp_servicestatus->latency = strtod(val, NULL);
 
1133
                                                else if(!strcmp(var, "check_type"))
 
1134
                                                        temp_servicestatus->check_type = atoi(val);
 
1135
                                                else if(!strcmp(var, "current_state"))
 
1136
                                                        temp_servicestatus->status = atoi(val);
 
1137
                                                else if(!strcmp(var, "last_hard_state"))
 
1138
                                                        temp_servicestatus->last_hard_state = atoi(val);
 
1139
                                                else if(!strcmp(var, "current_attempt"))
 
1140
                                                        temp_servicestatus->current_attempt = atoi(val);
 
1141
                                                else if(!strcmp(var, "max_attempts"))
 
1142
                                                        temp_servicestatus->max_attempts = atoi(val);
 
1143
                                                else if(!strcmp(var, "state_type"))
 
1144
                                                        temp_servicestatus->state_type = atoi(val);
 
1145
                                                else if(!strcmp(var, "last_state_change"))
 
1146
                                                        temp_servicestatus->last_state_change = strtoul(val, NULL, 10);
 
1147
                                                else if(!strcmp(var, "last_hard_state_change"))
 
1148
                                                        temp_servicestatus->last_hard_state_change = strtoul(val, NULL, 10);
 
1149
                                                else if(!strcmp(var, "last_time_ok"))
 
1150
                                                        temp_servicestatus->last_time_ok = strtoul(val, NULL, 10);
 
1151
                                                else if(!strcmp(var, "last_time_warning"))
 
1152
                                                        temp_servicestatus->last_time_warning = strtoul(val, NULL, 10);
 
1153
                                                else if(!strcmp(var, "last_time_unknown"))
 
1154
                                                        temp_servicestatus->last_time_unknown = strtoul(val, NULL, 10);
 
1155
                                                else if(!strcmp(var, "last_time_critical"))
 
1156
                                                        temp_servicestatus->last_time_critical = strtoul(val, NULL, 10);
 
1157
                                                else if(!strcmp(var, "plugin_output")) {
 
1158
                                                        temp_servicestatus->plugin_output = (char *)strdup(val);
 
1159
                                                        unescape_newlines(temp_servicestatus->plugin_output);
 
1160
                                                        }
 
1161
                                                else if(!strcmp(var, "long_plugin_output")) {
 
1162
                                                        temp_servicestatus->long_plugin_output = (char *)strdup(val);
 
1163
                                                        unescape_newlines(temp_servicestatus->long_plugin_output);
 
1164
                                                        }
 
1165
                                                else if(!strcmp(var, "performance_data"))
 
1166
                                                        temp_servicestatus->perf_data = (char *)strdup(val);
 
1167
                                                else if(!strcmp(var, "last_check"))
 
1168
                                                        temp_servicestatus->last_check = strtoul(val, NULL, 10);
 
1169
                                                else if(!strcmp(var, "next_check"))
 
1170
                                                        temp_servicestatus->next_check = strtoul(val, NULL, 10);
 
1171
                                                else if(!strcmp(var, "check_options"))
 
1172
                                                        temp_servicestatus->check_options = atoi(val);
 
1173
                                                else if(!strcmp(var, "current_notification_number"))
 
1174
                                                        temp_servicestatus->current_notification_number = atoi(val);
 
1175
                                                else if(!strcmp(var, "last_notification"))
 
1176
                                                        temp_servicestatus->last_notification = strtoul(val, NULL, 10);
 
1177
                                                else if(!strcmp(var, "next_notification"))
 
1178
                                                        temp_servicestatus->next_notification = strtoul(val, NULL, 10);
 
1179
                                                else if(!strcmp(var, "no_more_notifications"))
 
1180
                                                        temp_servicestatus->no_more_notifications = (atoi(val) > 0) ? TRUE : FALSE;
 
1181
                                                else if(!strcmp(var, "notifications_enabled"))
 
1182
                                                        temp_servicestatus->notifications_enabled = (atoi(val) > 0) ? TRUE : FALSE;
 
1183
                                                else if(!strcmp(var, "active_checks_enabled"))
 
1184
                                                        temp_servicestatus->checks_enabled = (atoi(val) > 0) ? TRUE : FALSE;
 
1185
                                                else if(!strcmp(var, "passive_checks_enabled"))
 
1186
                                                        temp_servicestatus->accept_passive_service_checks = (atoi(val) > 0) ? TRUE : FALSE;
 
1187
                                                else if(!strcmp(var, "event_handler_enabled"))
 
1188
                                                        temp_servicestatus->event_handler_enabled = (atoi(val) > 0) ? TRUE : FALSE;
 
1189
                                                else if(!strcmp(var, "problem_has_been_acknowledged"))
 
1190
                                                        temp_servicestatus->problem_has_been_acknowledged = (atoi(val) > 0) ? TRUE : FALSE;
 
1191
                                                else if(!strcmp(var, "acknowledgement_type"))
 
1192
                                                        temp_servicestatus->acknowledgement_type = atoi(val);
 
1193
                                                else if(!strcmp(var, "flap_detection_enabled"))
 
1194
                                                        temp_servicestatus->flap_detection_enabled = (atoi(val) > 0) ? TRUE : FALSE;
 
1195
                                                else if(!strcmp(var, "failure_prediction_enabled"))
 
1196
                                                        temp_servicestatus->failure_prediction_enabled = (atoi(val) > 0) ? TRUE : FALSE;
 
1197
                                                else if(!strcmp(var, "process_performance_data"))
 
1198
                                                        temp_servicestatus->process_performance_data = (atoi(val) > 0) ? TRUE : FALSE;
 
1199
                                                else if(!strcmp(var, "obsess_over_service"))
 
1200
                                                        temp_servicestatus->obsess_over_service = (atoi(val) > 0) ? TRUE : FALSE;
 
1201
                                                else if(!strcmp(var, "last_update"))
 
1202
                                                        temp_servicestatus->last_update = strtoul(val, NULL, 10);
 
1203
                                                else if(!strcmp(var, "is_flapping"))
 
1204
                                                        temp_servicestatus->is_flapping = (atoi(val) > 0) ? TRUE : FALSE;
 
1205
                                                else if(!strcmp(var, "percent_state_change"))
 
1206
                                                        temp_servicestatus->percent_state_change = strtod(val, NULL);
 
1207
                                                else if(!strcmp(var, "scheduled_downtime_depth"))
 
1208
                                                        temp_servicestatus->scheduled_downtime_depth = atoi(val);
 
1209
                                                /*
 
1210
                                                else if(!strcmp(var,"state_history")){
 
1211
                                                        temp_ptr=val;
 
1212
                                                        for(x=0;x<MAX_STATE_HISTORY_ENTRIES;x++)
 
1213
                                                                temp_servicestatus->state_history[x]=atoi(my_strsep(&temp_ptr,","));
 
1214
                                                        temp_servicestatus->state_history_index=0;
 
1215
                                                        }
 
1216
                                                */
 
1217
                                                }
 
1218
                                        break;
 
1219
 
 
1220
                                case XSDDEFAULT_CONTACTSTATUS_DATA:
 
1221
                                        /* unimplemented */
 
1222
                                        break;
 
1223
 
 
1224
                                case XSDDEFAULT_HOSTCOMMENT_DATA:
 
1225
                                case XSDDEFAULT_SERVICECOMMENT_DATA:
 
1226
                                        if(!strcmp(var, "host_name"))
 
1227
                                                host_name = (char *)strdup(val);
 
1228
                                        else if(!strcmp(var, "service_description"))
 
1229
                                                service_description = (char *)strdup(val);
 
1230
                                        else if(!strcmp(var, "entry_type"))
 
1231
                                                entry_type = atoi(val);
 
1232
                                        else if(!strcmp(var, "comment_id"))
 
1233
                                                comment_id = strtoul(val, NULL, 10);
 
1234
                                        else if(!strcmp(var, "source"))
 
1235
                                                source = atoi(val);
 
1236
                                        else if(!strcmp(var, "persistent"))
 
1237
                                                persistent = (atoi(val) > 0) ? TRUE : FALSE;
 
1238
                                        else if(!strcmp(var, "entry_time"))
 
1239
                                                entry_time = strtoul(val, NULL, 10);
 
1240
                                        else if(!strcmp(var, "expires"))
 
1241
                                                expires = (atoi(val) > 0) ? TRUE : FALSE;
 
1242
                                        else if(!strcmp(var, "expire_time"))
 
1243
                                                expire_time = strtoul(val, NULL, 10);
 
1244
                                        else if(!strcmp(var, "author"))
 
1245
                                                author = (char *)strdup(val);
 
1246
                                        else if(!strcmp(var, "comment_data"))
 
1247
                                                comment_data = (char *)strdup(val);
 
1248
                                        break;
 
1249
 
 
1250
                                case XSDDEFAULT_HOSTDOWNTIME_DATA:
 
1251
                                case XSDDEFAULT_SERVICEDOWNTIME_DATA:
 
1252
                                        if(!strcmp(var, "host_name"))
 
1253
                                                host_name = (char *)strdup(val);
 
1254
                                        else if(!strcmp(var, "service_description"))
 
1255
                                                service_description = (char *)strdup(val);
 
1256
                                        else if(!strcmp(var, "downtime_id"))
 
1257
                                                downtime_id = strtoul(val, NULL, 10);
 
1258
                                        else if(!strcmp(var, "entry_time"))
 
1259
                                                entry_time = strtoul(val, NULL, 10);
 
1260
                                        else if(!strcmp(var, "start_time"))
 
1261
                                                start_time = strtoul(val, NULL, 10);
 
1262
                                        else if(!strcmp(var, "end_time"))
 
1263
                                                end_time = strtoul(val, NULL, 10);
 
1264
                                        else if(!strcmp(var, "fixed"))
 
1265
                                                fixed = (atoi(val) > 0) ? TRUE : FALSE;
 
1266
                                        else if(!strcmp(var, "triggered_by"))
 
1267
                                                triggered_by = strtoul(val, NULL, 10);
 
1268
                                        else if(!strcmp(var, "duration"))
 
1269
                                                duration = strtoul(val, NULL, 10);
 
1270
                                        else if(!strcmp(var, "is_in_effect"))
 
1271
                                                is_in_effect = (atoi(val) > 0) ? TRUE : FALSE;
 
1272
                                        else if(!strcmp(var, "author"))
 
1273
                                                author = (char *)strdup(val);
 
1274
                                        else if(!strcmp(var, "comment"))
 
1275
                                                comment_data = (char *)strdup(val);
 
1276
                                        break;
 
1277
 
 
1278
                                default:
 
1279
                                        break;
 
1280
                                }
 
1281
 
 
1282
                        }
 
1283
                }
1299
1284
 
1300
1285
        /* free memory and close the file */
1301
1286
#ifdef NO_MMAP
1309
1294
        my_free(xsddefault_status_log);
1310
1295
        my_free(xsddefault_temp_file);
1311
1296
 
1312
 
        if(sort_downtime()!=OK)
 
1297
        if(sort_downtime() != OK)
1313
1298
                return ERROR;
1314
 
        if(sort_comments()!=OK)
 
1299
        if(sort_comments() != OK)
1315
1300
                return ERROR;
1316
1301
 
1317
1302
        return OK;
1318
 
        }
 
1303
        }
1319
1304
 
1320
1305
#endif
1321
1306