Icinga-core 1.4.0
next gen monitoring
base/commands.c
Go to the documentation of this file.
00001 /*****************************************************************************
00002  *
00003  * COMMANDS.C - External command functions for Icinga
00004  *
00005  * Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
00006  * Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
00007  * Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org)
00008  *
00009  * License:
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License version 2 as
00013  * published by the Free Software Foundation.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00023  *
00024  *****************************************************************************/
00025 
00026 #include "../include/config.h"
00027 #include "../include/common.h"
00028 #include "../include/comments.h"
00029 #include "../include/downtime.h"
00030 #include "../include/statusdata.h"
00031 #include "../include/perfdata.h"
00032 #include "../include/sretention.h"
00033 #include "../include/broker.h"
00034 #include "../include/icinga.h"
00035 
00036 extern char     *config_file;
00037 extern char     *log_file;
00038 extern char     *command_file;
00039 extern char     *temp_file;
00040 extern char     *temp_path;
00041 
00042 extern int      sigshutdown;
00043 extern int      sigrestart;
00044 
00045 extern int      check_external_commands;
00046 
00047 extern int      ipc_pipe[2];
00048 
00049 extern time_t   last_command_check;
00050 extern time_t   last_command_status_update;
00051 
00052 extern int      command_check_interval;
00053 
00054 extern int      enable_notifications;
00055 extern int      execute_service_checks;
00056 extern int      accept_passive_service_checks;
00057 extern int      execute_host_checks;
00058 extern int      accept_passive_host_checks;
00059 extern int      enable_event_handlers;
00060 extern int      obsess_over_services;
00061 extern int      obsess_over_hosts;
00062 extern int      check_service_freshness;
00063 extern int      check_host_freshness;
00064 extern int      enable_failure_prediction;
00065 extern int      process_performance_data;
00066 
00067 extern int      log_external_commands;
00068 extern int      log_external_commands_user;
00069 extern int      log_passive_checks;
00070 
00071 extern unsigned long    modified_host_process_attributes;
00072 extern unsigned long    modified_service_process_attributes;
00073 
00074 extern char     *global_host_event_handler;
00075 extern char     *global_service_event_handler;
00076 extern command  *global_host_event_handler_ptr;
00077 extern command  *global_service_event_handler_ptr;
00078 
00079 extern host     *host_list;
00080 extern service  *service_list;
00081 
00082 extern FILE     *command_file_fp;
00083 extern int      command_file_fd;
00084 
00085 passive_check_result    *passive_check_result_list=NULL;
00086 passive_check_result    *passive_check_result_list_tail=NULL;
00087 
00088 extern pthread_t       worker_threads[TOTAL_WORKER_THREADS];
00089 extern circular_buffer external_command_buffer;
00090 extern int             external_command_buffer_slots;
00091 
00092 int dummy;      /* reduce compiler warnings */
00093 
00094 /******************************************************************/
00095 /****************** EXTERNAL COMMAND PROCESSING *******************/
00096 /******************************************************************/
00097 
00098 
00099 /* checks for the existence of the external command file and processes all commands found in it */
00100 int check_for_external_commands(void){
00101         char *buffer=NULL;
00102         int update_status=FALSE;
00103 
00104         log_debug_info(DEBUGL_FUNCTIONS,0,"check_for_external_commands()\n");
00105 
00106         /* bail out if we shouldn't be checking for external commands */
00107         if(check_external_commands==FALSE)
00108                 return ERROR;
00109 
00110         /* update last command check time */
00111         last_command_check=time(NULL);
00112 
00113         /* update the status log with new program information */
00114         /* go easy on the frequency of this if we're checking often - only update program status every 10 seconds.... */
00115         if(last_command_check<(last_command_status_update+10))
00116                 update_status=FALSE;
00117         else
00118                 update_status=TRUE;
00119         if(update_status==TRUE){
00120                 last_command_status_update=last_command_check;
00121                 update_program_status(FALSE);
00122                 }
00123 
00124         /* reset passive check result list pointers */
00125         passive_check_result_list=NULL;
00126         passive_check_result_list_tail=NULL;
00127 
00128         /* process all commands found in the buffer */
00129         while(1){
00130 
00131                 /* get a lock on the buffer */
00132                 pthread_mutex_lock(&external_command_buffer.buffer_lock);
00133 
00134                 /* if no items present, bail out */
00135                 if(external_command_buffer.items<=0){
00136                         pthread_mutex_unlock(&external_command_buffer.buffer_lock);
00137                         break;
00138                         }
00139 
00140                 if(external_command_buffer.buffer[external_command_buffer.tail])
00141                         buffer=strdup(((char **)external_command_buffer.buffer)[external_command_buffer.tail]);
00142 
00143                 /* free memory allocated for buffer slot */
00144                 my_free(((char **)external_command_buffer.buffer)[external_command_buffer.tail]);
00145 
00146                 /* adjust tail counter and number of items */
00147                 external_command_buffer.tail=(external_command_buffer.tail + 1) % external_command_buffer_slots;
00148                 external_command_buffer.items--;
00149 
00150                 /* release the lock on the buffer */
00151                 pthread_mutex_unlock(&external_command_buffer.buffer_lock);
00152 
00153                 /* process the command */
00154                 process_external_command1(buffer);
00155 
00156                 /* free memory */
00157                 my_free(buffer);
00158                 }
00159 
00160         /**** PROCESS ALL PASSIVE HOST AND SERVICE CHECK RESULTS AT ONE TIME ****/
00161         if(passive_check_result_list!=NULL)
00162                 process_passive_checks();
00163 
00164         return OK;
00165         }
00166 
00167 
00168 
00169 /* processes all external commands in a (regular) file */
00170 int process_external_commands_from_file(char *fname, int delete_file){
00171         mmapfile *thefile=NULL;
00172         char *input=NULL;
00173 
00174 
00175         log_debug_info(DEBUGL_FUNCTIONS,0,"process_external_commands_from_file()\n");
00176 
00177         if(fname==NULL)
00178                 return ERROR;
00179 
00180         log_debug_info(DEBUGL_EXTERNALCOMMANDS,1,"Processing commands from file '%s'.  File will %s deleted after processing.\n",fname,(delete_file==TRUE)?"be":"NOT be");
00181 
00182         /* open the config file for reading */
00183         if((thefile=mmap_fopen(fname))==NULL){
00184                 logit(NSLOG_INFO_MESSAGE,FALSE,"Error: Cannot open file '%s' to process external commands!",fname);
00185                 return ERROR;
00186                 }
00187 
00188         /* process all commands in the file */
00189         while(1){
00190 
00191                 /* free memory */
00192                 my_free(input);
00193 
00194                 /* read the next line */
00195                 if((input=mmap_fgets(thefile))==NULL)
00196                         break;
00197 
00198                 /* process the command */
00199                 process_external_command1(input);
00200                 }
00201 
00202         /* close the file */
00203         mmap_fclose(thefile);
00204 
00205         /* delete the file */
00206         if(delete_file==TRUE)
00207                 unlink(fname);
00208 
00209         return OK;
00210         }
00211 
00212 
00213 
00214 /* top-level external command processor */
00215 int process_external_command1(char *cmd){
00216         char *temp_buffer=NULL;
00217         char *command_id=NULL;
00218         char *args=NULL;
00219         time_t entry_time=0L;
00220         int command_type=CMD_NONE;
00221         char *temp_ptr=NULL;
00222         char *username=NULL;
00223 
00224         log_debug_info(DEBUGL_FUNCTIONS,0,"process_external_command1()\n");
00225 
00226         if(cmd==NULL)
00227                 return ERROR;
00228 
00229         /* strip the command of newlines and carriage returns */
00230         strip(cmd);
00231 
00232         log_debug_info(DEBUGL_EXTERNALCOMMANDS,2,"Raw command entry: %s\n",cmd);
00233 
00234         /* get the command entry time */
00235         if((temp_ptr=my_strtok(cmd,"["))==NULL)
00236                 return ERROR;
00237         if((temp_ptr=my_strtok(NULL,"]"))==NULL)
00238                 return ERROR;
00239         entry_time=(time_t)strtoul(temp_ptr,NULL,10);
00240 
00241         /* get the command identifier */
00242         if((temp_ptr=my_strtok(NULL,";"))==NULL)
00243                 return ERROR;
00244         if((command_id=(char *)strdup(temp_ptr+1))==NULL)
00245                 return ERROR;
00246 
00247         if(log_external_commands_user==TRUE){
00248                 /* get the command arguments incl username */
00249                 if((temp_ptr=my_strtok(NULL,"\n"))==NULL)
00250                         temp_buffer=(char *)strdup("");
00251                 else
00252                         temp_buffer=(char *)strdup(temp_ptr);
00253 
00254                 /* get the command username */
00255                 if((temp_ptr=my_strtok(temp_buffer,";"))==NULL)
00256                         username=(char *)strdup("");
00257                 else
00258                         username=(char *)strdup(temp_ptr);
00259 
00260                 //logit(NSLOG_EXTERNAL_COMMAND | NSLOG_RUNTIME_WARNING,TRUE,"external command username: %s\n",username);
00261 
00262                 /* get the command args */
00263                 if((temp_ptr=my_strtok(NULL,"\n"))==NULL)
00264                         args=(char *)strdup("");
00265                 else
00266                         args=(char *)strdup(temp_ptr);
00267 
00268                 //logit(NSLOG_EXTERNAL_COMMAND | NSLOG_RUNTIME_WARNING,TRUE,"external command args: %s\n",args);
00269 
00270                 my_free(temp_buffer);
00271         } else {
00272                 /* get the command arguments */
00273                 if((temp_ptr=my_strtok(NULL,"\n"))==NULL)
00274                         args=(char *)strdup("");
00275                 else
00276                         args=(char *)strdup(temp_ptr);
00277         }
00278 
00279 
00280         if(args==NULL){
00281                 my_free(command_id);
00282                 return ERROR;
00283                 }
00284 
00285         /* decide what type of command this is... */
00286 
00287         /**************************/
00288         /**** PROCESS COMMANDS ****/
00289         /**************************/
00290 
00291         if(!strcmp(command_id,"ENTER_STANDBY_MODE") || !strcmp(command_id,"DISABLE_NOTIFICATIONS"))
00292                 command_type=CMD_DISABLE_NOTIFICATIONS;
00293         else if(!strcmp(command_id,"ENTER_ACTIVE_MODE") || !strcmp(command_id,"ENABLE_NOTIFICATIONS"))
00294                 command_type=CMD_ENABLE_NOTIFICATIONS;
00295 
00296         else if(!strcmp(command_id,"SHUTDOWN_PROGRAM") || !strcmp(command_id,"SHUTDOWN_PROCESS"))
00297                 command_type=CMD_SHUTDOWN_PROCESS;
00298         else if(!strcmp(command_id,"RESTART_PROGRAM") || !strcmp(command_id,"RESTART_PROCESS"))
00299                 command_type=CMD_RESTART_PROCESS;
00300 
00301         else if(!strcmp(command_id,"SAVE_STATE_INFORMATION"))
00302                 command_type=CMD_SAVE_STATE_INFORMATION;
00303         else if(!strcmp(command_id,"READ_STATE_INFORMATION"))
00304                 command_type=CMD_READ_STATE_INFORMATION;
00305         else if(!strcmp(command_id,"SYNC_STATE_INFORMATION"))
00306                 command_type=CMD_SYNC_STATE_INFORMATION;
00307 
00308         else if(!strcmp(command_id,"ENABLE_EVENT_HANDLERS"))
00309                 command_type=CMD_ENABLE_EVENT_HANDLERS;
00310         else if(!strcmp(command_id,"DISABLE_EVENT_HANDLERS"))
00311                 command_type=CMD_DISABLE_EVENT_HANDLERS;
00312 
00313         else if(!strcmp(command_id,"FLUSH_PENDING_COMMANDS"))
00314                 command_type=CMD_FLUSH_PENDING_COMMANDS;
00315 
00316         else if(!strcmp(command_id,"ENABLE_FAILURE_PREDICTION"))
00317                 command_type=CMD_ENABLE_FAILURE_PREDICTION;
00318         else if(!strcmp(command_id,"DISABLE_FAILURE_PREDICTION"))
00319                 command_type=CMD_DISABLE_FAILURE_PREDICTION;
00320 
00321         else if(!strcmp(command_id,"ENABLE_PERFORMANCE_DATA"))
00322                 command_type=CMD_ENABLE_PERFORMANCE_DATA;
00323         else if(!strcmp(command_id,"DISABLE_PERFORMANCE_DATA"))
00324                 command_type=CMD_DISABLE_PERFORMANCE_DATA;
00325 
00326         else if(!strcmp(command_id,"START_EXECUTING_HOST_CHECKS"))
00327                 command_type=CMD_START_EXECUTING_HOST_CHECKS;
00328         else if(!strcmp(command_id,"STOP_EXECUTING_HOST_CHECKS"))
00329                 command_type=CMD_STOP_EXECUTING_HOST_CHECKS;
00330 
00331         else if(!strcmp(command_id,"START_EXECUTING_SVC_CHECKS"))
00332                 command_type=CMD_START_EXECUTING_SVC_CHECKS;
00333         else if(!strcmp(command_id,"STOP_EXECUTING_SVC_CHECKS"))
00334                 command_type=CMD_STOP_EXECUTING_SVC_CHECKS;
00335 
00336         else if(!strcmp(command_id,"START_ACCEPTING_PASSIVE_HOST_CHECKS"))
00337                 command_type=CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS;
00338         else if(!strcmp(command_id,"STOP_ACCEPTING_PASSIVE_HOST_CHECKS"))
00339                 command_type=CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS;
00340 
00341         else if(!strcmp(command_id,"START_ACCEPTING_PASSIVE_SVC_CHECKS"))
00342                 command_type=CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS;
00343         else if(!strcmp(command_id,"STOP_ACCEPTING_PASSIVE_SVC_CHECKS"))
00344                 command_type=CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS;
00345 
00346         else if(!strcmp(command_id,"START_OBSESSING_OVER_HOST_CHECKS"))
00347                 command_type=CMD_START_OBSESSING_OVER_HOST_CHECKS;
00348         else if(!strcmp(command_id,"STOP_OBSESSING_OVER_HOST_CHECKS"))
00349                 command_type=CMD_STOP_OBSESSING_OVER_HOST_CHECKS;
00350 
00351         else if(!strcmp(command_id,"START_OBSESSING_OVER_SVC_CHECKS"))
00352                 command_type=CMD_START_OBSESSING_OVER_SVC_CHECKS;
00353         else if(!strcmp(command_id,"STOP_OBSESSING_OVER_SVC_CHECKS"))
00354                 command_type=CMD_STOP_OBSESSING_OVER_SVC_CHECKS;
00355 
00356         else if(!strcmp(command_id,"ENABLE_FLAP_DETECTION"))
00357                 command_type=CMD_ENABLE_FLAP_DETECTION;
00358         else if(!strcmp(command_id,"DISABLE_FLAP_DETECTION"))
00359                 command_type=CMD_DISABLE_FLAP_DETECTION;
00360 
00361         else if(!strcmp(command_id,"CHANGE_GLOBAL_HOST_EVENT_HANDLER"))
00362                 command_type=CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER;
00363         else if(!strcmp(command_id,"CHANGE_GLOBAL_SVC_EVENT_HANDLER"))
00364                 command_type=CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER;
00365 
00366         else if(!strcmp(command_id,"ENABLE_SERVICE_FRESHNESS_CHECKS"))
00367                 command_type=CMD_ENABLE_SERVICE_FRESHNESS_CHECKS;
00368         else if(!strcmp(command_id,"DISABLE_SERVICE_FRESHNESS_CHECKS"))
00369                 command_type=CMD_DISABLE_SERVICE_FRESHNESS_CHECKS;
00370 
00371         else if(!strcmp(command_id,"ENABLE_HOST_FRESHNESS_CHECKS"))
00372                 command_type=CMD_ENABLE_HOST_FRESHNESS_CHECKS;
00373         else if(!strcmp(command_id,"DISABLE_HOST_FRESHNESS_CHECKS"))
00374                 command_type=CMD_DISABLE_HOST_FRESHNESS_CHECKS;
00375 
00376 
00377         /*******************************/
00378         /**** HOST-RELATED COMMANDS ****/
00379         /*******************************/
00380 
00381         else if(!strcmp(command_id,"ADD_HOST_COMMENT"))
00382                 command_type=CMD_ADD_HOST_COMMENT;
00383         else if(!strcmp(command_id,"DEL_HOST_COMMENT"))
00384                 command_type=CMD_DEL_HOST_COMMENT;
00385         else if(!strcmp(command_id,"DEL_ALL_HOST_COMMENTS"))
00386                 command_type=CMD_DEL_ALL_HOST_COMMENTS;
00387 
00388         else if(!strcmp(command_id,"DELAY_HOST_NOTIFICATION"))
00389                 command_type=CMD_DELAY_HOST_NOTIFICATION;
00390 
00391         else if(!strcmp(command_id,"ENABLE_HOST_NOTIFICATIONS"))
00392                 command_type=CMD_ENABLE_HOST_NOTIFICATIONS;
00393         else if(!strcmp(command_id,"DISABLE_HOST_NOTIFICATIONS"))
00394                 command_type=CMD_DISABLE_HOST_NOTIFICATIONS;
00395 
00396         else if(!strcmp(command_id,"ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST"))
00397                 command_type=CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST;
00398         else if(!strcmp(command_id,"DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST"))
00399                 command_type=CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST;
00400 
00401         else if(!strcmp(command_id,"ENABLE_HOST_AND_CHILD_NOTIFICATIONS"))
00402                 command_type=CMD_ENABLE_HOST_AND_CHILD_NOTIFICATIONS;
00403         else if(!strcmp(command_id,"DISABLE_HOST_AND_CHILD_NOTIFICATIONS"))
00404                 command_type=CMD_DISABLE_HOST_AND_CHILD_NOTIFICATIONS;
00405 
00406         else if(!strcmp(command_id,"ENABLE_HOST_SVC_NOTIFICATIONS"))
00407                 command_type=CMD_ENABLE_HOST_SVC_NOTIFICATIONS;
00408         else if(!strcmp(command_id,"DISABLE_HOST_SVC_NOTIFICATIONS"))
00409                 command_type=CMD_DISABLE_HOST_SVC_NOTIFICATIONS;
00410 
00411         else if(!strcmp(command_id,"ENABLE_HOST_SVC_CHECKS"))
00412                 command_type=CMD_ENABLE_HOST_SVC_CHECKS;
00413         else if(!strcmp(command_id,"DISABLE_HOST_SVC_CHECKS"))
00414                 command_type=CMD_DISABLE_HOST_SVC_CHECKS;
00415 
00416         else if(!strcmp(command_id,"ENABLE_PASSIVE_HOST_CHECKS"))
00417                 command_type=CMD_ENABLE_PASSIVE_HOST_CHECKS;
00418         else if(!strcmp(command_id,"DISABLE_PASSIVE_HOST_CHECKS"))
00419                 command_type=CMD_DISABLE_PASSIVE_HOST_CHECKS;
00420 
00421         else if(!strcmp(command_id,"SCHEDULE_HOST_SVC_CHECKS"))
00422                 command_type=CMD_SCHEDULE_HOST_SVC_CHECKS;
00423         else if(!strcmp(command_id,"SCHEDULE_FORCED_HOST_SVC_CHECKS"))
00424                 command_type=CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS;
00425 
00426         else if(!strcmp(command_id,"ACKNOWLEDGE_HOST_PROBLEM"))
00427                 command_type=CMD_ACKNOWLEDGE_HOST_PROBLEM;
00428         else if(!strcmp(command_id,"REMOVE_HOST_ACKNOWLEDGEMENT"))
00429                 command_type=CMD_REMOVE_HOST_ACKNOWLEDGEMENT;
00430 
00431         else if(!strcmp(command_id,"ENABLE_HOST_EVENT_HANDLER"))
00432                 command_type=CMD_ENABLE_HOST_EVENT_HANDLER;
00433         else if(!strcmp(command_id,"DISABLE_HOST_EVENT_HANDLER"))
00434                 command_type=CMD_DISABLE_HOST_EVENT_HANDLER;
00435 
00436         else if(!strcmp(command_id,"ENABLE_HOST_CHECK"))
00437                 command_type=CMD_ENABLE_HOST_CHECK;
00438         else if(!strcmp(command_id,"DISABLE_HOST_CHECK"))
00439                 command_type=CMD_DISABLE_HOST_CHECK;
00440 
00441         else if(!strcmp(command_id,"SCHEDULE_HOST_CHECK"))
00442                 command_type=CMD_SCHEDULE_HOST_CHECK;
00443         else if(!strcmp(command_id,"SCHEDULE_FORCED_HOST_CHECK"))
00444                 command_type=CMD_SCHEDULE_FORCED_HOST_CHECK;
00445 
00446         else if(!strcmp(command_id,"SCHEDULE_HOST_DOWNTIME"))
00447                 command_type=CMD_SCHEDULE_HOST_DOWNTIME;
00448         else if(!strcmp(command_id,"SCHEDULE_HOST_SVC_DOWNTIME"))
00449                 command_type=CMD_SCHEDULE_HOST_SVC_DOWNTIME;
00450         else if(!strcmp(command_id,"DEL_HOST_DOWNTIME"))
00451                 command_type=CMD_DEL_HOST_DOWNTIME;
00452         else if(!strcmp(command_id,"DEL_DOWNTIME_BY_HOST_NAME"))
00453                 command_type=CMD_DEL_DOWNTIME_BY_HOST_NAME;
00454         else if(!strcmp(command_id,"DEL_DOWNTIME_BY_HOSTGROUP_NAME"))
00455                 command_type=CMD_DEL_DOWNTIME_BY_HOSTGROUP_NAME;
00456 
00457         else if(!strcmp(command_id,"DEL_DOWNTIME_BY_START_TIME_COMMENT"))
00458                 command_type=CMD_DEL_DOWNTIME_BY_START_TIME_COMMENT;
00459 
00460         else if(!strcmp(command_id,"ENABLE_HOST_FLAP_DETECTION"))
00461                 command_type=CMD_ENABLE_HOST_FLAP_DETECTION;
00462         else if(!strcmp(command_id,"DISABLE_HOST_FLAP_DETECTION"))
00463                 command_type=CMD_DISABLE_HOST_FLAP_DETECTION;
00464 
00465         else if(!strcmp(command_id,"START_OBSESSING_OVER_HOST"))
00466                 command_type=CMD_START_OBSESSING_OVER_HOST;
00467         else if(!strcmp(command_id,"STOP_OBSESSING_OVER_HOST"))
00468                 command_type=CMD_STOP_OBSESSING_OVER_HOST;
00469 
00470         else if(!strcmp(command_id,"CHANGE_HOST_EVENT_HANDLER"))
00471                 command_type=CMD_CHANGE_HOST_EVENT_HANDLER;
00472         else if(!strcmp(command_id,"CHANGE_HOST_CHECK_COMMAND"))
00473                 command_type=CMD_CHANGE_HOST_CHECK_COMMAND;
00474 
00475         else if(!strcmp(command_id,"CHANGE_NORMAL_HOST_CHECK_INTERVAL"))
00476                 command_type=CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL;
00477         else if(!strcmp(command_id,"CHANGE_RETRY_HOST_CHECK_INTERVAL"))
00478                 command_type=CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL;
00479 
00480         else if(!strcmp(command_id,"CHANGE_MAX_HOST_CHECK_ATTEMPTS"))
00481                 command_type=CMD_CHANGE_MAX_HOST_CHECK_ATTEMPTS;
00482 
00483         else if(!strcmp(command_id,"SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME"))
00484                 command_type=CMD_SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME;
00485 
00486         else if(!strcmp(command_id,"SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME"))
00487                 command_type=CMD_SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME;
00488 
00489         else if(!strcmp(command_id,"SET_HOST_NOTIFICATION_NUMBER"))
00490                 command_type=CMD_SET_HOST_NOTIFICATION_NUMBER;
00491 
00492         else if(!strcmp(command_id,"CHANGE_HOST_CHECK_TIMEPERIOD"))
00493                 command_type=CMD_CHANGE_HOST_CHECK_TIMEPERIOD;
00494 
00495         else if (!strcmp(command_id,"CHANGE_CUSTOM_HOST_VAR"))
00496                 command_type=CMD_CHANGE_CUSTOM_HOST_VAR;
00497 
00498         else if (!strcmp(command_id,"SEND_CUSTOM_HOST_NOTIFICATION"))
00499                 command_type=CMD_SEND_CUSTOM_HOST_NOTIFICATION;
00500 
00501         else if(!strcmp(command_id,"CHANGE_HOST_NOTIFICATION_TIMEPERIOD"))
00502                 command_type=CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD;
00503 
00504         else if(!strcmp(command_id,"CHANGE_HOST_MODATTR"))
00505                 command_type=CMD_CHANGE_HOST_MODATTR;
00506 
00507 
00508         /************************************/
00509         /**** HOSTGROUP-RELATED COMMANDS ****/
00510         /************************************/
00511 
00512         else if(!strcmp(command_id,"ENABLE_HOSTGROUP_HOST_NOTIFICATIONS"))
00513                 command_type=CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS;
00514         else if(!strcmp(command_id,"DISABLE_HOSTGROUP_HOST_NOTIFICATIONS"))
00515                 command_type=CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS;
00516 
00517         else if(!strcmp(command_id,"ENABLE_HOSTGROUP_SVC_NOTIFICATIONS"))
00518                 command_type=CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS;
00519         else if(!strcmp(command_id,"DISABLE_HOSTGROUP_SVC_NOTIFICATIONS"))
00520                 command_type=CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS;
00521 
00522         else if(!strcmp(command_id,"ENABLE_HOSTGROUP_HOST_CHECKS"))
00523                 command_type=CMD_ENABLE_HOSTGROUP_HOST_CHECKS;
00524         else if(!strcmp(command_id,"DISABLE_HOSTGROUP_HOST_CHECKS"))
00525                 command_type=CMD_DISABLE_HOSTGROUP_HOST_CHECKS;
00526 
00527         else if(!strcmp(command_id,"ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS"))
00528                 command_type=CMD_ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS;
00529         else if(!strcmp(command_id,"DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS"))
00530                 command_type=CMD_DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS;
00531 
00532         else if(!strcmp(command_id,"ENABLE_HOSTGROUP_SVC_CHECKS"))
00533                 command_type=CMD_ENABLE_HOSTGROUP_SVC_CHECKS;
00534         else if(!strcmp(command_id,"DISABLE_HOSTGROUP_SVC_CHECKS"))
00535                 command_type=CMD_DISABLE_HOSTGROUP_SVC_CHECKS;
00536 
00537         else if(!strcmp(command_id,"ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS"))
00538                 command_type=CMD_ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS;
00539         else if(!strcmp(command_id,"DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS"))
00540                 command_type=CMD_DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS;
00541 
00542         else if(!strcmp(command_id,"SCHEDULE_HOSTGROUP_HOST_DOWNTIME"))
00543                 command_type=CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME;
00544         else if(!strcmp(command_id,"SCHEDULE_HOSTGROUP_SVC_DOWNTIME"))
00545                 command_type=CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME;
00546 
00547 
00548         /**********************************/
00549         /**** SERVICE-RELATED COMMANDS ****/
00550         /**********************************/
00551 
00552         else if(!strcmp(command_id,"ADD_SVC_COMMENT"))
00553                 command_type=CMD_ADD_SVC_COMMENT;
00554         else if(!strcmp(command_id,"DEL_SVC_COMMENT"))
00555                 command_type=CMD_DEL_SVC_COMMENT;
00556         else if(!strcmp(command_id,"DEL_ALL_SVC_COMMENTS"))
00557                 command_type=CMD_DEL_ALL_SVC_COMMENTS;
00558 
00559         else if(!strcmp(command_id,"SCHEDULE_SVC_CHECK"))
00560                 command_type=CMD_SCHEDULE_SVC_CHECK;
00561         else if(!strcmp(command_id,"SCHEDULE_FORCED_SVC_CHECK"))
00562                 command_type=CMD_SCHEDULE_FORCED_SVC_CHECK;
00563 
00564         else if(!strcmp(command_id,"ENABLE_SVC_CHECK"))
00565                 command_type=CMD_ENABLE_SVC_CHECK;
00566         else if(!strcmp(command_id,"DISABLE_SVC_CHECK"))
00567                 command_type=CMD_DISABLE_SVC_CHECK;
00568 
00569         else if(!strcmp(command_id,"ENABLE_PASSIVE_SVC_CHECKS"))
00570                 command_type=CMD_ENABLE_PASSIVE_SVC_CHECKS;
00571         else if(!strcmp(command_id,"DISABLE_PASSIVE_SVC_CHECKS"))
00572                 command_type=CMD_DISABLE_PASSIVE_SVC_CHECKS;
00573 
00574         else if(!strcmp(command_id,"DELAY_SVC_NOTIFICATION"))
00575                 command_type=CMD_DELAY_SVC_NOTIFICATION;
00576         else if(!strcmp(command_id,"ENABLE_SVC_NOTIFICATIONS"))
00577                 command_type=CMD_ENABLE_SVC_NOTIFICATIONS;
00578         else if(!strcmp(command_id,"DISABLE_SVC_NOTIFICATIONS"))
00579                 command_type=CMD_DISABLE_SVC_NOTIFICATIONS;
00580 
00581         else if(!strcmp(command_id,"PROCESS_SERVICE_CHECK_RESULT"))
00582                 command_type=CMD_PROCESS_SERVICE_CHECK_RESULT;
00583         else if(!strcmp(command_id,"PROCESS_HOST_CHECK_RESULT"))
00584                 command_type=CMD_PROCESS_HOST_CHECK_RESULT;
00585 
00586         else if(!strcmp(command_id,"ENABLE_SVC_EVENT_HANDLER"))
00587                 command_type=CMD_ENABLE_SVC_EVENT_HANDLER;
00588         else if(!strcmp(command_id,"DISABLE_SVC_EVENT_HANDLER"))
00589                 command_type=CMD_DISABLE_SVC_EVENT_HANDLER;
00590 
00591         else if(!strcmp(command_id,"ENABLE_SVC_FLAP_DETECTION"))
00592                 command_type=CMD_ENABLE_SVC_FLAP_DETECTION;
00593         else if(!strcmp(command_id,"DISABLE_SVC_FLAP_DETECTION"))
00594                 command_type=CMD_DISABLE_SVC_FLAP_DETECTION;
00595 
00596         else if(!strcmp(command_id,"SCHEDULE_SVC_DOWNTIME"))
00597                 command_type=CMD_SCHEDULE_SVC_DOWNTIME;
00598         else if(!strcmp(command_id,"DEL_SVC_DOWNTIME"))
00599                 command_type=CMD_DEL_SVC_DOWNTIME;
00600 
00601         else if(!strcmp(command_id,"ACKNOWLEDGE_SVC_PROBLEM"))
00602                 command_type=CMD_ACKNOWLEDGE_SVC_PROBLEM;
00603         else if(!strcmp(command_id,"REMOVE_SVC_ACKNOWLEDGEMENT"))
00604                 command_type=CMD_REMOVE_SVC_ACKNOWLEDGEMENT;
00605 
00606         else if(!strcmp(command_id,"START_OBSESSING_OVER_SVC"))
00607                 command_type=CMD_START_OBSESSING_OVER_SVC;
00608         else if(!strcmp(command_id,"STOP_OBSESSING_OVER_SVC"))
00609                 command_type=CMD_STOP_OBSESSING_OVER_SVC;
00610 
00611         else if(!strcmp(command_id,"CHANGE_SVC_EVENT_HANDLER"))
00612                 command_type=CMD_CHANGE_SVC_EVENT_HANDLER;
00613         else if(!strcmp(command_id,"CHANGE_SVC_CHECK_COMMAND"))
00614                 command_type=CMD_CHANGE_SVC_CHECK_COMMAND;
00615 
00616         else if(!strcmp(command_id,"CHANGE_NORMAL_SVC_CHECK_INTERVAL"))
00617                 command_type=CMD_CHANGE_NORMAL_SVC_CHECK_INTERVAL;
00618         else if(!strcmp(command_id,"CHANGE_RETRY_SVC_CHECK_INTERVAL"))
00619                 command_type=CMD_CHANGE_RETRY_SVC_CHECK_INTERVAL;
00620 
00621         else if(!strcmp(command_id,"CHANGE_MAX_SVC_CHECK_ATTEMPTS"))
00622                 command_type=CMD_CHANGE_MAX_SVC_CHECK_ATTEMPTS;
00623 
00624         else if(!strcmp(command_id,"SET_SVC_NOTIFICATION_NUMBER"))
00625                 command_type=CMD_SET_SVC_NOTIFICATION_NUMBER;
00626 
00627         else if(!strcmp(command_id,"CHANGE_SVC_CHECK_TIMEPERIOD"))
00628                 command_type=CMD_CHANGE_SVC_CHECK_TIMEPERIOD;
00629 
00630         else if (!strcmp(command_id,"CHANGE_CUSTOM_SVC_VAR"))
00631                 command_type=CMD_CHANGE_CUSTOM_SVC_VAR;
00632 
00633         else if (!strcmp(command_id,"CHANGE_CUSTOM_CONTACT_VAR"))
00634                 command_type=CMD_CHANGE_CUSTOM_CONTACT_VAR;
00635 
00636         else if (!strcmp(command_id,"SEND_CUSTOM_SVC_NOTIFICATION"))
00637                 command_type=CMD_SEND_CUSTOM_SVC_NOTIFICATION;
00638 
00639         else if(!strcmp(command_id,"CHANGE_SVC_NOTIFICATION_TIMEPERIOD"))
00640                 command_type=CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD;
00641 
00642         else if(!strcmp(command_id,"CHANGE_SVC_MODATTR"))
00643                 command_type=CMD_CHANGE_SVC_MODATTR;
00644 
00645 
00646         /***************************************/
00647         /**** SERVICEGROUP-RELATED COMMANDS ****/
00648         /***************************************/
00649 
00650         else if(!strcmp(command_id,"ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS"))
00651                 command_type=CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS;
00652         else if(!strcmp(command_id,"DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS"))
00653                 command_type=CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS;
00654 
00655         else if(!strcmp(command_id,"ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS"))
00656                 command_type=CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS;
00657         else if(!strcmp(command_id,"DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS"))
00658                 command_type=CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS;
00659 
00660         else if(!strcmp(command_id,"ENABLE_SERVICEGROUP_HOST_CHECKS"))
00661                 command_type=CMD_ENABLE_SERVICEGROUP_HOST_CHECKS;
00662         else if(!strcmp(command_id,"DISABLE_SERVICEGROUP_HOST_CHECKS"))
00663                 command_type=CMD_DISABLE_SERVICEGROUP_HOST_CHECKS;
00664 
00665         else if(!strcmp(command_id,"ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS"))
00666                 command_type=CMD_ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS;
00667         else if(!strcmp(command_id,"DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS"))
00668                 command_type=CMD_DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS;
00669 
00670         else if(!strcmp(command_id,"ENABLE_SERVICEGROUP_SVC_CHECKS"))
00671                 command_type=CMD_ENABLE_SERVICEGROUP_SVC_CHECKS;
00672         else if(!strcmp(command_id,"DISABLE_SERVICEGROUP_SVC_CHECKS"))
00673                 command_type=CMD_DISABLE_SERVICEGROUP_SVC_CHECKS;
00674 
00675         else if(!strcmp(command_id,"ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS"))
00676                 command_type=CMD_ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS;
00677         else if(!strcmp(command_id,"DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS"))
00678                 command_type=CMD_DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS;
00679 
00680         else if(!strcmp(command_id,"SCHEDULE_SERVICEGROUP_HOST_DOWNTIME"))
00681                 command_type=CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME;
00682         else if(!strcmp(command_id,"SCHEDULE_SERVICEGROUP_SVC_DOWNTIME"))
00683                 command_type=CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME;
00684 
00685 
00686         /**********************************/
00687         /**** CONTACT-RELATED COMMANDS ****/
00688         /**********************************/
00689 
00690         else if(!strcmp(command_id,"ENABLE_CONTACT_HOST_NOTIFICATIONS"))
00691                 command_type=CMD_ENABLE_CONTACT_HOST_NOTIFICATIONS;
00692         else if(!strcmp(command_id,"DISABLE_CONTACT_HOST_NOTIFICATIONS"))
00693                 command_type=CMD_DISABLE_CONTACT_HOST_NOTIFICATIONS;
00694 
00695         else if(!strcmp(command_id,"ENABLE_CONTACT_SVC_NOTIFICATIONS"))
00696                 command_type=CMD_ENABLE_CONTACT_SVC_NOTIFICATIONS;
00697         else if(!strcmp(command_id,"DISABLE_CONTACT_SVC_NOTIFICATIONS"))
00698                 command_type=CMD_DISABLE_CONTACT_SVC_NOTIFICATIONS;
00699 
00700         else if(!strcmp(command_id,"CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD"))
00701                 command_type=CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD;
00702 
00703         else if(!strcmp(command_id,"CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD"))
00704                 command_type=CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD;
00705 
00706         else if(!strcmp(command_id,"CHANGE_CONTACT_MODATTR"))
00707                 command_type=CMD_CHANGE_CONTACT_MODATTR;
00708         else if(!strcmp(command_id,"CHANGE_CONTACT_MODHATTR"))
00709                 command_type=CMD_CHANGE_CONTACT_MODHATTR;
00710         else if(!strcmp(command_id,"CHANGE_CONTACT_MODSATTR"))
00711                 command_type=CMD_CHANGE_CONTACT_MODSATTR;
00712 
00713         /***************************************/
00714         /**** CONTACTGROUP-RELATED COMMANDS ****/
00715         /***************************************/
00716 
00717         else if(!strcmp(command_id,"ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS"))
00718                 command_type=CMD_ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS;
00719         else if(!strcmp(command_id,"DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS"))
00720                 command_type=CMD_DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS;
00721 
00722         else if(!strcmp(command_id,"ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS"))
00723                 command_type=CMD_ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS;
00724         else if(!strcmp(command_id,"DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS"))
00725                 command_type=CMD_DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS;
00726 
00727 
00728         /**************************/
00729         /****** MISC COMMANDS *****/
00730         /**************************/
00731 
00732         else if(!strcmp(command_id,"PROCESS_FILE"))
00733                 command_type=CMD_PROCESS_FILE;
00734 
00735 
00736 
00737         /****************************/
00738         /****** CUSTOM COMMANDS *****/
00739         /****************************/
00740 
00741         else if(command_id[0]=='_')
00742                 command_type=CMD_CUSTOM_COMMAND;
00743 
00744 
00745 
00746         /**** UNKNOWN COMMAND ****/
00747         else{
00748                 /* log the bad external command */
00749                 logit(NSLOG_EXTERNAL_COMMAND | NSLOG_RUNTIME_WARNING,TRUE,"Warning: Unrecognized external command -> %s;%s\n",command_id,args);
00750 
00751                 /* free memory */
00752                 my_free(command_id);
00753                 my_free(args);
00754 
00755                 return ERROR;
00756                 }
00757 
00758         /* update statistics for external commands */
00759         update_check_stats(EXTERNAL_COMMAND_STATS,time(NULL));
00760 
00761         /* log the external command */
00762         if(log_external_commands_user==TRUE){
00763                 dummy=asprintf(&temp_buffer,"EXTERNAL COMMAND: %s;%s;%s\n",command_id,username,args);
00764         } else {
00765                 dummy=asprintf(&temp_buffer,"EXTERNAL COMMAND: %s;%s\n",command_id,args);
00766         }
00767 
00768         if(command_type==CMD_PROCESS_SERVICE_CHECK_RESULT || command_type==CMD_PROCESS_HOST_CHECK_RESULT){
00769                 /* passive checks are logged in checks.c as well, as some my bypass external commands by getting dropped in checkresults dir */
00770                 if(log_passive_checks==TRUE)
00771                         write_to_all_logs(temp_buffer,NSLOG_PASSIVE_CHECK);
00772                 }
00773         else{
00774                 if(log_external_commands==TRUE)
00775                         write_to_all_logs(temp_buffer,NSLOG_EXTERNAL_COMMAND);
00776                 }
00777         my_free(temp_buffer);
00778 
00779 #ifdef USE_EVENT_BROKER
00780         /* send data to event broker */
00781         broker_external_command(NEBTYPE_EXTERNALCOMMAND_START,NEBFLAG_NONE,NEBATTR_NONE,command_type,entry_time,command_id,args,NULL);
00782 #endif
00783 
00784         /* process the command */
00785         process_external_command2(command_type,entry_time,args);
00786 
00787 #ifdef USE_EVENT_BROKER
00788         /* send data to event broker */
00789         broker_external_command(NEBTYPE_EXTERNALCOMMAND_END,NEBFLAG_NONE,NEBATTR_NONE,command_type,entry_time,command_id,args,NULL);
00790 #endif
00791 
00792         /* free memory */
00793         my_free(command_id);
00794         my_free(args);
00795 
00796         return OK;
00797         }
00798 
00799 
00800 
00801 /* top-level processor for a single external command */
00802 int process_external_command2(int cmd, time_t entry_time, char *args){
00803 
00804         log_debug_info(DEBUGL_FUNCTIONS,0,"process_external_command2()\n");
00805 
00806         log_debug_info(DEBUGL_EXTERNALCOMMANDS,1,"External Command Type: %d\n",cmd);
00807         log_debug_info(DEBUGL_EXTERNALCOMMANDS,1,"Command Entry Time: %lu\n",(unsigned long)entry_time);
00808         log_debug_info(DEBUGL_EXTERNALCOMMANDS,1,"Command Arguments: %s\n",(args==NULL)?"":args);
00809 
00810         /* how shall we execute the command? */
00811         switch(cmd){
00812 
00813                 /***************************/
00814                 /***** SYSTEM COMMANDS *****/
00815                 /***************************/
00816 
00817         case CMD_SHUTDOWN_PROCESS:
00818         case CMD_RESTART_PROCESS:
00819                 cmd_signal_process(cmd,args);
00820                 break;
00821 
00822         case CMD_SAVE_STATE_INFORMATION:
00823                 save_state_information(FALSE);
00824                 break;
00825 
00826         case CMD_READ_STATE_INFORMATION:
00827                 read_initial_state_information();
00828                 break;
00829 
00830         case CMD_SYNC_STATE_INFORMATION:
00831                 sync_state_information();
00832                 break;
00833 
00834         case CMD_ENABLE_NOTIFICATIONS:
00835                 enable_all_notifications();
00836                 break;
00837 
00838         case CMD_DISABLE_NOTIFICATIONS:
00839                 disable_all_notifications();
00840                 break;
00841 
00842         case CMD_START_EXECUTING_SVC_CHECKS:
00843                 start_executing_service_checks();
00844                 break;
00845 
00846         case CMD_STOP_EXECUTING_SVC_CHECKS:
00847                 stop_executing_service_checks();
00848                 break;
00849 
00850         case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
00851                 start_accepting_passive_service_checks();
00852                 break;
00853 
00854         case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
00855                 stop_accepting_passive_service_checks();
00856                 break;
00857 
00858         case CMD_START_OBSESSING_OVER_SVC_CHECKS:
00859                 start_obsessing_over_service_checks();
00860                 break;
00861 
00862         case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
00863                 stop_obsessing_over_service_checks();
00864                 break;
00865 
00866         case CMD_START_EXECUTING_HOST_CHECKS:
00867                 start_executing_host_checks();
00868                 break;
00869 
00870         case CMD_STOP_EXECUTING_HOST_CHECKS:
00871                 stop_executing_host_checks();
00872                 break;
00873 
00874         case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
00875                 start_accepting_passive_host_checks();
00876                 break;
00877 
00878         case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
00879                 stop_accepting_passive_host_checks();
00880                 break;
00881 
00882         case CMD_START_OBSESSING_OVER_HOST_CHECKS:
00883                 start_obsessing_over_host_checks();
00884                 break;
00885 
00886         case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
00887                 stop_obsessing_over_host_checks();
00888                 break;
00889 
00890         case CMD_ENABLE_EVENT_HANDLERS:
00891                 start_using_event_handlers();
00892                 break;
00893 
00894         case CMD_DISABLE_EVENT_HANDLERS:
00895                 stop_using_event_handlers();
00896                 break;
00897 
00898         case CMD_ENABLE_FLAP_DETECTION:
00899                 enable_flap_detection_routines();
00900                 break;
00901 
00902         case CMD_DISABLE_FLAP_DETECTION:
00903                 disable_flap_detection_routines();
00904                 break;
00905 
00906         case CMD_ENABLE_SERVICE_FRESHNESS_CHECKS:
00907                 enable_service_freshness_checks();
00908                 break;
00909         
00910         case CMD_DISABLE_SERVICE_FRESHNESS_CHECKS:
00911                 disable_service_freshness_checks();
00912                 break;
00913         
00914         case CMD_ENABLE_HOST_FRESHNESS_CHECKS:
00915                 enable_host_freshness_checks();
00916                 break;
00917         
00918         case CMD_DISABLE_HOST_FRESHNESS_CHECKS:
00919                 disable_host_freshness_checks();
00920                 break;
00921         
00922         case CMD_ENABLE_FAILURE_PREDICTION:
00923                 enable_all_failure_prediction();
00924                 break;
00925                 
00926         case CMD_DISABLE_FAILURE_PREDICTION:
00927                 disable_all_failure_prediction();
00928                 break;
00929 
00930         case CMD_ENABLE_PERFORMANCE_DATA:
00931                 enable_performance_data();
00932                 break;
00933 
00934         case CMD_DISABLE_PERFORMANCE_DATA:
00935                 disable_performance_data();
00936                 break;
00937 
00938 
00939                 /***************************/
00940                 /*****  HOST COMMANDS  *****/
00941                 /***************************/
00942 
00943         case CMD_ENABLE_HOST_CHECK:
00944         case CMD_DISABLE_HOST_CHECK:
00945         case CMD_ENABLE_PASSIVE_HOST_CHECKS:
00946         case CMD_DISABLE_PASSIVE_HOST_CHECKS:
00947         case CMD_ENABLE_HOST_SVC_CHECKS:
00948         case CMD_DISABLE_HOST_SVC_CHECKS:
00949         case CMD_ENABLE_HOST_NOTIFICATIONS:
00950         case CMD_DISABLE_HOST_NOTIFICATIONS:
00951         case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
00952         case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
00953         case CMD_ENABLE_HOST_AND_CHILD_NOTIFICATIONS:
00954         case CMD_DISABLE_HOST_AND_CHILD_NOTIFICATIONS:
00955         case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
00956         case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
00957         case CMD_ENABLE_HOST_FLAP_DETECTION:
00958         case CMD_DISABLE_HOST_FLAP_DETECTION:
00959         case CMD_ENABLE_HOST_EVENT_HANDLER:
00960         case CMD_DISABLE_HOST_EVENT_HANDLER:
00961         case CMD_START_OBSESSING_OVER_HOST:
00962         case CMD_STOP_OBSESSING_OVER_HOST:
00963         case CMD_SET_HOST_NOTIFICATION_NUMBER:
00964         case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
00965                 process_host_command(cmd,entry_time,args);
00966                 break;
00967 
00968 
00969                 /*****************************/
00970                 /***** HOSTGROUP COMMANDS ****/
00971                 /*****************************/
00972 
00973         case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
00974         case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
00975         case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
00976         case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
00977         case CMD_ENABLE_HOSTGROUP_HOST_CHECKS:
00978         case CMD_DISABLE_HOSTGROUP_HOST_CHECKS:
00979         case CMD_ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS:
00980         case CMD_DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS:
00981         case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
00982         case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
00983         case CMD_ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS:
00984         case CMD_DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS:
00985                 process_hostgroup_command(cmd,entry_time,args);
00986                 break;
00987 
00988 
00989                 /***************************/
00990                 /***** SERVICE COMMANDS ****/
00991                 /***************************/
00992 
00993         case CMD_ENABLE_SVC_CHECK:
00994         case CMD_DISABLE_SVC_CHECK:
00995         case CMD_ENABLE_PASSIVE_SVC_CHECKS:
00996         case CMD_DISABLE_PASSIVE_SVC_CHECKS:
00997         case CMD_ENABLE_SVC_NOTIFICATIONS:
00998         case CMD_DISABLE_SVC_NOTIFICATIONS:
00999         case CMD_ENABLE_SVC_FLAP_DETECTION:
01000         case CMD_DISABLE_SVC_FLAP_DETECTION:
01001         case CMD_ENABLE_SVC_EVENT_HANDLER:
01002         case CMD_DISABLE_SVC_EVENT_HANDLER:
01003         case CMD_START_OBSESSING_OVER_SVC:
01004         case CMD_STOP_OBSESSING_OVER_SVC:
01005         case CMD_SET_SVC_NOTIFICATION_NUMBER:
01006         case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
01007                 process_service_command(cmd,entry_time,args);
01008                 break;
01009 
01010 
01011                 /********************************/
01012                 /***** SERVICEGROUP COMMANDS ****/
01013                 /********************************/
01014 
01015         case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
01016         case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
01017         case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
01018         case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
01019         case CMD_ENABLE_SERVICEGROUP_HOST_CHECKS:
01020         case CMD_DISABLE_SERVICEGROUP_HOST_CHECKS:
01021         case CMD_ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS:
01022         case CMD_DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS:
01023         case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
01024         case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
01025         case CMD_ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
01026         case CMD_DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
01027                 process_servicegroup_command(cmd,entry_time,args);
01028                 break;
01029 
01030 
01031                 /**********************************/
01032                 /**** CONTACT-RELATED COMMANDS ****/
01033                 /**********************************/
01034 
01035         case CMD_ENABLE_CONTACT_HOST_NOTIFICATIONS:
01036         case CMD_DISABLE_CONTACT_HOST_NOTIFICATIONS:
01037         case CMD_ENABLE_CONTACT_SVC_NOTIFICATIONS:
01038         case CMD_DISABLE_CONTACT_SVC_NOTIFICATIONS:
01039                 process_contact_command(cmd,entry_time,args);
01040                 break;
01041 
01042 
01043                 /***************************************/
01044                 /**** CONTACTGROUP-RELATED COMMANDS ****/
01045                 /***************************************/
01046 
01047         case CMD_ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS:
01048         case CMD_DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS:
01049         case CMD_ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
01050         case CMD_DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
01051                 process_contactgroup_command(cmd,entry_time,args);
01052                 break;
01053 
01054 
01055                 /***************************/
01056                 /**** UNSORTED COMMANDS ****/
01057                 /***************************/
01058 
01059 
01060         case CMD_ADD_HOST_COMMENT:
01061         case CMD_ADD_SVC_COMMENT:
01062                 cmd_add_comment(cmd,entry_time,args);
01063                 break;
01064 
01065         case CMD_DEL_HOST_COMMENT:
01066         case CMD_DEL_SVC_COMMENT:
01067                 cmd_delete_comment(cmd,args);
01068                 break;
01069 
01070         case CMD_DELAY_HOST_NOTIFICATION:
01071         case CMD_DELAY_SVC_NOTIFICATION:
01072                 cmd_delay_notification(cmd,args);
01073                 break;
01074 
01075         case CMD_SCHEDULE_SVC_CHECK:
01076         case CMD_SCHEDULE_FORCED_SVC_CHECK:
01077                 cmd_schedule_check(cmd,args);
01078                 break;
01079 
01080         case CMD_SCHEDULE_HOST_SVC_CHECKS:
01081         case CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS:
01082                 cmd_schedule_check(cmd,args);
01083                 break;
01084 
01085         case CMD_DEL_ALL_HOST_COMMENTS:
01086         case CMD_DEL_ALL_SVC_COMMENTS:
01087                 cmd_delete_all_comments(cmd,args);
01088                 break;
01089 
01090         case CMD_PROCESS_SERVICE_CHECK_RESULT:
01091                 cmd_process_service_check_result(cmd,entry_time,args);
01092                 break;
01093 
01094         case CMD_PROCESS_HOST_CHECK_RESULT:
01095                 cmd_process_host_check_result(cmd,entry_time,args);
01096                 break;
01097 
01098         case CMD_ACKNOWLEDGE_HOST_PROBLEM:
01099         case CMD_ACKNOWLEDGE_SVC_PROBLEM:
01100                 cmd_acknowledge_problem(cmd,args);
01101                 break;
01102 
01103         case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
01104         case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
01105                 cmd_remove_acknowledgement(cmd,args);
01106                 break;
01107 
01108         case CMD_SCHEDULE_HOST_DOWNTIME:
01109         case CMD_SCHEDULE_SVC_DOWNTIME:
01110         case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
01111         case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
01112         case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
01113         case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
01114         case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
01115         case CMD_SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME:
01116         case CMD_SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME:
01117                 cmd_schedule_downtime(cmd,entry_time,args);
01118                 break;
01119 
01120         case CMD_DEL_HOST_DOWNTIME:
01121         case CMD_DEL_SVC_DOWNTIME:
01122                 cmd_delete_downtime(cmd,args);
01123                 break;
01124 
01125         case CMD_DEL_DOWNTIME_BY_HOST_NAME:
01126                 cmd_delete_downtime_by_host_name(cmd,args);
01127                 break;
01128 
01129         case CMD_DEL_DOWNTIME_BY_HOSTGROUP_NAME:
01130                 cmd_delete_downtime_by_hostgroup_name(cmd,args);
01131                 break;
01132 
01133         case CMD_DEL_DOWNTIME_BY_START_TIME_COMMENT:
01134                 cmd_delete_downtime_by_start_time_comment(cmd,args);
01135                 break;
01136 
01137         case CMD_CANCEL_ACTIVE_HOST_SVC_DOWNTIME:
01138         case CMD_CANCEL_PENDING_HOST_SVC_DOWNTIME:
01139                 break;
01140 
01141         case CMD_SCHEDULE_HOST_CHECK:
01142         case CMD_SCHEDULE_FORCED_HOST_CHECK:
01143                 cmd_schedule_check(cmd,args);
01144                 break;
01145 
01146         case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
01147         case CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER:
01148         case CMD_CHANGE_HOST_EVENT_HANDLER:
01149         case CMD_CHANGE_SVC_EVENT_HANDLER:
01150         case CMD_CHANGE_HOST_CHECK_COMMAND:
01151         case CMD_CHANGE_SVC_CHECK_COMMAND:
01152         case CMD_CHANGE_HOST_CHECK_TIMEPERIOD:
01153         case CMD_CHANGE_SVC_CHECK_TIMEPERIOD:
01154         case CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD:
01155         case CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD:
01156         case CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD:
01157         case CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD:
01158                 cmd_change_object_char_var(cmd,args);
01159                 break;
01160 
01161         case CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL:
01162         case CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL:
01163         case CMD_CHANGE_NORMAL_SVC_CHECK_INTERVAL:
01164         case CMD_CHANGE_RETRY_SVC_CHECK_INTERVAL:
01165         case CMD_CHANGE_MAX_HOST_CHECK_ATTEMPTS:
01166         case CMD_CHANGE_MAX_SVC_CHECK_ATTEMPTS:
01167         case CMD_CHANGE_HOST_MODATTR:
01168         case CMD_CHANGE_SVC_MODATTR:
01169         case CMD_CHANGE_CONTACT_MODATTR:
01170         case CMD_CHANGE_CONTACT_MODHATTR:
01171         case CMD_CHANGE_CONTACT_MODSATTR:
01172                 cmd_change_object_int_var(cmd,args);
01173                 break;
01174 
01175         case CMD_CHANGE_CUSTOM_HOST_VAR:
01176         case CMD_CHANGE_CUSTOM_SVC_VAR:
01177         case CMD_CHANGE_CUSTOM_CONTACT_VAR:
01178                 cmd_change_object_custom_var(cmd,args);
01179                 break;
01180 
01181 
01182                 /***********************/
01183                 /**** MISC COMMANDS ****/
01184                 /***********************/
01185 
01186 
01187         case CMD_PROCESS_FILE:
01188                 cmd_process_external_commands_from_file(cmd,args);
01189                 break;
01190 
01191 
01192                 /*************************/
01193                 /**** CUSTOM COMMANDS ****/
01194                 /*************************/
01195 
01196 
01197         case CMD_CUSTOM_COMMAND:
01198                 /* custom commands aren't handled internally by Icinga, but may be by NEB modules */
01199                 break;
01200 
01201         default:
01202                 return ERROR;
01203                 break;
01204                 }
01205 
01206         return OK;
01207         }
01208 
01209 
01210 /* processes an external host command */
01211 int process_host_command(int cmd, time_t entry_time, char *args){
01212         char *host_name=NULL;
01213         host *temp_host=NULL;
01214         service *temp_service=NULL;
01215         servicesmember *temp_servicesmember=NULL;
01216         char *str=NULL;
01217         char *buf[2]={NULL,NULL};
01218         int intval=0;
01219 
01220         printf("ARGS: %s\n",args);
01221 
01222         /* get the host name */
01223         if((host_name=my_strtok(args,";"))==NULL)
01224                 return ERROR;
01225 
01226         /* find the host */
01227         if((temp_host=find_host(host_name))==NULL)
01228                 return ERROR;
01229 
01230         switch(cmd){
01231 
01232         case CMD_ENABLE_HOST_NOTIFICATIONS:
01233                 enable_host_notifications(temp_host);
01234                 break;
01235 
01236         case CMD_DISABLE_HOST_NOTIFICATIONS:
01237                 disable_host_notifications(temp_host);
01238                 break;
01239 
01240         case CMD_ENABLE_HOST_AND_CHILD_NOTIFICATIONS:
01241                 enable_and_propagate_notifications(temp_host,0,TRUE,TRUE,FALSE);
01242                 break;
01243 
01244         case CMD_DISABLE_HOST_AND_CHILD_NOTIFICATIONS:
01245                 disable_and_propagate_notifications(temp_host,0,TRUE,TRUE,FALSE);
01246                 break;
01247 
01248         case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
01249                 enable_and_propagate_notifications(temp_host,0,FALSE,TRUE,TRUE);
01250                 break;
01251 
01252         case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
01253                 disable_and_propagate_notifications(temp_host,0,FALSE,TRUE,TRUE);
01254                 break;
01255 
01256         case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
01257         case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
01258                 for(temp_servicesmember=temp_host->services;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
01259                         if((temp_service=temp_servicesmember->service_ptr)==NULL)
01260                                 continue;
01261                         if(cmd==CMD_ENABLE_HOST_SVC_NOTIFICATIONS)
01262                                 enable_service_notifications(temp_service);
01263                         else
01264                                 disable_service_notifications(temp_service);
01265                         }
01266                 break;
01267 
01268         case CMD_ENABLE_HOST_SVC_CHECKS:
01269         case CMD_DISABLE_HOST_SVC_CHECKS:
01270                 for(temp_servicesmember=temp_host->services;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
01271                         if((temp_service=temp_servicesmember->service_ptr)==NULL)
01272                                 continue;
01273                         if(cmd==CMD_ENABLE_HOST_SVC_CHECKS)
01274                                 enable_service_checks(temp_service);
01275                         else
01276                                 disable_service_checks(temp_service);
01277                         } 
01278                 break;
01279 
01280         case CMD_ENABLE_HOST_CHECK:
01281                 enable_host_checks(temp_host);
01282                 break;
01283 
01284         case CMD_DISABLE_HOST_CHECK:
01285                 disable_host_checks(temp_host);
01286                 break;
01287 
01288         case CMD_ENABLE_HOST_EVENT_HANDLER:
01289                 enable_host_event_handler(temp_host);
01290                 break;
01291 
01292         case CMD_DISABLE_HOST_EVENT_HANDLER:
01293                 disable_host_event_handler(temp_host);
01294                 break;
01295 
01296         case CMD_ENABLE_HOST_FLAP_DETECTION:
01297                 enable_host_flap_detection(temp_host);
01298                 break;
01299 
01300         case CMD_DISABLE_HOST_FLAP_DETECTION:
01301                 disable_host_flap_detection(temp_host);
01302                 break;
01303 
01304         case CMD_ENABLE_PASSIVE_HOST_CHECKS:
01305                 enable_passive_host_checks(temp_host);
01306                 break;
01307 
01308         case CMD_DISABLE_PASSIVE_HOST_CHECKS:
01309                 disable_passive_host_checks(temp_host);
01310                 break;
01311 
01312         case CMD_START_OBSESSING_OVER_HOST:
01313                 start_obsessing_over_host(temp_host);
01314                 break;
01315 
01316         case CMD_STOP_OBSESSING_OVER_HOST:
01317                 stop_obsessing_over_host(temp_host);
01318                 break;
01319 
01320         case CMD_SET_HOST_NOTIFICATION_NUMBER:
01321                 if((str=my_strtok(NULL,";"))){
01322                         intval=atoi(str);
01323                         set_host_notification_number(temp_host,intval);
01324                         }
01325                 break;
01326 
01327         case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
01328                 if((str=my_strtok(NULL,";")))
01329                         intval=atoi(str);
01330                 str=my_strtok(NULL,";");
01331                 if(str)
01332                         buf[0]=strdup(str);
01333                 str=my_strtok(NULL,";");
01334                 if(str)
01335                         buf[1]=strdup(str);
01336                 if(buf[0] && buf[1])
01337                         host_notification(temp_host,NOTIFICATION_CUSTOM,buf[0],buf[1],intval);
01338                 break;
01339 
01340         default:
01341                 break;
01342                 }
01343 
01344         return OK;
01345         }
01346 
01347 
01348 /* processes an external hostgroup command */
01349 int process_hostgroup_command(int cmd, time_t entry_time, char *args){
01350         char *hostgroup_name=NULL;
01351         hostgroup *temp_hostgroup=NULL;
01352         hostsmember *temp_member=NULL;
01353         host *temp_host=NULL;
01354         service *temp_service=NULL;
01355         servicesmember *temp_servicesmember=NULL;
01356 
01357         /* get the hostgroup name */
01358         if((hostgroup_name=my_strtok(args,";"))==NULL)
01359                 return ERROR;
01360 
01361         /* find the hostgroup */
01362         if((temp_hostgroup=find_hostgroup(hostgroup_name))==NULL)
01363                 return ERROR;
01364 
01365         /* loop through all hosts in the hostgroup */
01366         for(temp_member=temp_hostgroup->members;temp_member!=NULL;temp_member=temp_member->next){
01367 
01368                 if((temp_host=(host *)temp_member->host_ptr)==NULL)
01369                         continue;
01370 
01371                 switch(cmd){
01372 
01373                 case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
01374                         enable_host_notifications(temp_host);
01375                         break;
01376 
01377                 case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
01378                         disable_host_notifications(temp_host);
01379                         break;
01380 
01381                 case CMD_ENABLE_HOSTGROUP_HOST_CHECKS:
01382                         enable_host_checks(temp_host);
01383                         break;
01384 
01385                 case CMD_DISABLE_HOSTGROUP_HOST_CHECKS:
01386                         disable_host_checks(temp_host);
01387                         break;
01388 
01389                 case CMD_ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS:
01390                         enable_passive_host_checks(temp_host);
01391                         break;
01392 
01393                 case CMD_DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS:
01394                         disable_passive_host_checks(temp_host);
01395                         break;
01396 
01397                 default:
01398 
01399                         /* loop through all services on the host */
01400                         for(temp_servicesmember=temp_host->services;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
01401                                 if((temp_service=temp_servicesmember->service_ptr)==NULL)
01402                                         continue;
01403                                         
01404                                 switch(cmd){
01405 
01406                                 case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
01407                                         enable_service_notifications(temp_service);
01408                                         break;
01409 
01410                                 case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
01411                                         disable_service_notifications(temp_service);
01412                                         break;
01413 
01414                                 case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
01415                                         enable_service_checks(temp_service);
01416                                         break;
01417 
01418                                 case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
01419                                         disable_service_checks(temp_service);
01420                                         break;
01421 
01422                                 case CMD_ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS:
01423                                         enable_passive_service_checks(temp_service);
01424                                         break;
01425 
01426                                 case CMD_DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS:
01427                                         disable_passive_service_checks(temp_service);
01428                                         break;
01429 
01430                                 default:
01431                                         break;
01432                                         }
01433                                 }
01434                         
01435                         break;
01436                         }
01437 
01438                 }
01439 
01440         return OK;
01441         }
01442 
01443 
01444 
01445 /* processes an external service command */
01446 int process_service_command(int cmd, time_t entry_time, char *args){
01447         char *host_name=NULL;
01448         char *svc_description=NULL;
01449         service *temp_service=NULL;
01450         char *str=NULL;
01451         char *buf[2]={NULL,NULL};
01452         int intval=0;
01453 
01454         /* get the host name */
01455         if((host_name=my_strtok(args,";"))==NULL)
01456                 return ERROR;
01457 
01458         /* get the service description */
01459         if((svc_description=my_strtok(NULL,";"))==NULL)
01460                 return ERROR;
01461 
01462         /* find the service */
01463         if((temp_service=find_service(host_name,svc_description))==NULL)
01464                 return ERROR;
01465 
01466         switch(cmd){
01467 
01468         case CMD_ENABLE_SVC_NOTIFICATIONS:
01469                 enable_service_notifications(temp_service);
01470                 break;
01471 
01472         case CMD_DISABLE_SVC_NOTIFICATIONS:
01473                 disable_service_notifications(temp_service);
01474                 break;
01475 
01476         case CMD_ENABLE_SVC_CHECK:
01477                 enable_service_checks(temp_service);
01478                 break;
01479 
01480         case CMD_DISABLE_SVC_CHECK:
01481                 disable_service_checks(temp_service);
01482                 break;
01483 
01484         case CMD_ENABLE_SVC_EVENT_HANDLER:
01485                 enable_service_event_handler(temp_service);
01486                 break;
01487 
01488         case CMD_DISABLE_SVC_EVENT_HANDLER:
01489                 disable_service_event_handler(temp_service);
01490                 break;
01491 
01492         case CMD_ENABLE_SVC_FLAP_DETECTION:
01493                 enable_service_flap_detection(temp_service);
01494                 break;
01495 
01496         case CMD_DISABLE_SVC_FLAP_DETECTION:
01497                 disable_service_flap_detection(temp_service);
01498                 break;
01499 
01500         case CMD_ENABLE_PASSIVE_SVC_CHECKS:
01501                 enable_passive_service_checks(temp_service);
01502                 break;
01503 
01504         case CMD_DISABLE_PASSIVE_SVC_CHECKS:
01505                 disable_passive_service_checks(temp_service);
01506                 break;
01507 
01508         case CMD_START_OBSESSING_OVER_SVC:
01509                 start_obsessing_over_service(temp_service);
01510                 break;
01511 
01512         case CMD_STOP_OBSESSING_OVER_SVC:
01513                 stop_obsessing_over_service(temp_service);
01514                 break;
01515 
01516         case CMD_SET_SVC_NOTIFICATION_NUMBER:
01517                 if((str=my_strtok(NULL,";"))){
01518                         intval=atoi(str);
01519                         set_service_notification_number(temp_service,intval);
01520                         }
01521                 break;
01522 
01523         case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
01524                 if((str=my_strtok(NULL,";")))
01525                         intval=atoi(str);
01526                 str=my_strtok(NULL,";");
01527                 if(str)
01528                         buf[0]=strdup(str);
01529                 str=my_strtok(NULL,";");
01530                 if(str)
01531                         buf[1]=strdup(str);
01532                 if(buf[0] && buf[1])
01533                         service_notification(temp_service,NOTIFICATION_CUSTOM,buf[0],buf[1],intval);
01534                 break;
01535 
01536         default:
01537                 break;
01538                 }
01539 
01540         return OK;
01541         }
01542 
01543 
01544 /* processes an external servicegroup command */
01545 int process_servicegroup_command(int cmd, time_t entry_time, char *args){
01546         char *servicegroup_name=NULL;
01547         servicegroup *temp_servicegroup=NULL;
01548         servicesmember *temp_member=NULL;
01549         host *temp_host=NULL;
01550         host *last_host=NULL;
01551         service *temp_service=NULL;
01552 
01553         /* get the servicegroup name */
01554         if((servicegroup_name=my_strtok(args,";"))==NULL)
01555                 return ERROR;
01556 
01557         /* find the servicegroup */
01558         if((temp_servicegroup=find_servicegroup(servicegroup_name))==NULL)
01559                 return ERROR;
01560 
01561         switch(cmd){
01562 
01563         case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
01564         case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
01565         case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
01566         case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
01567         case CMD_ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
01568         case CMD_DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
01569 
01570                 /* loop through all servicegroup members */
01571                 for(temp_member=temp_servicegroup->members;temp_member!=NULL;temp_member=temp_member->next){
01572 
01573                         temp_service=find_service(temp_member->host_name,temp_member->service_description);
01574                         if(temp_service==NULL)
01575                                 continue;
01576 
01577                         switch(cmd){
01578 
01579                         case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
01580                                 enable_service_notifications(temp_service);
01581                                 break;
01582 
01583                         case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
01584                                 disable_service_notifications(temp_service);
01585                                 break;
01586 
01587                         case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
01588                                 enable_service_checks(temp_service);
01589                                 break;
01590 
01591                         case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
01592                                 disable_service_checks(temp_service);
01593                                 break;
01594 
01595                         case CMD_ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
01596                                 enable_passive_service_checks(temp_service);
01597                                 break;
01598 
01599                         case CMD_DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
01600                                 disable_passive_service_checks(temp_service);
01601                                 break;
01602 
01603                         default:
01604                                 break;
01605                                 }
01606                         }
01607 
01608                 break;
01609 
01610         case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
01611         case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
01612         case CMD_ENABLE_SERVICEGROUP_HOST_CHECKS:
01613         case CMD_DISABLE_SERVICEGROUP_HOST_CHECKS:
01614         case CMD_ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS:
01615         case CMD_DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS:
01616 
01617                 /* loop through all hosts that have services belonging to the servicegroup */
01618                 last_host=NULL;
01619                 for(temp_member=temp_servicegroup->members;temp_member!=NULL;temp_member=temp_member->next){
01620 
01621                         if((temp_host=find_host(temp_member->host_name))==NULL)
01622                                 continue;
01623 
01624                         if(temp_host==last_host)
01625                                 continue;
01626 
01627                         switch(cmd){
01628 
01629                         case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
01630                                 enable_host_notifications(temp_host);
01631                                 break;
01632 
01633                         case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
01634                                 disable_host_notifications(temp_host);
01635                                 break;
01636 
01637                         case CMD_ENABLE_SERVICEGROUP_HOST_CHECKS:
01638                                 enable_host_checks(temp_host);
01639                                 break;
01640 
01641                         case CMD_DISABLE_SERVICEGROUP_HOST_CHECKS:
01642                                 disable_host_checks(temp_host);
01643                                 break;
01644 
01645                         case CMD_ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS:
01646                                 enable_passive_host_checks(temp_host);
01647                                 break;
01648 
01649                         case CMD_DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS:
01650                                 disable_passive_host_checks(temp_host);
01651                                 break;
01652 
01653                         default:
01654                                 break;
01655                                 }
01656 
01657                         last_host=temp_host;
01658                         }
01659 
01660                 break;
01661 
01662         default:
01663                 break;
01664                 }
01665 
01666         return OK;
01667         }
01668 
01669 
01670 
01671 /* processes an external contact command */
01672 int process_contact_command(int cmd, time_t entry_time, char *args){
01673         char *contact_name=NULL;
01674         contact *temp_contact=NULL;
01675 
01676         /* get the contact name */
01677         if((contact_name=my_strtok(args,";"))==NULL)
01678                 return ERROR;
01679 
01680         /* find the contact */
01681         if((temp_contact=find_contact(contact_name))==NULL)
01682                 return ERROR;
01683 
01684         switch(cmd){
01685 
01686         case CMD_ENABLE_CONTACT_HOST_NOTIFICATIONS:
01687                 enable_contact_host_notifications(temp_contact);
01688                 break;
01689 
01690         case CMD_DISABLE_CONTACT_HOST_NOTIFICATIONS:
01691                 disable_contact_host_notifications(temp_contact);
01692                 break;
01693 
01694         case CMD_ENABLE_CONTACT_SVC_NOTIFICATIONS:
01695                 enable_contact_service_notifications(temp_contact);
01696                 break;
01697 
01698         case CMD_DISABLE_CONTACT_SVC_NOTIFICATIONS:
01699                 disable_contact_service_notifications(temp_contact);
01700                 break;
01701 
01702         default:
01703                 break;
01704                 }
01705 
01706         return OK;
01707         }
01708 
01709 
01710 /* processes an external contactgroup command */
01711 int process_contactgroup_command(int cmd, time_t entry_time, char *args){
01712         char *contactgroup_name=NULL;
01713         contactgroup *temp_contactgroup=NULL;
01714         contactsmember *temp_member=NULL;
01715         contact *temp_contact=NULL;
01716 
01717         /* get the contactgroup name */
01718         if((contactgroup_name=my_strtok(args,";"))==NULL)
01719                 return ERROR;
01720 
01721         /* find the contactgroup */
01722         if((temp_contactgroup=find_contactgroup(contactgroup_name))==NULL)
01723                 return ERROR;
01724 
01725         switch(cmd){
01726 
01727         case CMD_ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS:
01728         case CMD_DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS:
01729         case CMD_ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
01730         case CMD_DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
01731 
01732                 /* loop through all contactgroup members */
01733                 for(temp_member=temp_contactgroup->members;temp_member!=NULL;temp_member=temp_member->next){
01734 
01735                         if((temp_contact=temp_member->contact_ptr)==NULL)
01736                                 continue;
01737 
01738                         switch(cmd){
01739 
01740                         case CMD_ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS:
01741                                 enable_contact_host_notifications(temp_contact);
01742                                 break;
01743 
01744                         case CMD_DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS:
01745                                 disable_contact_host_notifications(temp_contact);
01746                                 break;
01747 
01748                         case CMD_ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
01749                                 enable_contact_service_notifications(temp_contact);
01750                                 break;
01751 
01752                         case CMD_DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
01753                                 disable_contact_service_notifications(temp_contact);
01754                                 break;
01755 
01756                         default:
01757                                 break;
01758                                 }
01759                         }
01760 
01761                 break;
01762 
01763         default:
01764                 break;
01765                 }
01766 
01767         return OK;
01768         }
01769 
01770 
01771 
01772 /******************************************************************/
01773 /*************** EXTERNAL COMMAND IMPLEMENTATIONS  ****************/
01774 /******************************************************************/
01775 
01776 /* adds a host or service comment to the status log */
01777 int cmd_add_comment(int cmd,time_t entry_time,char *args){
01778         char *temp_ptr=NULL;
01779         host *temp_host=NULL;
01780         service *temp_service=NULL;
01781         char *host_name=NULL;
01782         char *svc_description=NULL;
01783         char *user=NULL;
01784         char *comment_data=NULL;
01785         int persistent=0;
01786         int result=0;
01787 
01788         /* get the host name */
01789         if((host_name=my_strtok(args,";"))==NULL)
01790                 return ERROR;
01791 
01792         /* if we're adding a service comment...  */
01793         if(cmd==CMD_ADD_SVC_COMMENT){
01794 
01795                 /* get the service description */
01796                 if((svc_description=my_strtok(NULL,";"))==NULL)
01797                         return ERROR;
01798 
01799                 /* verify that the service is valid */
01800                 if((temp_service=find_service(host_name,svc_description))==NULL)
01801                         return ERROR;
01802                 }
01803 
01804         /* else verify that the host is valid */
01805         if((temp_host=find_host(host_name))==NULL)
01806                 return ERROR;
01807 
01808         /* get the persistent flag */
01809         if((temp_ptr=my_strtok(NULL,";"))==NULL)
01810                 return ERROR;
01811         persistent=atoi(temp_ptr);
01812         if(persistent>1)
01813                 persistent=1;
01814         else if(persistent<0)
01815                 persistent=0;
01816 
01817         /* get the name of the user who entered the comment */
01818         if((user=my_strtok(NULL,";"))==NULL)
01819                 return ERROR;
01820 
01821         /* get the comment */
01822         if((comment_data=my_strtok(NULL,"\n"))==NULL)
01823                 return ERROR;
01824 
01825         /* add the comment */
01826         result=add_new_comment((cmd==CMD_ADD_HOST_COMMENT)?HOST_COMMENT:SERVICE_COMMENT,USER_COMMENT,host_name,svc_description,entry_time,user,comment_data,persistent,COMMENTSOURCE_EXTERNAL,FALSE,(time_t)0,NULL);
01827 
01828         if(result<0)
01829                 return ERROR;
01830 
01831         return OK;
01832         }
01833 
01834 
01835 
01836 /* removes a host or service comment from the status log */
01837 int cmd_delete_comment(int cmd,char *args){
01838         unsigned long comment_id=0L;
01839 
01840         /* get the comment id we should delete */
01841         if((comment_id=strtoul(args,NULL,10))==0)
01842                 return ERROR;
01843 
01844         /* delete the specified comment */
01845         if(cmd==CMD_DEL_HOST_COMMENT)
01846                 delete_host_comment(comment_id);
01847         else
01848                 delete_service_comment(comment_id);
01849 
01850         return OK;
01851         }
01852 
01853 
01854 
01855 /* removes all comments associated with a host or service from the status log */
01856 int cmd_delete_all_comments(int cmd,char *args){
01857         service *temp_service=NULL;
01858         host *temp_host=NULL;
01859         char *host_name=NULL;
01860         char *svc_description=NULL;
01861 
01862         /* get the host name */
01863         if((host_name=my_strtok(args,";"))==NULL)
01864                 return ERROR;
01865 
01866         /* if we're deleting service comments...  */
01867         if(cmd==CMD_DEL_ALL_SVC_COMMENTS){
01868 
01869                 /* get the service description */
01870                 if((svc_description=my_strtok(NULL,";"))==NULL)
01871                         return ERROR;
01872 
01873                 /* verify that the service is valid */
01874                 if((temp_service=find_service(host_name,svc_description))==NULL)
01875                         return ERROR;
01876                 }
01877 
01878         /* else verify that the host is valid */
01879         if((temp_host=find_host(host_name))==NULL)
01880                 return ERROR;
01881 
01882         /* delete comments */
01883         delete_all_comments((cmd==CMD_DEL_ALL_HOST_COMMENTS)?HOST_COMMENT:SERVICE_COMMENT,host_name,svc_description);
01884 
01885         return OK;
01886         }
01887 
01888 
01889 
01890 /* delays a host or service notification for given number of minutes */
01891 int cmd_delay_notification(int cmd,char *args){
01892         char *temp_ptr=NULL;
01893         host *temp_host=NULL;
01894         service *temp_service=NULL;
01895         char *host_name=NULL;
01896         char *svc_description=NULL;
01897         time_t delay_time=0L;
01898 
01899         /* get the host name */
01900         if((host_name=my_strtok(args,";"))==NULL)
01901                 return ERROR;
01902 
01903         /* if this is a service notification delay...  */
01904         if(cmd==CMD_DELAY_SVC_NOTIFICATION){
01905 
01906                 /* get the service description */
01907                 if((svc_description=my_strtok(NULL,";"))==NULL)
01908                         return ERROR;
01909 
01910                 /* verify that the service is valid */
01911                 if((temp_service=find_service(host_name,svc_description))==NULL)
01912                         return ERROR;
01913                 }
01914 
01915         /* else verify that the host is valid */
01916         else{
01917 
01918                 if((temp_host=find_host(host_name))==NULL)
01919                         return ERROR;
01920                 }
01921 
01922         /* get the time that we should delay until... */
01923         if((temp_ptr=my_strtok(NULL,"\n"))==NULL)
01924                 return ERROR;
01925         delay_time=strtoul(temp_ptr,NULL,10);
01926 
01927         /* delay the next notification... */
01928         if(cmd==CMD_DELAY_HOST_NOTIFICATION)
01929                 temp_host->next_host_notification=delay_time;
01930         else
01931                 temp_service->next_notification=delay_time;
01932 
01933         return OK;
01934         }
01935 
01936 
01937 
01938 /* schedules a host check at a particular time */
01939 int cmd_schedule_check(int cmd,char *args){
01940         char *temp_ptr=NULL;
01941         host *temp_host=NULL;
01942         service *temp_service=NULL;
01943         servicesmember *temp_servicesmember=NULL;
01944         char *host_name=NULL;
01945         char *svc_description=NULL;
01946         time_t delay_time=0L;
01947 
01948         /* get the host name */
01949         if((host_name=my_strtok(args,";"))==NULL)
01950                 return ERROR;
01951 
01952         if(cmd==CMD_SCHEDULE_HOST_CHECK || cmd==CMD_SCHEDULE_FORCED_HOST_CHECK || cmd==CMD_SCHEDULE_HOST_SVC_CHECKS || cmd==CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS){
01953 
01954                 /* verify that the host is valid */
01955                 if((temp_host=find_host(host_name))==NULL)
01956                         return ERROR;
01957                 }
01958         else{
01959 
01960                 /* get the service description */
01961                 if((svc_description=my_strtok(NULL,";"))==NULL)
01962                         return ERROR;
01963 
01964                 /* verify that the service is valid */
01965                 if((temp_service=find_service(host_name,svc_description))==NULL)
01966                         return ERROR;
01967                 }
01968 
01969         /* get the next check time */
01970         if((temp_ptr=my_strtok(NULL,"\n"))==NULL)
01971                 return ERROR;
01972         delay_time=strtoul(temp_ptr,NULL,10);
01973 
01974         /* schedule the host check */
01975         if(cmd==CMD_SCHEDULE_HOST_CHECK || cmd==CMD_SCHEDULE_FORCED_HOST_CHECK)
01976                 schedule_host_check(temp_host,delay_time,(cmd==CMD_SCHEDULE_FORCED_HOST_CHECK)?CHECK_OPTION_FORCE_EXECUTION:CHECK_OPTION_NONE);
01977 
01978         /* schedule service checks */
01979         else if(cmd==CMD_SCHEDULE_HOST_SVC_CHECKS || cmd==CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS){
01980                 for(temp_servicesmember=temp_host->services;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
01981                         if((temp_service=temp_servicesmember->service_ptr)==NULL)
01982                                 continue;
01983                         schedule_service_check(temp_service,delay_time,(cmd==CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS)?CHECK_OPTION_FORCE_EXECUTION:CHECK_OPTION_NONE);
01984                         }
01985                 }
01986         else
01987                 schedule_service_check(temp_service,delay_time,(cmd==CMD_SCHEDULE_FORCED_SVC_CHECK)?CHECK_OPTION_FORCE_EXECUTION:CHECK_OPTION_NONE);
01988 
01989         return OK;
01990         }
01991 
01992 
01993 
01994 /* schedules all service checks on a host for a particular time */
01995 int cmd_schedule_host_service_checks(int cmd,char *args, int force){
01996         char *temp_ptr=NULL;
01997         service *temp_service=NULL;
01998         servicesmember *temp_servicesmember=NULL;
01999         host *temp_host=NULL;
02000         char *host_name=NULL;
02001         time_t delay_time=0L;
02002 
02003         /* get the host name */
02004         if((host_name=my_strtok(args,";"))==NULL)
02005                 return ERROR;
02006 
02007         /* verify that the host is valid */
02008         if((temp_host=find_host(host_name))==NULL)
02009                 return ERROR;
02010 
02011         /* get the next check time */
02012         if((temp_ptr=my_strtok(NULL,"\n"))==NULL)
02013                 return ERROR;
02014         delay_time=strtoul(temp_ptr,NULL,10);
02015 
02016         /* reschedule all services on the specified host */
02017         for(temp_servicesmember=temp_host->services;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
02018                 if((temp_service=temp_servicesmember->service_ptr)==NULL)
02019                         continue;
02020                 schedule_service_check(temp_service,delay_time,(force==TRUE)?CHECK_OPTION_FORCE_EXECUTION:CHECK_OPTION_NONE);
02021                 }
02022 
02023         return OK;
02024         }
02025 
02026 
02027 
02028 
02029 /* schedules a program shutdown or restart */
02030 int cmd_signal_process(int cmd, char *args){
02031         time_t scheduled_time=0L;
02032         char *temp_ptr=NULL;
02033         int result=OK;
02034 
02035         /* get the time to schedule the event */
02036         if((temp_ptr=my_strtok(args,"\n"))==NULL)
02037                 scheduled_time=0L;
02038         else
02039                 scheduled_time=strtoul(temp_ptr,NULL,10);
02040 
02041         /* add a scheduled program shutdown or restart to the event list */
02042         result=schedule_new_event((cmd==CMD_SHUTDOWN_PROCESS)?EVENT_PROGRAM_SHUTDOWN:EVENT_PROGRAM_RESTART,TRUE,scheduled_time,FALSE,0,NULL,FALSE,NULL,NULL,0);
02043 
02044         return result;
02045         }
02046 
02047 
02048 
02049 /* processes results of an external service check */
02050 int cmd_process_service_check_result(int cmd,time_t check_time,char *args){
02051         char *temp_ptr=NULL;
02052         char *host_name=NULL;
02053         char *svc_description=NULL;
02054         int return_code=0;
02055         char *output=NULL;
02056         int result=0;
02057 
02058         /* get the host name */
02059         if((temp_ptr=my_strtok(args,";"))==NULL)
02060                 return ERROR;
02061         host_name=(char *)strdup(temp_ptr);
02062 
02063         /* get the service description */
02064         if((temp_ptr=my_strtok(NULL,";"))==NULL){
02065                 my_free(host_name);
02066                 return ERROR;
02067                 }
02068         svc_description=(char *)strdup(temp_ptr);
02069 
02070         /* get the service check return code */
02071         if((temp_ptr=my_strtok(NULL,";"))==NULL){
02072                 my_free(host_name);
02073                 my_free(svc_description);
02074                 return ERROR;
02075                 }
02076         return_code=atoi(temp_ptr);
02077 
02078         /* get the plugin output (may be empty) */
02079         if((temp_ptr=my_strtok(NULL,"\n"))==NULL)
02080                 output=(char *)strdup("");
02081         else
02082                 output=(char *)strdup(temp_ptr);
02083 
02084         /* submit the passive check result */
02085         result=process_passive_service_check(check_time,host_name,svc_description,return_code,output);
02086 
02087         /* free memory */
02088         my_free(host_name);
02089         my_free(svc_description);
02090         my_free(output);
02091 
02092         return result;
02093         }
02094 
02095 
02096 
02097 /* submits a passive service check result for later processing */
02098 int process_passive_service_check(time_t check_time, char *host_name, char *svc_description, int return_code, char *output){
02099         passive_check_result *new_pcr=NULL;
02100         host *temp_host=NULL;
02101         service *temp_service=NULL;
02102         char *real_host_name=NULL;
02103         struct timeval tv;
02104         int result=OK;
02105 
02106         /* skip this service check result if we aren't accepting passive service checks */
02107         if(accept_passive_service_checks==FALSE)
02108                 return ERROR;
02109 
02110         /* make sure we have all required data */
02111         if(host_name==NULL || svc_description==NULL || output==NULL)
02112                 return ERROR;
02113 
02114         /* find the host by its name or address */
02115         if(find_host(host_name)!=NULL)
02116                 real_host_name=host_name;
02117         else{
02118                 for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
02119                         if(!strcmp(host_name,temp_host->address)){
02120                                 real_host_name=temp_host->name;
02121                                 break;
02122                                 }
02123                         else if(!strcmp(host_name,temp_host->address6)){
02124                                 real_host_name=temp_host->name;
02125                                 break;
02126                                 }
02127                         }
02128                 }
02129 
02130         /* we couldn't find the host */
02131         if(real_host_name==NULL){
02132                 logit(NSLOG_RUNTIME_WARNING,TRUE,"Warning:  Passive check result was received for service '%s' on host '%s', but the host could not be found!\n",svc_description,host_name);
02133                 return ERROR;
02134                 }
02135 
02136         /* make sure the service exists */
02137         if((temp_service=find_service(real_host_name,svc_description))==NULL){
02138                 logit(NSLOG_RUNTIME_WARNING,TRUE,"Warning:  Passive check result was received for service '%s' on host '%s', but the service could not be found!\n",svc_description,host_name);
02139                 return ERROR;
02140                 }
02141 
02142         /* skip this is we aren't accepting passive checks for this service */
02143         if(temp_service->accept_passive_service_checks==FALSE)
02144                 return ERROR;
02145 
02146         /* allocate memory for the passive check result */
02147         new_pcr=(passive_check_result *)malloc(sizeof(passive_check_result));
02148         if(new_pcr==NULL)
02149                 return ERROR;
02150 
02151         /* initialize vars */
02152         new_pcr->object_check_type=SERVICE_CHECK;
02153         new_pcr->host_name=NULL;
02154         new_pcr->service_description=NULL;
02155         new_pcr->output=NULL;
02156         new_pcr->next=NULL;
02157 
02158         /* save string vars */
02159         if((new_pcr->host_name=(char *)strdup(real_host_name))==NULL)
02160                 result=ERROR;
02161         if((new_pcr->service_description=(char *)strdup(svc_description))==NULL)
02162                 result=ERROR;
02163         if((new_pcr->output=(char *)strdup(output))==NULL)
02164                 result=ERROR;
02165 
02166         /* handle errors */
02167         if(result==ERROR){
02168                 my_free(new_pcr->output);
02169                 my_free(new_pcr->service_description);
02170                 my_free(new_pcr->host_name);
02171                 my_free(new_pcr);
02172                 return ERROR;
02173                 }
02174 
02175         /* save the return code */
02176         new_pcr->return_code=return_code;
02177 
02178         /* make sure the return code is within bounds */
02179         if(new_pcr->return_code<0 || new_pcr->return_code>3)
02180                 new_pcr->return_code=STATE_UNKNOWN;
02181 
02182         new_pcr->check_time=check_time;
02183 
02184         /* calculate latency */
02185         gettimeofday(&tv,NULL);
02186         new_pcr->latency=(double)((double)(tv.tv_sec-check_time)+(double)(tv.tv_usec/1000.0)/1000.0);
02187         if(new_pcr->latency<0.0)
02188                 new_pcr->latency=0.0;
02189 
02190         /* add the passive check result to the end of the list in memory */
02191         if(passive_check_result_list==NULL)
02192                 passive_check_result_list=new_pcr;
02193         else
02194                 passive_check_result_list_tail->next=new_pcr;
02195         passive_check_result_list_tail=new_pcr;
02196 
02197         return OK;
02198         }
02199 
02200 
02201 
02202 /* process passive host check result */
02203 int cmd_process_host_check_result(int cmd,time_t check_time,char *args){
02204         char *temp_ptr=NULL;
02205         char *host_name=NULL;
02206         int return_code=0;
02207         char *output=NULL;
02208         int result=0;
02209 
02210         /* get the host name */
02211         if((temp_ptr=my_strtok(args,";"))==NULL)
02212                 return ERROR;
02213         host_name=(char *)strdup(temp_ptr);
02214 
02215         /* get the host check return code */
02216         if((temp_ptr=my_strtok(NULL,";"))==NULL){
02217                 my_free(host_name);
02218                 return ERROR;
02219                 }
02220         return_code=atoi(temp_ptr);
02221 
02222         /* get the plugin output (may be empty) */
02223         if((temp_ptr=my_strtok(NULL,"\n"))==NULL)
02224                 output=(char *)strdup("");
02225         else
02226                 output=(char *)strdup(temp_ptr);
02227 
02228         /* submit the check result */
02229         result=process_passive_host_check(check_time,host_name,return_code,output);
02230 
02231         /* free memory */
02232         my_free(host_name);
02233         my_free(output);
02234 
02235         return result;
02236         }
02237 
02238 
02239 /* process passive host check result */
02240 int process_passive_host_check(time_t check_time, char *host_name, int return_code, char *output){
02241         passive_check_result *new_pcr=NULL;
02242         host *temp_host=NULL;
02243         char *real_host_name=NULL;
02244         struct timeval tv;
02245         int result=OK;
02246 
02247         /* skip this host check result if we aren't accepting passive host checks */
02248         if(accept_passive_service_checks==FALSE)
02249                 return ERROR;
02250 
02251         /* make sure we have all required data */
02252         if(host_name==NULL || output==NULL)
02253                 return ERROR;
02254 
02255         /* make sure we have a reasonable return code */
02256         if(return_code<0 || return_code>2)
02257                 return ERROR;
02258 
02259         /* find the host by its name or address */
02260         if((temp_host=find_host(host_name))!=NULL)
02261                 real_host_name=host_name;
02262         else{
02263                 for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
02264                         if(!strcmp(host_name,temp_host->address)){
02265                                 real_host_name=temp_host->name;
02266                                 break;
02267                                 }
02268                         else if(!strcmp(host_name,temp_host->address6)){
02269                                 real_host_name=temp_host->name;
02270                                 break;
02271                                 }
02272                         }
02273                 }
02274 
02275         /* we couldn't find the host */
02276         if(temp_host==NULL){
02277                 logit(NSLOG_RUNTIME_WARNING,TRUE,"Warning:  Passive check result was received for host '%s', but the host could not be found!\n",host_name);
02278                 return ERROR;
02279                 }
02280 
02281         /* skip this is we aren't accepting passive checks for this host */
02282         if(temp_host->accept_passive_host_checks==FALSE)
02283                 return ERROR;
02284 
02285         /* allocate memory for the passive check result */
02286         new_pcr=(passive_check_result *)malloc(sizeof(passive_check_result));
02287         if(new_pcr==NULL)
02288                 return ERROR;
02289 
02290         /* initialize vars */
02291         new_pcr->object_check_type=HOST_CHECK;
02292         new_pcr->host_name=NULL;
02293         new_pcr->service_description=NULL;
02294         new_pcr->output=NULL;
02295         new_pcr->next=NULL;
02296 
02297         /* save string vars */
02298         if((new_pcr->host_name=(char *)strdup(real_host_name))==NULL)
02299                 result=ERROR;
02300         if((new_pcr->output=(char *)strdup(output))==NULL)
02301                 result=ERROR;
02302 
02303         /* handle errors */
02304         if(result==ERROR){
02305                 my_free(new_pcr->output);
02306                 my_free(new_pcr->service_description);
02307                 my_free(new_pcr->host_name);
02308                 my_free(new_pcr);
02309                 return ERROR;
02310                 }
02311 
02312         /* save the return code */
02313         new_pcr->return_code=return_code;
02314 
02315         /* make sure the return code is within bounds */
02316         if(new_pcr->return_code<0 || new_pcr->return_code>3)
02317                 new_pcr->return_code=STATE_UNKNOWN;
02318 
02319         new_pcr->check_time=check_time;
02320 
02321         /* calculate latency */
02322         gettimeofday(&tv,NULL);
02323         new_pcr->latency=(double)((double)(tv.tv_sec-check_time)+(double)(tv.tv_usec/1000.0)/1000.0);
02324         if(new_pcr->latency<0.0)
02325                 new_pcr->latency=0.0;
02326 
02327         /* add the passive check result to the end of the list in memory */
02328         if(passive_check_result_list==NULL)
02329                 passive_check_result_list=new_pcr;
02330         else
02331                 passive_check_result_list_tail->next=new_pcr;
02332         passive_check_result_list_tail=new_pcr;
02333 
02334         return OK;
02335         }
02336 
02337 
02338 
02339 /* acknowledges a host or service problem */
02340 int cmd_acknowledge_problem(int cmd,char *args){
02341         service *temp_service=NULL;
02342         host *temp_host=NULL;
02343         char *host_name=NULL;
02344         char *svc_description=NULL;
02345         char *ack_author=NULL;
02346         char *ack_data=NULL;
02347         char *temp_ptr=NULL;
02348         int type=ACKNOWLEDGEMENT_NORMAL;
02349         int notify=TRUE;
02350         int persistent=TRUE;
02351 
02352         /* get the host name */
02353         if((host_name=my_strtok(args,";"))==NULL)
02354                 return ERROR;
02355 
02356         /* verify that the host is valid */
02357         if((temp_host=find_host(host_name))==NULL)
02358                 return ERROR;
02359 
02360         /* this is a service acknowledgement */
02361         if(cmd==CMD_ACKNOWLEDGE_SVC_PROBLEM){
02362 
02363                 /* get the service name */
02364                 if((svc_description=my_strtok(NULL,";"))==NULL)
02365                         return ERROR;
02366 
02367                 /* verify that the service is valid */
02368                 if((temp_service=find_service(temp_host->name,svc_description))==NULL)
02369                         return ERROR;
02370                 }
02371 
02372         /* get the type */
02373         if((temp_ptr=my_strtok(NULL,";"))==NULL)
02374                 return ERROR;
02375         type=atoi(temp_ptr);
02376 
02377         /* get the notification option */
02378         if((temp_ptr=my_strtok(NULL,";"))==NULL)
02379                 return ERROR;
02380         notify=(atoi(temp_ptr)>0)?TRUE:FALSE;
02381 
02382         /* get the persistent option */
02383         if((temp_ptr=my_strtok(NULL,";"))==NULL)
02384                 return ERROR;
02385         persistent=(atoi(temp_ptr)>0)?TRUE:FALSE;
02386 
02387         /* get the acknowledgement author */
02388         if((temp_ptr=my_strtok(NULL,";"))==NULL)
02389                 return ERROR;
02390         ack_author=(char *)strdup(temp_ptr);
02391         
02392         /* get the acknowledgement data */
02393         if((temp_ptr=my_strtok(NULL,"\n"))==NULL){
02394                 my_free(ack_author);
02395                 return ERROR;
02396                 }
02397         ack_data=(char *)strdup(temp_ptr);
02398         
02399         /* acknowledge the host problem */
02400         if(cmd==CMD_ACKNOWLEDGE_HOST_PROBLEM)
02401                 acknowledge_host_problem(temp_host,ack_author,ack_data,type,notify,persistent);
02402 
02403         /* acknowledge the service problem */
02404         else
02405                 acknowledge_service_problem(temp_service,ack_author,ack_data,type,notify,persistent);
02406 
02407         /* free memory */
02408         my_free(ack_author);
02409         my_free(ack_data);
02410 
02411         return OK;
02412         }
02413 
02414 
02415 
02416 /* removes a host or service acknowledgement */
02417 int cmd_remove_acknowledgement(int cmd,char *args){
02418         service *temp_service=NULL;
02419         host *temp_host=NULL;
02420         char *host_name=NULL;
02421         char *svc_description=NULL;
02422 
02423         /* get the host name */
02424         if((host_name=my_strtok(args,";"))==NULL)
02425                 return ERROR;
02426 
02427         /* verify that the host is valid */
02428         if((temp_host=find_host(host_name))==NULL)
02429                 return ERROR;
02430 
02431         /* we are removing a service acknowledgement */
02432         if(cmd==CMD_REMOVE_SVC_ACKNOWLEDGEMENT){
02433 
02434                 /* get the service name */
02435                 if((svc_description=my_strtok(NULL,";"))==NULL)
02436                         return ERROR;
02437 
02438                 /* verify that the service is valid */
02439                 if((temp_service=find_service(temp_host->name,svc_description))==NULL)
02440                         return ERROR;
02441                 }
02442 
02443         /* acknowledge the host problem */
02444         if(cmd==CMD_REMOVE_HOST_ACKNOWLEDGEMENT)
02445                 remove_host_acknowledgement(temp_host);
02446 
02447         /* acknowledge the service problem */
02448         else
02449                 remove_service_acknowledgement(temp_service);
02450 
02451         return OK;
02452         }
02453 
02454 
02455 
02456 /* schedules downtime for a specific host or service */
02457 int cmd_schedule_downtime(int cmd, time_t entry_time, char *args){
02458         servicesmember *temp_servicesmember=NULL;
02459         service *temp_service=NULL;
02460         host *temp_host=NULL;
02461         host *last_host=NULL;
02462         hostgroup *temp_hostgroup=NULL;
02463         hostsmember *temp_hgmember=NULL;
02464         servicegroup *temp_servicegroup=NULL;
02465         servicesmember *temp_sgmember=NULL;
02466         char *host_name=NULL;
02467         char *hostgroup_name=NULL;
02468         char *servicegroup_name=NULL;
02469         char *svc_description=NULL;
02470         char *temp_ptr=NULL;
02471         time_t start_time=0L;
02472         time_t end_time=0L;
02473         int fixed=0;
02474         unsigned long triggered_by=0L;
02475         unsigned long duration=0L;
02476         char *author=NULL;
02477         char *comment_data=NULL;
02478         unsigned long downtime_id=0L;
02479 
02480         if(cmd==CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME || cmd==CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME){
02481                 
02482                 /* get the hostgroup name */
02483                 if((hostgroup_name=my_strtok(args,";"))==NULL)
02484                         return ERROR;
02485 
02486                 /* verify that the hostgroup is valid */
02487                 if((temp_hostgroup=find_hostgroup(hostgroup_name))==NULL)
02488                         return ERROR;
02489                 }
02490 
02491         else if(cmd==CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME || cmd==CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME){
02492 
02493                 /* get the servicegroup name */
02494                 if((servicegroup_name=my_strtok(args,";"))==NULL)
02495                         return ERROR;
02496 
02497                 /* verify that the servicegroup is valid */
02498                 if((temp_servicegroup=find_servicegroup(servicegroup_name))==NULL)
02499                         return ERROR;
02500                 }
02501 
02502         else{
02503 
02504                 /* get the host name */
02505                 if((host_name=my_strtok(args,";"))==NULL)
02506                         return ERROR;
02507 
02508                 /* verify that the host is valid */
02509                 if((temp_host=find_host(host_name))==NULL)
02510                         return ERROR;
02511 
02512                 /* this is a service downtime */
02513                 if(cmd==CMD_SCHEDULE_SVC_DOWNTIME){
02514 
02515                         /* get the service name */
02516                         if((svc_description=my_strtok(NULL,";"))==NULL)
02517                                 return ERROR;
02518 
02519                         /* verify that the service is valid */
02520                         if((temp_service=find_service(temp_host->name,svc_description))==NULL)
02521                                 return ERROR;
02522                         }
02523                 }
02524 
02525         /* get the start time */
02526         if((temp_ptr=my_strtok(NULL,";"))==NULL)
02527                 return ERROR;
02528         start_time=(time_t)strtoul(temp_ptr,NULL,10);
02529 
02530         /* get the end time */
02531         if((temp_ptr=my_strtok(NULL,";"))==NULL)
02532                 return ERROR;
02533         end_time=(time_t)strtoul(temp_ptr,NULL,10);
02534 
02535         /* get the fixed flag */
02536         if((temp_ptr=my_strtok(NULL,";"))==NULL)
02537                 return ERROR;
02538         fixed=atoi(temp_ptr);
02539 
02540         /* get the trigger id */
02541         if((temp_ptr=my_strtok(NULL,";"))==NULL)
02542                 return ERROR;
02543         triggered_by=strtoul(temp_ptr,NULL,10);
02544 
02545         /* get the duration */
02546         if((temp_ptr=my_strtok(NULL,";"))==NULL)
02547                 return ERROR;
02548         duration=strtoul(temp_ptr,NULL,10);
02549 
02550         /* get the author */
02551         if((author=my_strtok(NULL,";"))==NULL)
02552                 return ERROR;
02553 
02554         /* get the comment */
02555         if((comment_data=my_strtok(NULL,";"))==NULL)
02556                 return ERROR;
02557 
02558         /* MF 26-01-2011: check if flexible downtime demanded
02559            and duration set to non-zero.
02560            according to the documentation, a flexible downtime is
02561            started between start and end time and will last for
02562            "duration" seconds. strtoul converts a NULL value to 0
02563            so if set to 0, bail out as a duration>0 is needed.     */
02564 
02565         if(fixed==0 && duration==0)
02566                 return ERROR;
02567 
02568         /* duration should be auto-calculated, not user-specified */
02569         if(fixed>0)
02570                 duration=(unsigned long)(end_time-start_time);
02571 
02572         /* schedule downtime */
02573         switch(cmd){
02574 
02575         case CMD_SCHEDULE_HOST_DOWNTIME:
02576                 schedule_downtime(HOST_DOWNTIME,host_name,NULL,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&downtime_id);
02577                 break;
02578 
02579         case CMD_SCHEDULE_SVC_DOWNTIME:
02580                 schedule_downtime(SERVICE_DOWNTIME,host_name,svc_description,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&downtime_id);
02581                 break;
02582 
02583         case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
02584                 for(temp_servicesmember=temp_host->services;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
02585                         if((temp_service=temp_servicesmember->service_ptr)==NULL)
02586                                 continue;
02587                         schedule_downtime(SERVICE_DOWNTIME,host_name,temp_service->description,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&downtime_id);
02588                         }
02589                 
02590                 /* schedule downtime for the host itsself too */
02591                 schedule_downtime(HOST_DOWNTIME,host_name,NULL,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&downtime_id);
02592 
02593                 break;
02594 
02595         case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
02596                 for(temp_hgmember=temp_hostgroup->members;temp_hgmember!=NULL;temp_hgmember=temp_hgmember->next)
02597                         schedule_downtime(HOST_DOWNTIME,temp_hgmember->host_name,NULL,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&downtime_id);
02598                 break;
02599 
02600         case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
02601                 for(temp_hgmember=temp_hostgroup->members;temp_hgmember!=NULL;temp_hgmember=temp_hgmember->next){
02602                         if((temp_host=temp_hgmember->host_ptr)==NULL)
02603                                 continue;
02604                         for(temp_servicesmember=temp_host->services;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
02605                                 if((temp_service=temp_servicesmember->service_ptr)==NULL)
02606                                         continue;
02607                                 schedule_downtime(SERVICE_DOWNTIME,temp_service->host_name,temp_service->description,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&downtime_id);
02608                                 }
02609                         }
02610                 break;
02611 
02612         case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
02613                 last_host=NULL;
02614                 for(temp_sgmember=temp_servicegroup->members;temp_sgmember!=NULL;temp_sgmember=temp_sgmember->next){
02615                         temp_host=find_host(temp_sgmember->host_name);
02616                         if(temp_host==NULL)
02617                                 continue;
02618                         if(last_host==temp_host)
02619                                 continue;
02620                         schedule_downtime(HOST_DOWNTIME,temp_sgmember->host_name,NULL,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&downtime_id);
02621                         last_host=temp_host;
02622                         }
02623                 break;
02624 
02625         case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
02626                 for(temp_sgmember=temp_servicegroup->members;temp_sgmember!=NULL;temp_sgmember=temp_sgmember->next)
02627                         schedule_downtime(SERVICE_DOWNTIME,temp_sgmember->host_name,temp_sgmember->service_description,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&downtime_id);
02628                 break;
02629 
02630         case CMD_SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME:
02631 
02632                 /* schedule downtime for "parent" host */
02633                 schedule_downtime(HOST_DOWNTIME,host_name,NULL,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&downtime_id);
02634 
02635                 /* schedule (non-triggered) downtime for all child hosts */
02636                 schedule_and_propagate_downtime(temp_host,entry_time,author,comment_data,start_time,end_time,fixed,0,duration);
02637                 break;
02638 
02639         case CMD_SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME:
02640 
02641                 /* schedule downtime for "parent" host */
02642                 schedule_downtime(HOST_DOWNTIME,host_name,NULL,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&downtime_id);
02643 
02644                 /* schedule triggered downtime for all child hosts */
02645                 schedule_and_propagate_downtime(temp_host,entry_time,author,comment_data,start_time,end_time,fixed,downtime_id,duration);
02646                 break;
02647 
02648         default:
02649                 break;
02650                 }
02651 
02652         return OK;
02653         }
02654 
02655 
02656 
02657 /* deletes scheduled host or service downtime */
02658 int cmd_delete_downtime(int cmd, char *args){
02659         unsigned long downtime_id=0L;
02660         char *temp_ptr=NULL;
02661 
02662         /* get the id of the downtime to delete */
02663         if((temp_ptr=my_strtok(args,"\n"))==NULL)
02664                 return ERROR;
02665         downtime_id=strtoul(temp_ptr,NULL,10);
02666 
02667         if(cmd==CMD_DEL_HOST_DOWNTIME)
02668                 unschedule_downtime(HOST_DOWNTIME,downtime_id);
02669         else
02670                 unschedule_downtime(SERVICE_DOWNTIME,downtime_id);
02671 
02672         return OK;
02673         }
02674 
02675 
02676 /* Opsview enhancements: some of these commands are now "distributable" as no downtime ids are used */
02677 /* Deletes scheduled host and service downtime based on hostname and optionally other filter arguments */
02678 int cmd_delete_downtime_by_host_name(int cmd, char *args){
02679         char *temp_ptr=NULL;
02680         char *end_ptr=NULL;
02681         char *hostname=NULL;
02682         char *service_description=NULL;
02683         char *downtime_comment=NULL;
02684         time_t downtime_start_time=0L;
02685         int deleted=0;
02686 
02687         /* get the host name of the downtime to delete */
02688         temp_ptr=my_strtok(args,";");
02689         if(temp_ptr==NULL)
02690                 return ERROR;
02691         hostname=temp_ptr;
02692 
02693         /* get the optional service name */
02694         temp_ptr=my_strtok(NULL,";");
02695         if(temp_ptr!=NULL) {
02696                 if(*temp_ptr!='\0')
02697                         service_description=temp_ptr;
02698 
02699                 /* get the optional start time */
02700                 temp_ptr=my_strtok(NULL,";");
02701                 if(temp_ptr!=NULL) {
02702                         downtime_start_time=strtoul(temp_ptr,&end_ptr,10);
02703 
02704                         /* get the optional comment */
02705                         temp_ptr=my_strtok(NULL,";");
02706                         if(temp_ptr!=NULL) {
02707                                 if(*temp_ptr!='\0')
02708                                         downtime_comment=temp_ptr;
02709 
02710                                 }
02711                         }
02712                 }
02713 
02714         deleted=delete_downtime_by_hostname_service_description_start_time_comment(hostname, service_description, downtime_start_time, downtime_comment);
02715 
02716         if (deleted==0)
02717                 return ERROR;
02718 
02719         return OK;
02720         }
02721 
02722 /* Opsview enhancement: Deletes scheduled host and service downtime based on hostgroup and optionally other filter arguments */
02723 int cmd_delete_downtime_by_hostgroup_name(int cmd, char *args){
02724         char *temp_ptr=NULL;
02725         char *end_ptr=NULL;
02726         host *temp_host=NULL;
02727         hostgroup *temp_hostgroup=NULL;
02728         hostsmember *temp_member=NULL;
02729         char *service_description=NULL;
02730         char *downtime_comment=NULL;
02731         char *host_name=NULL;
02732         time_t downtime_start_time=0L;
02733         int deleted=0;
02734 
02735         /* get the host group name of the downtime to delete */
02736         temp_ptr=my_strtok(args,";");
02737         if(temp_ptr==NULL)
02738                 return ERROR;
02739 
02740         temp_hostgroup=find_hostgroup(temp_ptr);
02741         if(temp_hostgroup==NULL)
02742                 return ERROR;
02743 
02744         /* get the optional host name */
02745         temp_ptr=my_strtok(NULL,";");
02746         if(temp_ptr!=NULL) {
02747                 if(*temp_ptr!='\0')
02748                         host_name=temp_ptr;
02749 
02750                         /* get the optional service name */
02751                         temp_ptr=my_strtok(NULL,";");
02752                         if(temp_ptr!=NULL) {
02753                                 if(*temp_ptr!='\0')
02754                                         service_description=temp_ptr;
02755 
02756                                 /* get the optional start time */
02757                                 temp_ptr=my_strtok(NULL,";");
02758                                 if(temp_ptr!=NULL) {
02759                                         downtime_start_time=strtoul(temp_ptr,&end_ptr,10);
02760 
02761                                         /* get the optional comment */
02762                                         temp_ptr=my_strtok(NULL,";");
02763                                         if(temp_ptr!=NULL) {
02764                                                 if(*temp_ptr!='\0')
02765                                                         downtime_comment=temp_ptr;
02766 
02767                                                 }
02768                                         }
02769                                 }
02770 
02771                         /* get the optional service name */
02772                         temp_ptr=my_strtok(NULL,";");
02773                         if(temp_ptr!=NULL) {
02774                                 if(*temp_ptr!='\0')
02775                                         service_description=temp_ptr;
02776 
02777                         /* get the optional start time */
02778                         temp_ptr=my_strtok(NULL,";");
02779                         if(temp_ptr!=NULL) {
02780                                 downtime_start_time=strtoul(temp_ptr,&end_ptr,10);
02781 
02782                                 /* get the optional comment */
02783                                 temp_ptr=my_strtok(NULL,";");
02784                                         if(temp_ptr!=NULL) {
02785                                                 if(*temp_ptr!='\0')
02786                                                         downtime_comment=temp_ptr;
02787                                                 }
02788                                 }
02789                         }
02790                 }
02791 
02792         for(temp_member=temp_hostgroup->members;temp_member!=NULL;temp_member=temp_member->next){
02793                 if((temp_host=(host *)temp_member->host_ptr)==NULL)
02794                         continue;
02795                 if(host_name!=NULL && strcmp(temp_host->name,host_name)!=0)
02796                         continue;
02797                 deleted=+delete_downtime_by_hostname_service_description_start_time_comment(temp_host->name, service_description, downtime_start_time, downtime_comment);
02798                 }
02799 
02800         if (deleted==0)
02801                 return ERROR;
02802 
02803         return OK;
02804         }
02805 
02806 /* Opsview enhancement: Delete downtimes based on start time and/or comment */
02807 int cmd_delete_downtime_by_start_time_comment(int cmd, char *args){
02808         time_t downtime_start_time=0L;
02809         char *downtime_comment=NULL;
02810         char *temp_ptr=NULL;
02811         char *end_ptr=NULL;
02812         int deleted=0;
02813 
02814         /* Get start time if set */
02815         temp_ptr=my_strtok(args,";");
02816         if(temp_ptr!=NULL){
02817                 /* This will be set to 0 if no start_time is entered or data is bad */
02818                 downtime_start_time=strtoul(temp_ptr,&end_ptr,10);
02819                 }
02820 
02821         /* Get comment - not sure if this should be also tokenised by ; */
02822         temp_ptr=my_strtok(NULL,"\n");
02823         if(temp_ptr!=NULL && *temp_ptr!='\0'){
02824                 downtime_comment=temp_ptr;
02825                 }
02826 
02827         /* No args should give an error */
02828         if(downtime_start_time==0 && downtime_comment==NULL)
02829                 return ERROR;
02830 
02831         deleted=delete_downtime_by_hostname_service_description_start_time_comment(NULL,NULL,downtime_start_time,downtime_comment);
02832 
02833         if (deleted==0)
02834                 return ERROR;
02835 
02836         return OK;
02837         }
02838 
02839         
02840 /* changes a host or service (integer) variable */
02841 int cmd_change_object_int_var(int cmd,char *args){
02842         service *temp_service=NULL;
02843         host *temp_host=NULL;
02844         contact *temp_contact=NULL;
02845         char *host_name=NULL;
02846         char *svc_description=NULL;
02847         char *contact_name=NULL;
02848         char *temp_ptr=NULL;
02849         int intval=0;
02850         double dval=0.0;
02851         double old_dval=0.0;
02852         time_t preferred_time=0L;
02853         time_t next_valid_time=0L;
02854         unsigned long attr=MODATTR_NONE;
02855         unsigned long hattr=MODATTR_NONE;
02856         unsigned long sattr=MODATTR_NONE;
02857 
02858         switch(cmd){
02859 
02860         case CMD_CHANGE_NORMAL_SVC_CHECK_INTERVAL:
02861         case CMD_CHANGE_RETRY_SVC_CHECK_INTERVAL:
02862         case CMD_CHANGE_MAX_SVC_CHECK_ATTEMPTS:
02863         case CMD_CHANGE_SVC_MODATTR:
02864                 
02865                 /* get the host name */
02866                 if((host_name=my_strtok(args,";"))==NULL)
02867                         return ERROR;
02868 
02869                 /* get the service name */
02870                 if((svc_description=my_strtok(NULL,";"))==NULL)
02871                         return ERROR;
02872 
02873                 /* verify that the service is valid */
02874                 if((temp_service=find_service(host_name,svc_description))==NULL)
02875                         return ERROR;
02876 
02877                 break;
02878 
02879         case CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL:
02880         case CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL:
02881         case CMD_CHANGE_MAX_HOST_CHECK_ATTEMPTS:
02882         case CMD_CHANGE_HOST_MODATTR:
02883 
02884                 /* get the host name */
02885                 if((host_name=my_strtok(args,";"))==NULL)
02886                         return ERROR;
02887 
02888                 /* verify that the host is valid */
02889                 if((temp_host=find_host(host_name))==NULL)
02890                         return ERROR;
02891                 break;
02892 
02893         case CMD_CHANGE_CONTACT_MODATTR:
02894         case CMD_CHANGE_CONTACT_MODHATTR:
02895         case CMD_CHANGE_CONTACT_MODSATTR:
02896 
02897                 /* get the contact name */
02898                 if((contact_name=my_strtok(args,";"))==NULL)
02899                         return ERROR;
02900 
02901                 /* verify that the contact is valid */
02902                 if((temp_contact=find_contact(contact_name))==NULL)
02903                         return ERROR;
02904                 break;
02905 
02906         default:
02907                 /* unknown command */
02908                 return ERROR;
02909                 break;
02910                 }
02911 
02912         /* get the value */
02913         if((temp_ptr=my_strtok(NULL,";"))==NULL)
02914                 return ERROR;
02915         intval=(int)strtol(temp_ptr,NULL,0);
02916         if(intval<0 || (intval==0 && errno==EINVAL))
02917                 return ERROR;
02918         dval=(int)strtod(temp_ptr,NULL);
02919 
02920         switch(cmd){
02921 
02922         case CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL:
02923 
02924                 /* save the old check interval */
02925                 old_dval=temp_host->check_interval;
02926 
02927                 /* modify the check interval */
02928                 temp_host->check_interval=dval;
02929                 attr=MODATTR_NORMAL_CHECK_INTERVAL;
02930 
02931                 /* schedule a host check if previous interval was 0 (checks were not regularly scheduled) */
02932                 if(old_dval==0 && temp_host->checks_enabled==TRUE){
02933 
02934                         /* set the host check flag */
02935                         temp_host->should_be_scheduled=TRUE;
02936 
02937                         /* schedule a check for right now (or as soon as possible) */
02938                         time(&preferred_time);
02939                         if(check_time_against_period(preferred_time,temp_host->check_period_ptr)==ERROR){
02940                                 get_next_valid_time(preferred_time,&next_valid_time,temp_host->check_period_ptr);
02941                                 temp_host->next_check=next_valid_time;
02942                                 }
02943                         else
02944                                 temp_host->next_check=preferred_time;
02945 
02946                         /* schedule a check if we should */
02947                         if(temp_host->should_be_scheduled==TRUE)
02948                                 schedule_host_check(temp_host,temp_host->next_check,CHECK_OPTION_NONE);
02949                         }
02950 
02951                 break;
02952 
02953         case CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL:
02954 
02955                 temp_host->retry_interval=dval;
02956                 attr=MODATTR_RETRY_CHECK_INTERVAL;
02957 
02958                 break;
02959 
02960         case CMD_CHANGE_MAX_HOST_CHECK_ATTEMPTS:
02961 
02962                 temp_host->max_attempts=intval;
02963                 attr=MODATTR_MAX_CHECK_ATTEMPTS;
02964 
02965                 /* adjust current attempt number if in a hard state */
02966                 if(temp_host->state_type==HARD_STATE && temp_host->current_state!=HOST_UP && temp_host->current_attempt>1)
02967                         temp_host->current_attempt=temp_host->max_attempts;
02968 
02969                 break;
02970 
02971         case CMD_CHANGE_NORMAL_SVC_CHECK_INTERVAL:
02972 
02973                 /* save the old check interval */
02974                 old_dval=temp_service->check_interval;
02975 
02976                 /* modify the check interval */
02977                 temp_service->check_interval=dval;
02978                 attr=MODATTR_NORMAL_CHECK_INTERVAL;
02979 
02980                 /* schedule a service check if previous interval was 0 (checks were not regularly scheduled) */
02981                 if(old_dval==0 && temp_service->checks_enabled==TRUE && temp_service->check_interval!=0){
02982 
02983                         /* set the service check flag */
02984                         temp_service->should_be_scheduled=TRUE;
02985 
02986                         /* schedule a check for right now (or as soon as possible) */
02987                         time(&preferred_time);
02988                         if(check_time_against_period(preferred_time,temp_service->check_period_ptr)==ERROR){
02989                                 get_next_valid_time(preferred_time,&next_valid_time,temp_service->check_period_ptr);
02990                                 temp_service->next_check=next_valid_time;
02991                                 }
02992                         else
02993                                 temp_service->next_check=preferred_time;
02994 
02995                         /* schedule a check if we should */
02996                         if(temp_service->should_be_scheduled==TRUE)
02997                                 schedule_service_check(temp_service,temp_service->next_check,CHECK_OPTION_NONE);
02998                         }
02999 
03000                 break;
03001 
03002         case CMD_CHANGE_RETRY_SVC_CHECK_INTERVAL:
03003 
03004                 temp_service->retry_interval=dval;
03005                 attr=MODATTR_RETRY_CHECK_INTERVAL;
03006 
03007                 break;
03008 
03009         case CMD_CHANGE_MAX_SVC_CHECK_ATTEMPTS:
03010 
03011                 temp_service->max_attempts=intval;
03012                 attr=MODATTR_MAX_CHECK_ATTEMPTS;
03013 
03014                 /* adjust current attempt number if in a hard state */
03015                 if(temp_service->state_type==HARD_STATE && temp_service->current_state!=STATE_OK && temp_service->current_attempt>1)
03016                         temp_service->current_attempt=temp_service->max_attempts;
03017 
03018                 break;
03019 
03020         case CMD_CHANGE_HOST_MODATTR:
03021         case CMD_CHANGE_SVC_MODATTR:
03022         case CMD_CHANGE_CONTACT_MODATTR:
03023 
03024                 attr=intval;
03025                 break;
03026 
03027         case CMD_CHANGE_CONTACT_MODHATTR:
03028 
03029                 hattr=intval;
03030                 break;
03031 
03032         case CMD_CHANGE_CONTACT_MODSATTR:
03033 
03034                 sattr=intval;
03035                 break;
03036                 
03037 
03038         default:
03039                 break;
03040                 }
03041 
03042 
03043         /* send data to event broker and update status file */
03044         switch(cmd){
03045 
03046         case CMD_CHANGE_RETRY_SVC_CHECK_INTERVAL:
03047         case CMD_CHANGE_NORMAL_SVC_CHECK_INTERVAL:
03048         case CMD_CHANGE_MAX_SVC_CHECK_ATTEMPTS:
03049         case CMD_CHANGE_SVC_MODATTR:
03050 
03051                 /* set the modified service attribute */
03052                 if(cmd==CMD_CHANGE_SVC_MODATTR)
03053                         temp_service->modified_attributes=attr;
03054                 else
03055                         temp_service->modified_attributes|=attr;
03056 
03057 #ifdef USE_EVENT_BROKER
03058                 /* send data to event broker */
03059                 broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,temp_service,cmd,attr,temp_service->modified_attributes,NULL);
03060 #endif
03061 
03062                 /* update the status log with the service info */
03063                 update_service_status(temp_service,FALSE);
03064 
03065                 break;
03066 
03067         case CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL:
03068         case CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL:
03069         case CMD_CHANGE_MAX_HOST_CHECK_ATTEMPTS:
03070         case CMD_CHANGE_HOST_MODATTR:
03071 
03072                 /* set the modified host attribute */
03073                 if(cmd==CMD_CHANGE_HOST_MODATTR)
03074                         temp_host->modified_attributes=attr;
03075                 else
03076                         temp_host->modified_attributes|=attr;
03077 
03078 #ifdef USE_EVENT_BROKER
03079                 /* send data to event broker */
03080                 broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,temp_host,cmd,attr,temp_host->modified_attributes,NULL);
03081 #endif
03082 
03083                 /* update the status log with the host info */
03084                 update_host_status(temp_host,FALSE);
03085                 break;
03086 
03087         case CMD_CHANGE_CONTACT_MODATTR:
03088         case CMD_CHANGE_CONTACT_MODHATTR:
03089         case CMD_CHANGE_CONTACT_MODSATTR:
03090 
03091                 /* set the modified attribute */
03092                 switch(cmd){
03093                 case CMD_CHANGE_CONTACT_MODATTR:
03094                         temp_contact->modified_attributes=attr;
03095                         break;
03096                 case CMD_CHANGE_CONTACT_MODHATTR:
03097                         temp_contact->modified_host_attributes=hattr;
03098                         break;
03099                 case CMD_CHANGE_CONTACT_MODSATTR:
03100                         temp_contact->modified_service_attributes=sattr;
03101                         break;
03102                 default:
03103                         break;
03104                         }
03105 
03106 #ifdef USE_EVENT_BROKER
03107                 /* send data to event broker */
03108                 broker_adaptive_contact_data(NEBTYPE_ADAPTIVECONTACT_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,temp_contact,cmd,attr,temp_contact->modified_attributes,hattr,temp_contact->modified_host_attributes,sattr,temp_contact->modified_service_attributes,NULL);
03109 #endif
03110 
03111                 /* update the status log with the contact info */
03112                 update_contact_status(temp_contact,FALSE);
03113                 break;
03114 
03115         default:
03116                 break;
03117                 }
03118 
03119         return OK;
03120         }
03121 
03122 
03123       
03124 /* changes a host or service (char) variable */
03125 int cmd_change_object_char_var(int cmd,char *args){
03126         service *temp_service=NULL;
03127         host *temp_host=NULL;
03128         contact *temp_contact=NULL;
03129         timeperiod *temp_timeperiod=NULL;
03130         command *temp_command=NULL;
03131         char *host_name=NULL;
03132         char *svc_description=NULL;
03133         char *contact_name=NULL;
03134         char *charval=NULL;
03135         char *temp_ptr=NULL;
03136         char *temp_ptr2=NULL;
03137         unsigned long attr=MODATTR_NONE;
03138         unsigned long hattr=MODATTR_NONE;
03139         unsigned long sattr=MODATTR_NONE;
03140 
03141         
03142         /* SECURITY PATCH - disable these for the time being */
03143         switch(cmd){
03144         case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
03145         case CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER:
03146         case CMD_CHANGE_HOST_EVENT_HANDLER:
03147         case CMD_CHANGE_SVC_EVENT_HANDLER:
03148         case CMD_CHANGE_HOST_CHECK_COMMAND:
03149         case CMD_CHANGE_SVC_CHECK_COMMAND:
03150                 return ERROR;
03151                 }
03152 
03153 
03154         /* get the command arguments */
03155         switch(cmd){
03156 
03157         case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
03158         case CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER:
03159 
03160                 if((charval=my_strtok(args,"\n"))==NULL)
03161                         return ERROR;
03162                 
03163                 break;
03164 
03165         case CMD_CHANGE_HOST_EVENT_HANDLER:
03166         case CMD_CHANGE_HOST_CHECK_COMMAND:
03167         case CMD_CHANGE_HOST_CHECK_TIMEPERIOD:
03168         case CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD:
03169 
03170                 /* get the host name */
03171                 if((host_name=my_strtok(args,";"))==NULL)
03172                         return ERROR;
03173 
03174                 /* verify that the host is valid */
03175                 if((temp_host=find_host(host_name))==NULL)
03176                         return ERROR;
03177 
03178                 if((charval=my_strtok(NULL,"\n"))==NULL)
03179                         return ERROR;
03180 
03181                 break;
03182 
03183         case CMD_CHANGE_SVC_EVENT_HANDLER:
03184         case CMD_CHANGE_SVC_CHECK_COMMAND:
03185         case CMD_CHANGE_SVC_CHECK_TIMEPERIOD:
03186         case CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD:
03187 
03188                 /* get the host name */
03189                 if((host_name=my_strtok(args,";"))==NULL)
03190                         return ERROR;
03191 
03192                 /* get the service name */
03193                 if((svc_description=my_strtok(NULL,";"))==NULL)
03194                         return ERROR;
03195 
03196                 /* verify that the service is valid */
03197                 if((temp_service=find_service(host_name,svc_description))==NULL)
03198                         return ERROR;
03199 
03200                 if((charval=my_strtok(NULL,"\n"))==NULL)
03201                         return ERROR;
03202 
03203                 break;
03204 
03205 
03206         case CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD:
03207         case CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD:
03208 
03209                 /* get the contact name */
03210                 if((contact_name=my_strtok(args,";"))==NULL)
03211                         return ERROR;
03212 
03213                 /* verify that the contact is valid */
03214                 if((temp_contact=find_contact(contact_name))==NULL)
03215                         return ERROR;
03216 
03217                 if((charval=my_strtok(NULL,"\n"))==NULL)
03218                         return ERROR;
03219 
03220                 break;
03221 
03222         default:
03223                 /* invalid command */
03224                 return ERROR;
03225                 break;
03226 
03227                 }
03228 
03229         if((temp_ptr=(char *)strdup(charval))==NULL)
03230                 return ERROR;
03231 
03232 
03233         /* do some validation */
03234         switch(cmd){
03235 
03236         case CMD_CHANGE_HOST_CHECK_TIMEPERIOD:
03237         case CMD_CHANGE_SVC_CHECK_TIMEPERIOD:
03238         case CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD:
03239         case CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD:
03240         case CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD:
03241         case CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD:
03242 
03243                 /* make sure the timeperiod is valid */
03244                 if((temp_timeperiod=find_timeperiod(temp_ptr))==NULL){
03245                         my_free(temp_ptr);
03246                         return ERROR;
03247                         }
03248 
03249                 break;
03250 
03251         case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
03252         case CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER:
03253         case CMD_CHANGE_HOST_EVENT_HANDLER:
03254         case CMD_CHANGE_SVC_EVENT_HANDLER:
03255         case CMD_CHANGE_HOST_CHECK_COMMAND:
03256         case CMD_CHANGE_SVC_CHECK_COMMAND:
03257 
03258                 /* make sure the command exists */
03259                 temp_ptr2=my_strtok(temp_ptr,"!");
03260                 if((temp_command=find_command(temp_ptr2))==NULL){
03261                         my_free(temp_ptr);
03262                         return ERROR;
03263                         }
03264 
03265                 my_free(temp_ptr);
03266                 if((temp_ptr=(char *)strdup(charval))==NULL)
03267                         return ERROR;
03268 
03269                 break;
03270 
03271         default:
03272                 break;
03273                 }
03274 
03275 
03276         /* update the variable */
03277         switch(cmd){
03278 
03279         case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
03280 
03281                 my_free(global_host_event_handler);
03282                 global_host_event_handler=temp_ptr;
03283                 global_host_event_handler_ptr=temp_command;
03284                 attr=MODATTR_EVENT_HANDLER_COMMAND;
03285                 break;
03286 
03287         case CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER:
03288 
03289                 my_free(global_service_event_handler);
03290                 global_service_event_handler=temp_ptr;
03291                 global_service_event_handler_ptr=temp_command;
03292                 attr=MODATTR_EVENT_HANDLER_COMMAND;
03293                 break;
03294 
03295         case CMD_CHANGE_HOST_EVENT_HANDLER:
03296 
03297                 my_free(temp_host->event_handler);
03298                 temp_host->event_handler=temp_ptr;
03299                 temp_host->event_handler_ptr=temp_command;
03300                 attr=MODATTR_EVENT_HANDLER_COMMAND;
03301                 break;
03302 
03303         case CMD_CHANGE_HOST_CHECK_COMMAND:
03304 
03305                 my_free(temp_host->host_check_command);
03306                 temp_host->host_check_command=temp_ptr;
03307                 temp_host->check_command_ptr=temp_command;
03308                 attr=MODATTR_CHECK_COMMAND;
03309                 break;
03310 
03311         case CMD_CHANGE_HOST_CHECK_TIMEPERIOD:
03312 
03313                 my_free(temp_host->check_period);
03314                 temp_host->check_period=temp_ptr;
03315                 temp_host->check_period_ptr=temp_timeperiod;
03316                 attr=MODATTR_CHECK_TIMEPERIOD;
03317                 break;
03318 
03319         case CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD:
03320 
03321                 my_free(temp_host->notification_period);
03322                 temp_host->notification_period=temp_ptr;
03323                 temp_host->notification_period_ptr=temp_timeperiod;
03324                 attr=MODATTR_NOTIFICATION_TIMEPERIOD;
03325                 break;
03326 
03327         case CMD_CHANGE_SVC_EVENT_HANDLER:
03328 
03329                 my_free(temp_service->event_handler);
03330                 temp_service->event_handler=temp_ptr;
03331                 temp_service->event_handler_ptr=temp_command;
03332                 attr=MODATTR_EVENT_HANDLER_COMMAND;
03333                 break;
03334 
03335         case CMD_CHANGE_SVC_CHECK_COMMAND:
03336 
03337                 my_free(temp_service->service_check_command);
03338                 temp_service->service_check_command=temp_ptr;
03339                 temp_service->check_command_ptr=temp_command;
03340                 attr=MODATTR_CHECK_COMMAND;
03341                 break;
03342 
03343         case CMD_CHANGE_SVC_CHECK_TIMEPERIOD:
03344 
03345                 my_free(temp_service->check_period);
03346                 temp_service->check_period=temp_ptr;
03347                 temp_service->check_period_ptr=temp_timeperiod;
03348                 attr=MODATTR_CHECK_TIMEPERIOD;
03349                 break;
03350 
03351         case CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD:
03352 
03353                 my_free(temp_service->notification_period);
03354                 temp_service->notification_period=temp_ptr;
03355                 temp_service->notification_period_ptr=temp_timeperiod;
03356                 attr=MODATTR_NOTIFICATION_TIMEPERIOD;
03357                 break;
03358 
03359         case CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD:
03360 
03361                 my_free(temp_contact->host_notification_period);
03362                 temp_contact->host_notification_period=temp_ptr;
03363                 temp_contact->host_notification_period_ptr=temp_timeperiod;
03364                 hattr=MODATTR_NOTIFICATION_TIMEPERIOD;
03365                 break;
03366 
03367         case CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD:
03368 
03369                 my_free(temp_contact->service_notification_period);
03370                 temp_contact->service_notification_period=temp_ptr;
03371                 temp_contact->service_notification_period_ptr=temp_timeperiod;
03372                 sattr=MODATTR_NOTIFICATION_TIMEPERIOD;
03373                 break;
03374 
03375         default:
03376                 break;
03377                 }
03378 
03379 
03380         /* send data to event broker and update status file */
03381         switch(cmd){
03382 
03383         case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
03384 
03385                 /* set the modified host attribute */
03386                 modified_host_process_attributes|=attr;
03387 
03388 #ifdef USE_EVENT_BROKER
03389                 /* send data to event broker */
03390                 broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,cmd,attr,modified_host_process_attributes,MODATTR_NONE,modified_service_process_attributes,NULL);
03391 #endif
03392 
03393                 /* update program status */
03394                 update_program_status(FALSE);
03395 
03396                 break;
03397 
03398         case CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER:
03399 
03400                 /* set the modified service attribute */
03401                 modified_service_process_attributes|=attr;
03402 
03403 #ifdef USE_EVENT_BROKER
03404                 /* send data to event broker */
03405                 broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,cmd,MODATTR_NONE,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
03406 #endif
03407 
03408                 /* update program status */
03409                 update_program_status(FALSE);
03410 
03411                 break;
03412 
03413         case CMD_CHANGE_SVC_EVENT_HANDLER:
03414         case CMD_CHANGE_SVC_CHECK_COMMAND:
03415         case CMD_CHANGE_SVC_CHECK_TIMEPERIOD:
03416         case CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD:
03417 
03418                 /* set the modified service attribute */
03419                 temp_service->modified_attributes|=attr;
03420 
03421 #ifdef USE_EVENT_BROKER
03422                 /* send data to event broker */
03423                 broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,temp_service,cmd,attr,temp_service->modified_attributes,NULL);
03424 #endif
03425 
03426                 /* update the status log with the service info */
03427                 update_service_status(temp_service,FALSE);
03428 
03429                 break;
03430 
03431         case CMD_CHANGE_HOST_EVENT_HANDLER:
03432         case CMD_CHANGE_HOST_CHECK_COMMAND:
03433         case CMD_CHANGE_HOST_CHECK_TIMEPERIOD:
03434         case CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD:
03435 
03436                 /* set the modified host attribute */
03437                 temp_host->modified_attributes|=attr;
03438 
03439 #ifdef USE_EVENT_BROKER
03440                 /* send data to event broker */
03441                 broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,temp_host,cmd,attr,temp_host->modified_attributes,NULL);
03442 #endif
03443 
03444                 /* update the status log with the host info */
03445                 update_host_status(temp_host,FALSE);
03446                 break;
03447 
03448         case CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD:
03449         case CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD:
03450 
03451                 /* set the modified attributes */
03452                 temp_contact->modified_host_attributes|=hattr;
03453                 temp_contact->modified_service_attributes|=sattr;
03454 
03455 #ifdef USE_EVENT_BROKER
03456                 /* send data to event broker */
03457                 broker_adaptive_contact_data(NEBTYPE_ADAPTIVECONTACT_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,temp_contact,cmd,attr,temp_contact->modified_attributes,hattr,temp_contact->modified_host_attributes,sattr,temp_contact->modified_service_attributes,NULL);
03458 #endif
03459 
03460                 /* update the status log with the contact info */
03461                 update_contact_status(temp_contact,FALSE);
03462                 break;
03463 
03464         default:
03465                 break;
03466                 }
03467 
03468         return OK;
03469         }
03470 
03471 
03472 
03473 /* changes a custom host or service variable */
03474 int cmd_change_object_custom_var(int cmd, char *args){
03475         host *temp_host=NULL;
03476         service *temp_service=NULL;
03477         contact *temp_contact=NULL;
03478         customvariablesmember *temp_customvariablesmember=NULL;
03479         char *temp_ptr=NULL;
03480         char *name1=NULL;
03481         char *name2=NULL;
03482         char *varname=NULL;
03483         char *varvalue=NULL;
03484         register int x=0;
03485 
03486         /* get the host or contact name */
03487         if((temp_ptr=my_strtok(args,";"))==NULL)
03488                 return ERROR;
03489         if((name1=(char *)strdup(temp_ptr))==NULL)
03490                 return ERROR;
03491 
03492         /* get the service description if necessary */
03493         if(cmd==CMD_CHANGE_CUSTOM_SVC_VAR){
03494                 if((temp_ptr=my_strtok(NULL,";"))==NULL){
03495                         my_free(name1);
03496                         return ERROR;
03497                         }
03498                 if((name2=(char *)strdup(temp_ptr))==NULL){
03499                         my_free(name1);
03500                         return ERROR;
03501                         }
03502                 }
03503 
03504         /* get the custom variable name */
03505         if((temp_ptr=my_strtok(NULL,";"))==NULL){
03506                 my_free(name1);
03507                 my_free(name2);
03508                 return ERROR;
03509                 }
03510         if((varname=(char *)strdup(temp_ptr))==NULL){
03511                 my_free(name1);
03512                 my_free(name2);
03513                 return ERROR;
03514                 }
03515 
03516         /* get the custom variable value */
03517         if((temp_ptr=my_strtok(NULL,";"))==NULL){
03518                 my_free(name1);
03519                 my_free(name2);
03520                 my_free(varname);
03521                 return ERROR;
03522                 }
03523         if((varvalue=(char *)strdup(temp_ptr))==NULL){
03524                 my_free(name1);
03525                 my_free(name2);
03526                 my_free(varname);
03527                 return ERROR;
03528                 }
03529 
03530         /* find the object */
03531         switch(cmd){
03532         case CMD_CHANGE_CUSTOM_HOST_VAR:
03533                 if((temp_host=find_host(name1))==NULL)
03534                         return ERROR;
03535                 temp_customvariablesmember=temp_host->custom_variables;
03536                 break;
03537         case CMD_CHANGE_CUSTOM_SVC_VAR:
03538                 if((temp_service=find_service(name1,name2))==NULL)
03539                         return ERROR;
03540                 temp_customvariablesmember=temp_service->custom_variables;
03541                 break;
03542         case CMD_CHANGE_CUSTOM_CONTACT_VAR:
03543                 if((temp_contact=find_contact(name1))==NULL)
03544                         return ERROR;
03545                 temp_customvariablesmember=temp_contact->custom_variables;
03546                 break;
03547         default:
03548                 break;
03549                 }
03550 
03551         /* capitalize the custom variable name */
03552         for(x=0;varname[x]!='\x0';x++)
03553                 varname[x]=toupper(varname[x]);
03554 
03555         /* find the proper variable */
03556         for(;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){
03557                 
03558                 /* we found the variable, so update the value */
03559                 if(!strcmp(varname,temp_customvariablesmember->variable_name)){
03560 
03561                         /* update the value */
03562                         if(temp_customvariablesmember->variable_value)
03563                                 my_free(temp_customvariablesmember->variable_value);
03564                         temp_customvariablesmember->variable_value=(char *)strdup(varvalue);
03565 
03566                         /* mark the variable value as having been changed */
03567                         temp_customvariablesmember->has_been_modified=TRUE;
03568 
03569                         break;
03570                         }
03571                 }
03572 
03573         /* free memory */
03574         my_free(name1);
03575         my_free(name2);
03576         my_free(varname);
03577         my_free(varvalue);
03578 
03579         /* set the modified attributes and update the status of the object */
03580         switch(cmd){
03581         case CMD_CHANGE_CUSTOM_HOST_VAR:
03582                 temp_host->modified_attributes|=MODATTR_CUSTOM_VARIABLE;
03583                 update_host_status(temp_host,FALSE);
03584                 break;
03585         case CMD_CHANGE_CUSTOM_SVC_VAR:
03586                 temp_service->modified_attributes|=MODATTR_CUSTOM_VARIABLE;
03587                 update_service_status(temp_service,FALSE);
03588                 break;
03589         case CMD_CHANGE_CUSTOM_CONTACT_VAR:
03590                 temp_contact->modified_attributes|=MODATTR_CUSTOM_VARIABLE;
03591                 update_contact_status(temp_contact,FALSE);
03592                 break;
03593         default:
03594                 break;
03595                 }
03596 
03597         return OK;
03598         }
03599         
03600 
03601 /* processes an external host command */
03602 int cmd_process_external_commands_from_file(int cmd, char *args){
03603         char *fname=NULL;
03604         char *temp_ptr=NULL;
03605         int delete_file=FALSE;
03606 
03607         /* get the file name */
03608         if((temp_ptr=my_strtok(args,";"))==NULL)
03609                 return ERROR;
03610         if((fname=(char *)strdup(temp_ptr))==NULL)
03611                 return ERROR;
03612 
03613         /* find the deletion option */
03614         if((temp_ptr=my_strtok(NULL,"\n"))==NULL){
03615                 my_free(fname);
03616                 return ERROR;
03617                 }
03618         if(atoi(temp_ptr)==0)
03619                 delete_file=FALSE;
03620         else
03621                 delete_file=TRUE;
03622 
03623         /* process the file */
03624         process_external_commands_from_file(fname,delete_file);
03625 
03626         /* free memory */
03627         my_free(fname);
03628 
03629         return OK;
03630         }
03631 
03632 
03633 /******************************************************************/
03634 /*************** INTERNAL COMMAND IMPLEMENTATIONS  ****************/
03635 /******************************************************************/
03636 
03637 /* temporarily disables a service check */
03638 void disable_service_checks(service *svc){
03639         unsigned long attr=MODATTR_ACTIVE_CHECKS_ENABLED;
03640 
03641         /* checks are already disabled */
03642         if(svc->checks_enabled==FALSE)
03643                 return;
03644 
03645         /* set the attribute modified flag */
03646         svc->modified_attributes|=attr;
03647 
03648         /* disable the service check... */
03649         svc->checks_enabled=FALSE;
03650         svc->should_be_scheduled=FALSE;
03651 
03652 #ifdef USE_EVENT_BROKER
03653         /* send data to event broker */
03654         broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
03655 #endif
03656 
03657         /* update the status log to reflect the new service state */
03658         update_service_status(svc,FALSE);
03659 
03660         return;
03661         }
03662 
03663 
03664 
03665 /* enables a service check */
03666 void enable_service_checks(service *svc){
03667         time_t preferred_time=0L;
03668         time_t next_valid_time=0L;
03669         unsigned long attr=MODATTR_ACTIVE_CHECKS_ENABLED;
03670 
03671         /* checks are already enabled */
03672         if(svc->checks_enabled==TRUE)
03673                 return;
03674 
03675         /* set the attribute modified flag */
03676         svc->modified_attributes|=attr;
03677 
03678         /* enable the service check... */
03679         svc->checks_enabled=TRUE;
03680         svc->should_be_scheduled=TRUE;
03681 
03682         /* services with no check intervals don't get checked */
03683         if(svc->check_interval==0)
03684                 svc->should_be_scheduled=FALSE;
03685 
03686         /* schedule a check for right now (or as soon as possible) */
03687         time(&preferred_time);
03688         if(check_time_against_period(preferred_time,svc->check_period_ptr)==ERROR){
03689                 get_next_valid_time(preferred_time,&next_valid_time,svc->check_period_ptr);
03690                 svc->next_check=next_valid_time;
03691                 }
03692         else
03693                 svc->next_check=preferred_time;
03694 
03695         /* schedule a check if we should */
03696         if(svc->should_be_scheduled==TRUE)
03697                 schedule_service_check(svc,svc->next_check,CHECK_OPTION_NONE);
03698 
03699 #ifdef USE_EVENT_BROKER
03700         /* send data to event broker */
03701         broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
03702 #endif
03703 
03704         /* update the status log to reflect the new service state */
03705         update_service_status(svc,FALSE);
03706 
03707         return;
03708         }
03709 
03710 
03711 
03712 /* enable notifications on a program-wide basis */
03713 void enable_all_notifications(void){
03714         unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
03715 
03716         /* bail out if we're already set... */
03717         if(enable_notifications==TRUE)
03718                 return;
03719 
03720         /* set the attribute modified flag */
03721         modified_host_process_attributes|=attr;
03722         modified_service_process_attributes|=attr;
03723 
03724         /* update notification status */
03725         enable_notifications=TRUE;
03726 
03727 #ifdef USE_EVENT_BROKER
03728         /* send data to event broker */
03729         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
03730 #endif
03731 
03732         /* update the status log */
03733         update_program_status(FALSE);
03734 
03735         return;
03736         }
03737 
03738 
03739 /* disable notifications on a program-wide basis */
03740 void disable_all_notifications(void){
03741         unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
03742 
03743         /* bail out if we're already set... */
03744         if(enable_notifications==FALSE)
03745                 return;
03746 
03747         /* set the attribute modified flag */
03748         modified_host_process_attributes|=attr;
03749         modified_service_process_attributes|=attr;
03750 
03751         /* update notification status */
03752         enable_notifications=FALSE;
03753 
03754 #ifdef USE_EVENT_BROKER
03755         /* send data to event broker */
03756         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
03757 #endif
03758 
03759         /* update the status log */
03760         update_program_status(FALSE);
03761 
03762         return;
03763         }
03764 
03765 
03766 /* enables notifications for a service */
03767 void enable_service_notifications(service *svc){
03768         unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
03769 
03770         /* no change */
03771         if(svc->notifications_enabled==TRUE)
03772                 return;
03773 
03774         /* set the attribute modified flag */
03775         svc->modified_attributes|=attr;
03776 
03777         /* enable the service notifications... */
03778         svc->notifications_enabled=TRUE;
03779 
03780 #ifdef USE_EVENT_BROKER
03781         /* send data to event broker */
03782         broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
03783 #endif
03784 
03785         /* update the status log to reflect the new service state */
03786         update_service_status(svc,FALSE);
03787 
03788         return;
03789         }
03790 
03791 
03792 /* disables notifications for a service */
03793 void disable_service_notifications(service *svc){
03794         unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
03795 
03796         /* no change */
03797         if(svc->notifications_enabled==FALSE)
03798                 return;
03799 
03800         /* set the attribute modified flag */
03801         svc->modified_attributes|=attr;
03802 
03803         /* disable the service notifications... */
03804         svc->notifications_enabled=FALSE;
03805 
03806 #ifdef USE_EVENT_BROKER
03807         /* send data to event broker */
03808         broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
03809 #endif
03810 
03811         /* update the status log to reflect the new service state */
03812         update_service_status(svc,FALSE);
03813 
03814         return;
03815         }
03816 
03817 
03818 /* enables notifications for a host */
03819 void enable_host_notifications(host *hst){
03820         unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
03821 
03822         /* no change */
03823         if(hst->notifications_enabled==TRUE)
03824                 return;
03825 
03826         /* set the attribute modified flag */
03827         hst->modified_attributes|=attr;
03828 
03829         /* enable the host notifications... */
03830         hst->notifications_enabled=TRUE;
03831 
03832 #ifdef USE_EVENT_BROKER
03833         /* send data to event broker */
03834         broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
03835 #endif
03836 
03837         /* update the status log to reflect the new host state */
03838         update_host_status(hst,FALSE);
03839 
03840         return;
03841         }
03842 
03843 
03844 /* disables notifications for a host */
03845 void disable_host_notifications(host *hst){
03846         unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
03847 
03848         /* no change */
03849         if(hst->notifications_enabled==FALSE)
03850                 return;
03851 
03852         /* set the attribute modified flag */
03853         hst->modified_attributes|=attr;
03854 
03855         /* disable the host notifications... */
03856         hst->notifications_enabled=FALSE;
03857 
03858 #ifdef USE_EVENT_BROKER
03859         /* send data to event broker */
03860         broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
03861 #endif
03862 
03863         /* update the status log to reflect the new host state */
03864         update_host_status(hst,FALSE);
03865 
03866         return;
03867         }
03868 
03869 
03870 /* enables notifications for all hosts and services "beyond" a given host */
03871 void enable_and_propagate_notifications(host *hst, int level, int affect_top_host, int affect_hosts, int affect_services){
03872         host *child_host=NULL;
03873         service *temp_service=NULL;
03874         servicesmember *temp_servicesmember=NULL;
03875         hostsmember *temp_hostsmember=NULL;
03876 
03877         /* enable notification for top level host */
03878         if(affect_top_host==TRUE && level==0)
03879                 enable_host_notifications(hst);
03880 
03881         /* check all child hosts... */
03882         for(temp_hostsmember=hst->child_hosts;temp_hostsmember!=NULL;temp_hostsmember=temp_hostsmember->next){
03883 
03884                 if((child_host=temp_hostsmember->host_ptr)==NULL)
03885                         continue;
03886 
03887                 /* recurse... */
03888                 enable_and_propagate_notifications(child_host,level+1,affect_top_host,affect_hosts,affect_services);
03889 
03890                 /* enable notifications for this host */
03891                 if(affect_hosts==TRUE)
03892                         enable_host_notifications(child_host);
03893 
03894                 /* enable notifications for all services on this host... */
03895                 if(affect_services==TRUE){
03896                         for(temp_servicesmember=child_host->services;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
03897                                 if((temp_service=temp_servicesmember->service_ptr)==NULL)
03898                                         continue;
03899                                 enable_service_notifications(temp_service);
03900                                 }
03901                         }
03902                 }
03903 
03904         return;
03905         }
03906 
03907 
03908 /* disables notifications for all hosts and services "beyond" a given host */
03909 void disable_and_propagate_notifications(host *hst, int level, int affect_top_host, int affect_hosts, int affect_services){
03910         host *child_host=NULL;
03911         service *temp_service=NULL;
03912         servicesmember *temp_servicesmember=NULL;
03913         hostsmember *temp_hostsmember=NULL;
03914 
03915         if(hst==NULL)
03916                 return;
03917 
03918         /* disable notifications for top host */
03919         if(affect_top_host==TRUE && level==0)
03920                 disable_host_notifications(hst);
03921 
03922         /* check all child hosts... */
03923         for(temp_hostsmember=hst->child_hosts;temp_hostsmember!=NULL;temp_hostsmember=temp_hostsmember->next){
03924 
03925                 if((child_host=temp_hostsmember->host_ptr)==NULL)
03926                         continue;
03927 
03928                 /* recurse... */
03929                 disable_and_propagate_notifications(child_host,level+1,affect_top_host,affect_hosts,affect_services);
03930 
03931                 /* disable notifications for this host */
03932                 if(affect_hosts==TRUE)
03933                         disable_host_notifications(child_host);
03934 
03935                 /* disable notifications for all services on this host... */
03936                 if(affect_services==TRUE){
03937                         for(temp_servicesmember=child_host->services;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
03938                                 if((temp_service=temp_servicesmember->service_ptr)==NULL)
03939                                         continue;
03940                                 disable_service_notifications(temp_service);
03941                                 }
03942                         }
03943                 }
03944 
03945         return;
03946         }
03947 
03948 
03949 
03950 /* enables host notifications for a contact */
03951 void enable_contact_host_notifications(contact *cntct){
03952         unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
03953 
03954         /* no change */
03955         if(cntct->host_notifications_enabled==TRUE)
03956                 return;
03957 
03958         /* set the attribute modified flag */
03959         cntct->modified_host_attributes|=attr;
03960 
03961         /* enable the host notifications... */
03962         cntct->host_notifications_enabled=TRUE;
03963 
03964 #ifdef USE_EVENT_BROKER
03965         /* send data to event broker */
03966         broker_adaptive_contact_data(NEBTYPE_ADAPTIVECONTACT_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,cntct,CMD_NONE,MODATTR_NONE,cntct->modified_attributes,attr,cntct->modified_host_attributes,MODATTR_NONE,cntct->modified_service_attributes,NULL);
03967 #endif
03968 
03969         /* update the status log to reflect the new contact state */
03970         update_contact_status(cntct,FALSE);
03971 
03972         return;
03973         }
03974 
03975 
03976 
03977 /* disables host notifications for a contact */
03978 void disable_contact_host_notifications(contact *cntct){
03979         unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
03980 
03981         /* no change */
03982         if(cntct->host_notifications_enabled==FALSE)
03983                 return;
03984 
03985         /* set the attribute modified flag */
03986         cntct->modified_host_attributes|=attr;
03987 
03988         /* enable the host notifications... */
03989         cntct->host_notifications_enabled=FALSE;
03990 
03991 #ifdef USE_EVENT_BROKER
03992         /* send data to event broker */
03993         broker_adaptive_contact_data(NEBTYPE_ADAPTIVECONTACT_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,cntct,CMD_NONE,MODATTR_NONE,cntct->modified_attributes,attr,cntct->modified_host_attributes,MODATTR_NONE,cntct->modified_service_attributes,NULL);
03994 #endif
03995 
03996         /* update the status log to reflect the new contact state */
03997         update_contact_status(cntct,FALSE);
03998 
03999         return;
04000         }
04001 
04002 
04003 
04004 /* enables service notifications for a contact */
04005 void enable_contact_service_notifications(contact *cntct){
04006         unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
04007 
04008         /* no change */
04009         if(cntct->service_notifications_enabled==TRUE)
04010                 return;
04011 
04012         /* set the attribute modified flag */
04013         cntct->modified_service_attributes|=attr;
04014 
04015         /* enable the host notifications... */
04016         cntct->service_notifications_enabled=TRUE;
04017 
04018 #ifdef USE_EVENT_BROKER
04019         /* send data to event broker */
04020         broker_adaptive_contact_data(NEBTYPE_ADAPTIVECONTACT_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,cntct,CMD_NONE,MODATTR_NONE,cntct->modified_attributes,MODATTR_NONE,cntct->modified_host_attributes,attr,cntct->modified_service_attributes,NULL);
04021 #endif
04022 
04023         /* update the status log to reflect the new contact state */
04024         update_contact_status(cntct,FALSE);
04025 
04026         return;
04027         }
04028 
04029 
04030 
04031 /* disables service notifications for a contact */
04032 void disable_contact_service_notifications(contact *cntct){
04033         unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
04034 
04035         /* no change */
04036         if(cntct->service_notifications_enabled==FALSE)
04037                 return;
04038 
04039         /* set the attribute modified flag */
04040         cntct->modified_service_attributes|=attr;
04041 
04042         /* enable the host notifications... */
04043         cntct->service_notifications_enabled=FALSE;
04044 
04045 #ifdef USE_EVENT_BROKER
04046         /* send data to event broker */
04047         broker_adaptive_contact_data(NEBTYPE_ADAPTIVECONTACT_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,cntct,CMD_NONE,MODATTR_NONE,cntct->modified_attributes,MODATTR_NONE,cntct->modified_host_attributes,attr,cntct->modified_service_attributes,NULL);
04048 #endif
04049 
04050         /* update the status log to reflect the new contact state */
04051         update_contact_status(cntct,FALSE);
04052 
04053         return;
04054         }
04055 
04056 
04057 
04058 /* schedules downtime for all hosts "beyond" a given host */
04059 void schedule_and_propagate_downtime(host *temp_host, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration){
04060         host *child_host=NULL;
04061         hostsmember *temp_hostsmember=NULL;
04062 
04063         /* check all child hosts... */
04064         for(temp_hostsmember=temp_host->child_hosts;temp_hostsmember!=NULL;temp_hostsmember=temp_hostsmember->next){
04065 
04066                 if((child_host=temp_hostsmember->host_ptr)==NULL)
04067                         continue;
04068 
04069                 /* recurse... */
04070                 schedule_and_propagate_downtime(child_host,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration);
04071 
04072                 /* schedule downtime for this host */
04073                 schedule_downtime(HOST_DOWNTIME,child_host->name,NULL,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,NULL);
04074                 }
04075 
04076         return;
04077         }
04078 
04079 
04080 /* acknowledges a host problem */
04081 void acknowledge_host_problem(host *hst, char *ack_author, char *ack_data, int type, int notify, int persistent){
04082         time_t current_time=0L;
04083 
04084         /* cannot acknowledge a non-existent problem */
04085         if(hst->current_state==HOST_UP)
04086                 return;
04087 
04088 #ifdef USE_EVENT_BROKER
04089         /* send data to event broker */
04090         broker_acknowledgement_data(NEBTYPE_ACKNOWLEDGEMENT_ADD,NEBFLAG_NONE,NEBATTR_NONE,HOST_ACKNOWLEDGEMENT,(void *)hst,ack_author,ack_data,type,notify,persistent,NULL);
04091 #endif
04092 
04093         /* send out an acknowledgement notification */
04094         if(notify==TRUE)
04095                 host_notification(hst,NOTIFICATION_ACKNOWLEDGEMENT,ack_author,ack_data,NOTIFICATION_OPTION_NONE);
04096 
04097         /* set the acknowledgement flag */
04098         hst->problem_has_been_acknowledged=TRUE;
04099 
04100         /* set the acknowledgement type */
04101         hst->acknowledgement_type=(type==ACKNOWLEDGEMENT_STICKY)?ACKNOWLEDGEMENT_STICKY:ACKNOWLEDGEMENT_NORMAL;
04102 
04103         /* update the status log with the host info */
04104         update_host_status(hst,FALSE);
04105 
04106         /* add a comment for the acknowledgement */
04107         time(&current_time);
04108         add_new_host_comment(ACKNOWLEDGEMENT_COMMENT,hst->name,current_time,ack_author,ack_data,persistent,COMMENTSOURCE_INTERNAL,FALSE,(time_t)0,NULL);
04109 
04110         return;
04111         }
04112 
04113 
04114 /* acknowledges a service problem */
04115 void acknowledge_service_problem(service *svc, char *ack_author, char *ack_data, int type, int notify, int persistent){
04116         time_t current_time=0L;
04117 
04118         /* cannot acknowledge a non-existent problem */
04119         if(svc->current_state==STATE_OK)
04120                 return;
04121 
04122 #ifdef USE_EVENT_BROKER
04123         /* send data to event broker */
04124         broker_acknowledgement_data(NEBTYPE_ACKNOWLEDGEMENT_ADD,NEBFLAG_NONE,NEBATTR_NONE,SERVICE_ACKNOWLEDGEMENT,(void *)svc,ack_author,ack_data,type,notify,persistent,NULL);
04125 #endif
04126 
04127         /* send out an acknowledgement notification */
04128         if(notify==TRUE)
04129                 service_notification(svc,NOTIFICATION_ACKNOWLEDGEMENT,ack_author,ack_data,NOTIFICATION_OPTION_NONE);
04130 
04131         /* set the acknowledgement flag */
04132         svc->problem_has_been_acknowledged=TRUE;
04133 
04134         /* set the acknowledgement type */
04135         svc->acknowledgement_type=(type==ACKNOWLEDGEMENT_STICKY)?ACKNOWLEDGEMENT_STICKY:ACKNOWLEDGEMENT_NORMAL;
04136 
04137         /* update the status log with the service info */
04138         update_service_status(svc,FALSE);
04139 
04140         /* add a comment for the acknowledgement */
04141         time(&current_time);
04142         add_new_service_comment(ACKNOWLEDGEMENT_COMMENT,svc->host_name,svc->description,current_time,ack_author,ack_data,persistent,COMMENTSOURCE_INTERNAL,FALSE,(time_t)0,NULL);
04143 
04144         return;
04145         }
04146 
04147 
04148 /* removes a host acknowledgement */
04149 void remove_host_acknowledgement(host *hst){
04150 
04151         /* set the acknowledgement flag */
04152         hst->problem_has_been_acknowledged=FALSE;
04153 
04154         /* update the status log with the host info */
04155         update_host_status(hst,FALSE);
04156 
04157         /* remove any non-persistant comments associated with the ack */
04158         delete_host_acknowledgement_comments(hst);
04159 
04160         return;
04161         }
04162 
04163 
04164 /* removes a service acknowledgement */
04165 void remove_service_acknowledgement(service *svc){
04166 
04167         /* set the acknowledgement flag */
04168         svc->problem_has_been_acknowledged=FALSE;
04169 
04170         /* update the status log with the service info */
04171         update_service_status(svc,FALSE);
04172 
04173         /* remove any non-persistant comments associated with the ack */
04174         delete_service_acknowledgement_comments(svc);
04175 
04176         return;
04177         }
04178 
04179 
04180 /* starts executing service checks */
04181 void start_executing_service_checks(void){
04182         unsigned long attr=MODATTR_ACTIVE_CHECKS_ENABLED;
04183 
04184         /* bail out if we're already executing services */
04185         if(execute_service_checks==TRUE)
04186                 return;
04187 
04188         /* set the attribute modified flag */
04189         modified_service_process_attributes|=attr;
04190 
04191         /* set the service check execution flag */
04192         execute_service_checks=TRUE;
04193 
04194 #ifdef USE_EVENT_BROKER
04195         /* send data to event broker */
04196         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,MODATTR_NONE,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
04197 #endif
04198 
04199         /* update the status log with the program info */
04200         update_program_status(FALSE);
04201 
04202         return;
04203         }
04204 
04205 
04206 
04207 
04208 /* stops executing service checks */
04209 void stop_executing_service_checks(void){
04210         unsigned long attr=MODATTR_ACTIVE_CHECKS_ENABLED;
04211 
04212         /* bail out if we're already not executing services */
04213         if(execute_service_checks==FALSE)
04214                 return;
04215 
04216         /* set the attribute modified flag */
04217         modified_service_process_attributes|=attr;
04218 
04219         /* set the service check execution flag */
04220         execute_service_checks=FALSE;
04221 
04222 #ifdef USE_EVENT_BROKER
04223         /* send data to event broker */
04224         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,MODATTR_NONE,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
04225 #endif
04226 
04227         /* update the status log with the program info */
04228         update_program_status(FALSE);
04229 
04230         return;
04231         }
04232 
04233 
04234 
04235 /* starts accepting passive service checks */
04236 void start_accepting_passive_service_checks(void){
04237         unsigned long attr=MODATTR_PASSIVE_CHECKS_ENABLED;
04238 
04239         /* bail out if we're already accepting passive services */
04240         if(accept_passive_service_checks==TRUE)
04241                 return;
04242 
04243         /* set the attribute modified flag */
04244         modified_service_process_attributes|=attr;
04245 
04246         /* set the service check flag */
04247         accept_passive_service_checks=TRUE;
04248 
04249 #ifdef USE_EVENT_BROKER
04250         /* send data to event broker */
04251         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,MODATTR_NONE,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
04252 #endif
04253 
04254         /* update the status log with the program info */
04255         update_program_status(FALSE);
04256 
04257         return;
04258         }
04259 
04260 
04261 
04262 /* stops accepting passive service checks */
04263 void stop_accepting_passive_service_checks(void){
04264         unsigned long attr=MODATTR_PASSIVE_CHECKS_ENABLED;
04265 
04266         /* bail out if we're already not accepting passive services */
04267         if(accept_passive_service_checks==FALSE)
04268                 return;
04269 
04270         /* set the attribute modified flag */
04271         modified_service_process_attributes|=attr;
04272 
04273         /* set the service check flag */
04274         accept_passive_service_checks=FALSE;
04275 
04276 #ifdef USE_EVENT_BROKER
04277         /* send data to event broker */
04278         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,MODATTR_NONE,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
04279 #endif
04280 
04281         /* update the status log with the program info */
04282         update_program_status(FALSE);
04283 
04284         return;
04285         }
04286 
04287 
04288 
04289 /* enables passive service checks for a particular service */
04290 void enable_passive_service_checks(service *svc){
04291         unsigned long attr=MODATTR_PASSIVE_CHECKS_ENABLED;
04292 
04293         /* no change */
04294         if(svc->accept_passive_service_checks==TRUE)
04295                 return;
04296 
04297         /* set the attribute modified flag */
04298         svc->modified_attributes|=attr;
04299 
04300         /* set the passive check flag */
04301         svc->accept_passive_service_checks=TRUE;
04302 
04303 #ifdef USE_EVENT_BROKER
04304         /* send data to event broker */
04305         broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
04306 #endif
04307 
04308         /* update the status log with the service info */
04309         update_service_status(svc,FALSE);
04310 
04311         return;
04312         }
04313 
04314 
04315 
04316 /* disables passive service checks for a particular service */
04317 void disable_passive_service_checks(service *svc){
04318         unsigned long attr=MODATTR_PASSIVE_CHECKS_ENABLED;
04319 
04320         /* no change */
04321         if(svc->accept_passive_service_checks==FALSE)
04322                 return;
04323 
04324         /* set the attribute modified flag */
04325         svc->modified_attributes|=attr;
04326 
04327         /* set the passive check flag */
04328         svc->accept_passive_service_checks=FALSE;
04329 
04330 #ifdef USE_EVENT_BROKER
04331         /* send data to event broker */
04332         broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
04333 #endif
04334 
04335         /* update the status log with the service info */
04336         update_service_status(svc,FALSE);
04337 
04338         return;
04339         }
04340 
04341 
04342 
04343 /* starts executing host checks */
04344 void start_executing_host_checks(void){
04345         unsigned long attr=MODATTR_ACTIVE_CHECKS_ENABLED;
04346 
04347         /* bail out if we're already executing hosts */
04348         if(execute_host_checks==TRUE)
04349                 return;
04350 
04351         /* set the attribute modified flag */
04352         modified_host_process_attributes|=attr;
04353 
04354         /* set the host check execution flag */
04355         execute_host_checks=TRUE;
04356 
04357 #ifdef USE_EVENT_BROKER
04358         /* send data to event broker */
04359         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,MODATTR_NONE,modified_service_process_attributes,NULL);
04360 #endif
04361 
04362         /* update the status log with the program info */
04363         update_program_status(FALSE);
04364 
04365         return;
04366         }
04367 
04368 
04369 
04370 
04371 /* stops executing host checks */
04372 void stop_executing_host_checks(void){
04373         unsigned long attr=MODATTR_ACTIVE_CHECKS_ENABLED;
04374 
04375         /* bail out if we're already not executing hosts */
04376         if(execute_host_checks==FALSE)
04377                 return;
04378 
04379         /* set the attribute modified flag */
04380         modified_host_process_attributes|=attr;
04381 
04382         /* set the host check execution flag */
04383         execute_host_checks=FALSE;
04384 
04385 #ifdef USE_EVENT_BROKER
04386         /* send data to event broker */
04387         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,MODATTR_NONE,modified_service_process_attributes,NULL);
04388 #endif
04389 
04390         /* update the status log with the program info */
04391         update_program_status(FALSE);
04392 
04393         return;
04394         }
04395 
04396 
04397 
04398 /* starts accepting passive host checks */
04399 void start_accepting_passive_host_checks(void){
04400         unsigned long attr=MODATTR_PASSIVE_CHECKS_ENABLED;
04401 
04402         /* bail out if we're already accepting passive hosts */
04403         if(accept_passive_host_checks==TRUE)
04404                 return;
04405 
04406         /* set the attribute modified flag */
04407         modified_host_process_attributes|=attr;
04408 
04409         /* set the host check flag */
04410         accept_passive_host_checks=TRUE;
04411 
04412 #ifdef USE_EVENT_BROKER
04413         /* send data to event broker */
04414         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,MODATTR_NONE,modified_service_process_attributes,NULL);
04415 #endif
04416 
04417         /* update the status log with the program info */
04418         update_program_status(FALSE);
04419 
04420         return;
04421         }
04422 
04423 
04424 
04425 /* stops accepting passive host checks */
04426 void stop_accepting_passive_host_checks(void){
04427         unsigned long attr=MODATTR_PASSIVE_CHECKS_ENABLED;
04428 
04429         /* bail out if we're already not accepting passive hosts */
04430         if(accept_passive_host_checks==FALSE)
04431                 return;
04432 
04433         /* set the attribute modified flag */
04434         modified_host_process_attributes|=attr;
04435 
04436         /* set the host check flag */
04437         accept_passive_host_checks=FALSE;
04438 
04439 #ifdef USE_EVENT_BROKER
04440         /* send data to event broker */
04441         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,MODATTR_NONE,modified_service_process_attributes,NULL);
04442 #endif
04443 
04444         /* update the status log with the program info */
04445         update_program_status(FALSE);
04446 
04447         return;
04448         }
04449 
04450 
04451 
04452 /* enables passive host checks for a particular host */
04453 void enable_passive_host_checks(host *hst){
04454         unsigned long attr=MODATTR_PASSIVE_CHECKS_ENABLED;
04455 
04456         /* no change */
04457         if(hst->accept_passive_host_checks==TRUE)
04458                 return;
04459 
04460         /* set the attribute modified flag */
04461         hst->modified_attributes|=attr;
04462 
04463         /* set the passive check flag */
04464         hst->accept_passive_host_checks=TRUE;
04465 
04466 #ifdef USE_EVENT_BROKER
04467         /* send data to event broker */
04468         broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
04469 #endif
04470 
04471         /* update the status log with the host info */
04472         update_host_status(hst,FALSE);
04473 
04474         return;
04475         }
04476 
04477 
04478 
04479 /* disables passive host checks for a particular host */
04480 void disable_passive_host_checks(host *hst){
04481         unsigned long attr=MODATTR_PASSIVE_CHECKS_ENABLED;
04482 
04483         /* no change */
04484         if(hst->accept_passive_host_checks==FALSE)
04485                 return;
04486 
04487         /* set the attribute modified flag */
04488         hst->modified_attributes|=attr;
04489 
04490         /* set the passive check flag */
04491         hst->accept_passive_host_checks=FALSE;
04492 
04493 #ifdef USE_EVENT_BROKER
04494         /* send data to event broker */
04495         broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
04496 #endif
04497 
04498         /* update the status log with the host info */
04499         update_host_status(hst,FALSE);
04500 
04501         return;
04502         }
04503 
04504 
04505 /* enables event handlers on a program-wide basis */
04506 void start_using_event_handlers(void){
04507         unsigned long attr=MODATTR_EVENT_HANDLER_ENABLED;
04508 
04509         /* no change */
04510         if(enable_event_handlers==TRUE)
04511                 return;
04512 
04513         /* set the attribute modified flag */
04514         modified_host_process_attributes|=attr;
04515         modified_service_process_attributes|=attr;
04516 
04517         /* set the event handler flag */
04518         enable_event_handlers=TRUE;
04519 
04520 #ifdef USE_EVENT_BROKER
04521         /* send data to event broker */
04522         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
04523 #endif
04524 
04525         /* update the status log with the program info */
04526         update_program_status(FALSE);
04527 
04528         return;
04529         }
04530 
04531 
04532 /* disables event handlers on a program-wide basis */
04533 void stop_using_event_handlers(void){
04534         unsigned long attr=MODATTR_EVENT_HANDLER_ENABLED;
04535 
04536         /* no change */
04537         if(enable_event_handlers==FALSE)
04538                 return;
04539 
04540         /* set the attribute modified flag */
04541         modified_host_process_attributes|=attr;
04542         modified_service_process_attributes|=attr;
04543 
04544         /* set the event handler flag */
04545         enable_event_handlers=FALSE;
04546 
04547 #ifdef USE_EVENT_BROKER
04548         /* send data to event broker */
04549         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
04550 #endif
04551 
04552         /* update the status log with the program info */
04553         update_program_status(FALSE);
04554 
04555         return;
04556         }
04557 
04558 
04559 /* enables the event handler for a particular service */
04560 void enable_service_event_handler(service *svc){
04561         unsigned long attr=MODATTR_EVENT_HANDLER_ENABLED;
04562 
04563         /* no change */
04564         if(svc->event_handler_enabled==TRUE)
04565                 return;
04566 
04567         /* set the attribute modified flag */
04568         svc->modified_attributes|=attr;
04569 
04570         /* set the event handler flag */
04571         svc->event_handler_enabled=TRUE;
04572 
04573 #ifdef USE_EVENT_BROKER
04574         /* send data to event broker */
04575         broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
04576 #endif
04577 
04578         /* update the status log with the service info */
04579         update_service_status(svc,FALSE);
04580 
04581         return;
04582         }
04583 
04584 
04585 
04586 /* disables the event handler for a particular service */
04587 void disable_service_event_handler(service *svc){
04588         unsigned long attr=MODATTR_EVENT_HANDLER_ENABLED;
04589 
04590         /* no change */
04591         if(svc->event_handler_enabled==FALSE)
04592                 return;
04593 
04594         /* set the attribute modified flag */
04595         svc->modified_attributes|=attr;
04596 
04597         /* set the event handler flag */
04598         svc->event_handler_enabled=FALSE;
04599 
04600 #ifdef USE_EVENT_BROKER
04601         /* send data to event broker */
04602         broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
04603 #endif
04604 
04605         /* update the status log with the service info */
04606         update_service_status(svc,FALSE);
04607 
04608         return;
04609         }
04610 
04611 
04612 /* enables the event handler for a particular host */
04613 void enable_host_event_handler(host *hst){
04614         unsigned long attr=MODATTR_EVENT_HANDLER_ENABLED;
04615 
04616         /* no change */
04617         if(hst->event_handler_enabled==TRUE)
04618                 return;
04619 
04620         /* set the attribute modified flag */
04621         hst->modified_attributes|=attr;
04622 
04623         /* set the event handler flag */
04624         hst->event_handler_enabled=TRUE;
04625 
04626 #ifdef USE_EVENT_BROKER
04627         /* send data to event broker */
04628         broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
04629 #endif
04630 
04631         /* update the status log with the host info */
04632         update_host_status(hst,FALSE);
04633 
04634         return;
04635         }
04636 
04637 
04638 /* disables the event handler for a particular host */
04639 void disable_host_event_handler(host *hst){
04640         unsigned long attr=MODATTR_EVENT_HANDLER_ENABLED;
04641 
04642         /* no change */
04643         if(hst->event_handler_enabled==FALSE)
04644                 return;
04645 
04646         /* set the attribute modified flag */
04647         hst->modified_attributes|=attr;
04648 
04649         /* set the event handler flag */
04650         hst->event_handler_enabled=FALSE;
04651 
04652 #ifdef USE_EVENT_BROKER
04653         /* send data to event broker */
04654         broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
04655 #endif
04656 
04657         /* update the status log with the host info */
04658         update_host_status(hst,FALSE);
04659 
04660         return;
04661         }
04662 
04663 
04664 /* disables checks of a particular host */
04665 void disable_host_checks(host *hst){
04666         unsigned long attr=MODATTR_ACTIVE_CHECKS_ENABLED;
04667 
04668         /* checks are already disabled */
04669         if(hst->checks_enabled==FALSE)
04670                 return;
04671 
04672         /* set the attribute modified flag */
04673         hst->modified_attributes|=attr;
04674 
04675         /* set the host check flag */
04676         hst->checks_enabled=FALSE;
04677         hst->should_be_scheduled=FALSE;
04678 
04679 #ifdef USE_EVENT_BROKER
04680         /* send data to event broker */
04681         broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
04682 #endif
04683 
04684         /* update the status log with the host info */
04685         update_host_status(hst,FALSE);
04686 
04687         return;
04688         }
04689 
04690 
04691 /* enables checks of a particular host */
04692 void enable_host_checks(host *hst){
04693         time_t preferred_time=0L;
04694         time_t next_valid_time=0L;
04695         unsigned long attr=MODATTR_ACTIVE_CHECKS_ENABLED;
04696 
04697         /* checks are already enabled */
04698         if(hst->checks_enabled==TRUE)
04699                 return;
04700 
04701         /* set the attribute modified flag */
04702         hst->modified_attributes|=attr;
04703 
04704         /* set the host check flag */
04705         hst->checks_enabled=TRUE;
04706         hst->should_be_scheduled=TRUE;
04707 
04708         /* hosts with no check intervals don't get checked */
04709         if(hst->check_interval==0)
04710                 hst->should_be_scheduled=FALSE;
04711 
04712         /* schedule a check for right now (or as soon as possible) */
04713         time(&preferred_time);
04714         if(check_time_against_period(preferred_time,hst->check_period_ptr)==ERROR){
04715                 get_next_valid_time(preferred_time,&next_valid_time,hst->check_period_ptr);
04716                 hst->next_check=next_valid_time;
04717                 }
04718         else
04719                 hst->next_check=preferred_time;
04720 
04721         /* schedule a check if we should */
04722         if(hst->should_be_scheduled==TRUE)
04723                 schedule_host_check(hst,hst->next_check,CHECK_OPTION_NONE);
04724 
04725 #ifdef USE_EVENT_BROKER
04726         /* send data to event broker */
04727         broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
04728 #endif
04729 
04730         /* update the status log with the host info */
04731         update_host_status(hst,FALSE);
04732 
04733         return;
04734         }
04735 
04736 
04737 
04738 /* start obsessing over service check results */
04739 void start_obsessing_over_service_checks(void){
04740         unsigned long attr=MODATTR_OBSESSIVE_HANDLER_ENABLED;
04741 
04742         /* no change */
04743         if(obsess_over_services==TRUE)
04744                 return;
04745 
04746         /* set the attribute modified flag */
04747         modified_service_process_attributes|=attr;
04748 
04749         /* set the service obsession flag */
04750         obsess_over_services=TRUE;
04751 
04752 #ifdef USE_EVENT_BROKER
04753         /* send data to event broker */
04754         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,MODATTR_NONE,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
04755 #endif
04756 
04757         /* update the status log with the program info */
04758         update_program_status(FALSE);
04759 
04760         return;
04761         }
04762 
04763 
04764 
04765 /* stop obsessing over service check results */
04766 void stop_obsessing_over_service_checks(void){
04767         unsigned long attr=MODATTR_OBSESSIVE_HANDLER_ENABLED;
04768 
04769         /* no change */
04770         if(obsess_over_services==FALSE)
04771                 return;
04772 
04773         /* set the attribute modified flag */
04774         modified_service_process_attributes|=attr;
04775 
04776         /* set the service obsession flag */
04777         obsess_over_services=FALSE;
04778 
04779 #ifdef USE_EVENT_BROKER
04780         /* send data to event broker */
04781         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,MODATTR_NONE,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
04782 #endif
04783 
04784         /* update the status log with the program info */
04785         update_program_status(FALSE);
04786 
04787         return;
04788         }
04789 
04790 
04791 
04792 /* start obsessing over host check results */
04793 void start_obsessing_over_host_checks(void){
04794         unsigned long attr=MODATTR_OBSESSIVE_HANDLER_ENABLED;
04795 
04796         /* no change */
04797         if(obsess_over_hosts==TRUE)
04798                 return;
04799 
04800         /* set the attribute modified flag */
04801         modified_host_process_attributes|=attr;
04802 
04803         /* set the host obsession flag */
04804         obsess_over_hosts=TRUE;
04805 
04806 #ifdef USE_EVENT_BROKER
04807         /* send data to event broker */
04808         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,MODATTR_NONE,modified_service_process_attributes,NULL);
04809 #endif
04810 
04811         /* update the status log with the program info */
04812         update_program_status(FALSE);
04813 
04814         return;
04815         }
04816 
04817 
04818 
04819 /* stop obsessing over host check results */
04820 void stop_obsessing_over_host_checks(void){
04821         unsigned long attr=MODATTR_OBSESSIVE_HANDLER_ENABLED;
04822 
04823         /* no change */
04824         if(obsess_over_hosts==FALSE)
04825                 return;
04826 
04827         /* set the attribute modified flag */
04828         modified_host_process_attributes|=attr;
04829 
04830         /* set the host obsession flag */
04831         obsess_over_hosts=FALSE;
04832 
04833 #ifdef USE_EVENT_BROKER
04834         /* send data to event broker */
04835         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,MODATTR_NONE,modified_service_process_attributes,NULL);
04836 #endif
04837 
04838         /* update the status log with the program info */
04839         update_program_status(FALSE);
04840 
04841         return;
04842         }
04843 
04844 
04845 
04846 /* enables service freshness checking */
04847 void enable_service_freshness_checks(void){
04848         unsigned long attr=MODATTR_FRESHNESS_CHECKS_ENABLED;
04849 
04850         /* no change */
04851         if(check_service_freshness==TRUE)
04852                 return;
04853 
04854         /* set the attribute modified flag */
04855         modified_service_process_attributes|=attr;
04856 
04857         /* set the freshness check flag */
04858         check_service_freshness=TRUE;
04859 
04860 #ifdef USE_EVENT_BROKER
04861         /* send data to event broker */
04862         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,MODATTR_NONE,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
04863 #endif
04864 
04865         /* update the status log with the program info */
04866         update_program_status(FALSE);
04867 
04868         return;
04869         }
04870 
04871 
04872 /* disables service freshness checking */
04873 void disable_service_freshness_checks(void){
04874         unsigned long attr=MODATTR_FRESHNESS_CHECKS_ENABLED;
04875 
04876         /* no change */
04877         if(check_service_freshness==FALSE)
04878                 return;
04879 
04880         /* set the attribute modified flag */
04881         modified_service_process_attributes|=attr;
04882 
04883         /* set the freshness check flag */
04884         check_service_freshness=FALSE;
04885 
04886 #ifdef USE_EVENT_BROKER
04887         /* send data to event broker */
04888         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,MODATTR_NONE,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
04889 #endif
04890 
04891         /* update the status log with the program info */
04892         update_program_status(FALSE);
04893 
04894         return;
04895         }
04896 
04897 
04898 /* enables host freshness checking */
04899 void enable_host_freshness_checks(void){
04900         unsigned long attr=MODATTR_FRESHNESS_CHECKS_ENABLED;
04901 
04902         /* no change */
04903         if(check_host_freshness==TRUE)
04904                 return;
04905 
04906         /* set the attribute modified flag */
04907         modified_host_process_attributes|=attr;
04908 
04909         /* set the freshness check flag */
04910         check_host_freshness=TRUE;
04911 
04912 #ifdef USE_EVENT_BROKER
04913         /* send data to event broker */
04914         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,MODATTR_NONE,modified_service_process_attributes,NULL);
04915 #endif
04916 
04917         /* update the status log with the program info */
04918         update_program_status(FALSE);
04919 
04920         return;
04921         }
04922 
04923 
04924 /* disables host freshness checking */
04925 void disable_host_freshness_checks(void){
04926         unsigned long attr=MODATTR_FRESHNESS_CHECKS_ENABLED;
04927 
04928         /* no change */
04929         if(check_host_freshness==FALSE)
04930                 return;
04931 
04932         /* set the attribute modified flag */
04933         modified_host_process_attributes|=attr;
04934 
04935         /* set the freshness check flag */
04936         check_host_freshness=FALSE;
04937 
04938 #ifdef USE_EVENT_BROKER
04939         /* send data to event broker */
04940         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,MODATTR_NONE,modified_service_process_attributes,NULL);
04941 #endif
04942 
04943         /* update the status log with the program info */
04944         update_program_status(FALSE);
04945 
04946         return;
04947         }
04948 
04949 
04950 /* enable failure prediction on a program-wide basis */
04951 void enable_all_failure_prediction(void){
04952         unsigned long attr=MODATTR_FAILURE_PREDICTION_ENABLED;
04953 
04954         /* bail out if we're already set... */
04955         if(enable_failure_prediction==TRUE)
04956                 return;
04957 
04958         /* set the attribute modified flag */
04959         modified_host_process_attributes|=attr;
04960         modified_service_process_attributes|=attr;
04961 
04962         enable_failure_prediction=TRUE;
04963 
04964 #ifdef USE_EVENT_BROKER
04965         /* send data to event broker */
04966         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
04967 #endif
04968 
04969         /* update the status log */
04970         update_program_status(FALSE);
04971 
04972         return;
04973         }
04974 
04975 
04976 /* disable failure prediction on a program-wide basis */
04977 void disable_all_failure_prediction(void){
04978         unsigned long attr=MODATTR_FAILURE_PREDICTION_ENABLED;
04979 
04980         /* bail out if we're already set... */
04981         if(enable_failure_prediction==FALSE)
04982                 return;
04983 
04984         /* set the attribute modified flag */
04985         modified_host_process_attributes|=attr;
04986         modified_service_process_attributes|=attr;
04987 
04988         enable_failure_prediction=FALSE;
04989 
04990 #ifdef USE_EVENT_BROKER
04991         /* send data to event broker */
04992         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
04993 #endif
04994 
04995         /* update the status log */
04996         update_program_status(FALSE);
04997 
04998         return;
04999         }
05000 
05001 
05002 /* enable performance data on a program-wide basis */
05003 void enable_performance_data(void){
05004         unsigned long attr=MODATTR_PERFORMANCE_DATA_ENABLED;
05005 
05006         /* bail out if we're already set... */
05007         if(process_performance_data==TRUE)
05008                 return;
05009 
05010         /* set the attribute modified flag */
05011         modified_host_process_attributes|=attr;
05012         modified_service_process_attributes|=attr;
05013 
05014         process_performance_data=TRUE;
05015 
05016 #ifdef USE_EVENT_BROKER
05017         /* send data to event broker */
05018         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
05019 #endif
05020 
05021         /* update the status log */
05022         update_program_status(FALSE);
05023 
05024         return;
05025         }
05026 
05027 
05028 /* disable performance data on a program-wide basis */
05029 void disable_performance_data(void){
05030         unsigned long attr=MODATTR_PERFORMANCE_DATA_ENABLED;
05031 
05032 #       /* bail out if we're already set... */
05033         if(process_performance_data==FALSE)
05034                 return;
05035 
05036         /* set the attribute modified flag */
05037         modified_host_process_attributes|=attr;
05038         modified_service_process_attributes|=attr;
05039 
05040         process_performance_data=FALSE;
05041 
05042 #ifdef USE_EVENT_BROKER
05043         /* send data to event broker */
05044         broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
05045 #endif
05046 
05047         /* update the status log */
05048         update_program_status(FALSE);
05049 
05050         return;
05051         }
05052 
05053 
05054 /* start obsessing over a particular service */
05055 void start_obsessing_over_service(service *svc){
05056         unsigned long attr=MODATTR_OBSESSIVE_HANDLER_ENABLED;
05057 
05058         /* no change */
05059         if(svc->obsess_over_service==TRUE)
05060                 return;
05061 
05062         /* set the attribute modified flag */
05063         svc->modified_attributes|=attr;
05064 
05065         /* set the obsess over service flag */
05066         svc->obsess_over_service=TRUE;
05067 
05068 #ifdef USE_EVENT_BROKER
05069         /* send data to event broker */
05070         broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
05071 #endif
05072 
05073         /* update the status log with the service info */
05074         update_service_status(svc,FALSE);
05075 
05076         return;
05077         }
05078 
05079 
05080 /* stop obsessing over a particular service */
05081 void stop_obsessing_over_service(service *svc){
05082         unsigned long attr=MODATTR_OBSESSIVE_HANDLER_ENABLED;
05083 
05084         /* no change */
05085         if(svc->obsess_over_service==FALSE)
05086                 return;
05087 
05088         /* set the attribute modified flag */
05089         svc->modified_attributes|=attr;
05090 
05091         /* set the obsess over service flag */
05092         svc->obsess_over_service=FALSE;
05093 
05094 #ifdef USE_EVENT_BROKER
05095         /* send data to event broker */
05096         broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
05097 #endif
05098 
05099         /* update the status log with the service info */
05100         update_service_status(svc,FALSE);
05101 
05102         return;
05103         }
05104 
05105 
05106 /* start obsessing over a particular host */
05107 void start_obsessing_over_host(host *hst){
05108         unsigned long attr=MODATTR_OBSESSIVE_HANDLER_ENABLED;
05109 
05110         /* no change */
05111         if(hst->obsess_over_host==TRUE)
05112                 return;
05113 
05114         /* set the attribute modified flag */
05115         hst->modified_attributes|=attr;
05116 
05117         /* set the obsess over host flag */
05118         hst->obsess_over_host=TRUE;
05119 
05120 #ifdef USE_EVENT_BROKER
05121         /* send data to event broker */
05122         broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
05123 #endif
05124 
05125         /* update the status log with the host info */
05126         update_host_status(hst,FALSE);
05127 
05128         return;
05129         }
05130 
05131 
05132 /* stop obsessing over a particular host */
05133 void stop_obsessing_over_host(host *hst){
05134         unsigned long attr=MODATTR_OBSESSIVE_HANDLER_ENABLED;
05135 
05136         /* no change */
05137         if(hst->obsess_over_host==FALSE)
05138                 return;
05139 
05140         /* set the attribute modified flag */
05141         hst->modified_attributes|=attr;
05142 
05143         /* set the obsess over host flag */
05144         hst->obsess_over_host=FALSE;
05145 
05146 #ifdef USE_EVENT_BROKER
05147         /* send data to event broker */
05148         broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
05149 #endif
05150 
05151         /* update the status log with the host info */
05152         update_host_status(hst,FALSE);
05153 
05154         return;
05155         }
05156 
05157 
05158 /* sets the current notification number for a specific host */
05159 void set_host_notification_number(host *hst, int num){
05160 
05161         /* set the notification number */
05162         hst->current_notification_number=num;
05163 
05164         /* update the status log with the host info */
05165         update_host_status(hst,FALSE);
05166 
05167         return;
05168         }
05169 
05170 
05171 /* sets the current notification number for a specific service */
05172 void set_service_notification_number(service *svc, int num){
05173 
05174         /* set the notification number */
05175         svc->current_notification_number=num;
05176 
05177         /* update the status log with the service info */
05178         update_service_status(svc,FALSE);
05179 
05180         return;
05181         }
05182 
05183 
05184 
05185 /* process all passive host and service checks we found in the external command file */
05186 void process_passive_checks(void){
05187         passive_check_result *temp_pcr=NULL;
05188         passive_check_result *this_pcr=NULL;
05189         passive_check_result *next_pcr=NULL;
05190         char *checkresult_file=NULL;
05191         int checkresult_file_fd=-1;
05192         FILE *checkresult_file_fp=NULL;
05193         mode_t new_umask=077;
05194         mode_t old_umask;
05195         time_t current_time;
05196 
05197         log_debug_info(DEBUGL_FUNCTIONS,0,"process_passive_checks()\n");
05198 
05199         /* nothing to do */
05200         if(passive_check_result_list==NULL)
05201                 return;
05202 
05203         log_debug_info(DEBUGL_CHECKS,1,"Submitting passive host/service check results obtained from external commands...\n");
05204 
05205         /* open a temp file for storing check result(s) */
05206         old_umask=umask(new_umask);
05207         dummy=asprintf(&checkresult_file,"%s/checkXXXXXX",temp_path);
05208         checkresult_file_fd=mkstemp(checkresult_file);
05209         umask(old_umask);
05210 
05211         if(checkresult_file_fd < 0) {
05212                 logit(NSLOG_RUNTIME_ERROR,TRUE,"Failed to open checkresult file '%s': %s\n", checkresult_file, strerror(errno));
05213                 free(checkresult_file);
05214                 return;
05215         }
05216 
05217         checkresult_file_fp=fdopen(checkresult_file_fd,"w");
05218         
05219         time(&current_time);
05220         fprintf(checkresult_file_fp,"### Passive Check Result File ###\n");
05221         fprintf(checkresult_file_fp,"# Time: %s",ctime(&current_time));
05222         fprintf(checkresult_file_fp,"file_time=%lu\n",(unsigned long)current_time);
05223         fprintf(checkresult_file_fp,"\n");
05224 
05225         log_debug_info(DEBUGL_CHECKS|DEBUGL_IPC,1,"Passive check result(s) will be written to '%s' (fd=%d)\n",checkresult_file,checkresult_file_fd);
05226 
05227         /* write all service checks to check result queue file for later processing */
05228         for(temp_pcr=passive_check_result_list;temp_pcr!=NULL;temp_pcr=temp_pcr->next){
05229 
05230                 /* write check results to file */
05231                 if(checkresult_file_fp){
05232                 
05233                         fprintf(checkresult_file_fp,"### Icinga %s Check Result ###\n",(temp_pcr->object_check_type==SERVICE_CHECK)?"Service":"Host");
05234                         fprintf(checkresult_file_fp,"# Time: %s",ctime(&temp_pcr->check_time));
05235                         fprintf(checkresult_file_fp,"host_name=%s\n",(temp_pcr->host_name==NULL)?"":temp_pcr->host_name);
05236                         if(temp_pcr->object_check_type==SERVICE_CHECK)
05237                                 fprintf(checkresult_file_fp,"service_description=%s\n",(temp_pcr->service_description==NULL)?"":temp_pcr->service_description);
05238                         fprintf(checkresult_file_fp,"check_type=%d\n",(temp_pcr->object_check_type==HOST_CHECK)?HOST_CHECK_PASSIVE:SERVICE_CHECK_PASSIVE);
05239                         fprintf(checkresult_file_fp,"scheduled_check=0\n");
05240                         fprintf(checkresult_file_fp,"reschedule_check=0\n");
05241                         fprintf(checkresult_file_fp,"latency=%f\n",temp_pcr->latency);
05242                         fprintf(checkresult_file_fp,"start_time=%lu.%lu\n",temp_pcr->check_time,0L);
05243                         fprintf(checkresult_file_fp,"finish_time=%lu.%lu\n",temp_pcr->check_time,0L);
05244                         fprintf(checkresult_file_fp,"return_code=%d\n",temp_pcr->return_code);
05245                         /* newlines in output are already escaped */
05246                         fprintf(checkresult_file_fp,"output=%s\n",(temp_pcr->output==NULL)?"":temp_pcr->output);
05247                         fprintf(checkresult_file_fp,"\n");
05248                         }
05249                 }
05250 
05251         /* close the temp file */
05252         fclose(checkresult_file_fp);
05253 
05254         /* move check result to queue directory */
05255         move_check_result_to_queue(checkresult_file);
05256 
05257         /* free memory */
05258         my_free(checkresult_file);
05259 
05260         /* free memory for the passive check result list */
05261         this_pcr=passive_check_result_list;
05262         while(this_pcr!=NULL){
05263                 next_pcr=this_pcr->next;
05264                 my_free(this_pcr->host_name);
05265                 my_free(this_pcr->service_description);
05266                 my_free(this_pcr->output);
05267                 my_free(this_pcr);
05268                 this_pcr=next_pcr;
05269                 }
05270         passive_check_result_list=NULL;
05271         passive_check_result_list_tail=NULL;
05272 
05273         return;
05274         }
05275 
 All Data Structures Files Functions Variables Typedefs Defines