Icinga-core 1.4.0
next gen monitoring
common/downtime.c
Go to the documentation of this file.
00001 /*****************************************************************************
00002  *
00003  * DOWNTIME.C - Scheduled downtime functions for Icinga
00004  *
00005  * Copyright (c) 2000-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/objects.h"
00031 #include "../include/statusdata.h"
00032 
00033 /***** IMPLEMENTATION-SPECIFIC INCLUDES *****/
00034 
00035 #ifdef USE_XDDDEFAULT
00036 #include "../xdata/xdddefault.h"
00037 #endif
00038 
00039 #ifdef NSCORE
00040 #include "../include/icinga.h"
00041 #include "../include/broker.h"
00042 #endif
00043 
00044 #ifdef NSCGI
00045 #include "../include/cgiutils.h"
00046 #endif
00047 
00048 
00049 scheduled_downtime *scheduled_downtime_list=NULL;
00050 int                defer_downtime_sorting = 0;
00051 
00052 #ifdef NSCORE
00053 extern timed_event *event_list_high;
00054 extern timed_event *event_list_high_tail;
00055 #endif
00056 
00057 int dummy;      /* reduce compiler warnings */
00058 
00059 #ifdef NSCORE
00060 
00061 /******************************************************************/
00062 /**************** INITIALIZATION/CLEANUP FUNCTIONS ****************/
00063 /******************************************************************/
00064 
00065 
00066 /* initializes scheduled downtime data */
00067 int initialize_downtime_data(char *config_file){
00068         int result=OK;
00069 
00070         /**** IMPLEMENTATION-SPECIFIC CALLS ****/
00071 #ifdef USE_XDDDEFAULT
00072         result=xdddefault_initialize_downtime_data(config_file);
00073 #endif
00074 
00075         return result;
00076         }
00077 
00078 
00079 /* cleans up scheduled downtime data */
00080 int cleanup_downtime_data(char *config_file){
00081         int result=OK;
00082         
00083         /**** IMPLEMENTATION-SPECIFIC CALLS ****/
00084 #ifdef USE_XDDDEFAULT
00085         result=xdddefault_cleanup_downtime_data(config_file);
00086 #endif
00087 
00088         /* free memory allocated to downtime data */
00089         free_downtime_data();
00090 
00091         return result;
00092         }
00093 
00094 
00095 /******************************************************************/
00096 /********************** SCHEDULING FUNCTIONS **********************/
00097 /******************************************************************/
00098 
00099 /* schedules a host or service downtime */
00100 int schedule_downtime(int type, char *host_name, char *service_description, 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, unsigned long *new_downtime_id){
00101         unsigned long downtime_id=0L;
00102 
00103         log_debug_info(DEBUGL_FUNCTIONS,0,"schedule_downtime()\n");
00104 
00105         /* don't add old or invalid downtimes */
00106         if(start_time>=end_time || end_time<=time(NULL))
00107                 return ERROR;
00108 
00109         /* add a new downtime entry */
00110         add_new_downtime(type,host_name,service_description,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&downtime_id,FALSE);
00111 
00112         /* register the scheduled downtime */
00113         register_downtime(type,downtime_id);
00114 
00115         /* return downtime id */
00116         if(new_downtime_id!=NULL)
00117                 *new_downtime_id=downtime_id;
00118 
00119         return OK;
00120         }
00121 
00122 
00123 /* unschedules a host or service downtime */
00124 int unschedule_downtime(int type,unsigned long downtime_id){
00125         scheduled_downtime *temp_downtime=NULL;
00126         host *hst=NULL;
00127         service *svc=NULL;
00128         timed_event *temp_event=NULL;
00129 #ifdef USE_EVENT_BROKER
00130         int attr=0;
00131 #endif
00132 
00133         log_debug_info(DEBUGL_FUNCTIONS,0,"unschedule_downtime()\n");
00134 
00135         /* find the downtime entry in the list in memory */
00136         if((temp_downtime=find_downtime(type,downtime_id))==NULL)
00137                 return ERROR;
00138 
00139         /* find the host or service associated with this downtime */
00140         if(temp_downtime->type==HOST_DOWNTIME){
00141                 if((hst=find_host(temp_downtime->host_name))==NULL)
00142                         return ERROR;
00143                 }
00144         else{
00145                 if((svc=find_service(temp_downtime->host_name,temp_downtime->service_description))==NULL)
00146                         return ERROR;
00147                 }
00148 
00149         /* decrement pending flex downtime if necessary ... */
00150         if(temp_downtime->fixed==FALSE && temp_downtime->incremented_pending_downtime==TRUE){
00151                 if(temp_downtime->type==HOST_DOWNTIME)
00152                         hst->pending_flex_downtime--;
00153                 else
00154                         svc->pending_flex_downtime--;
00155                 }
00156 
00157         /* decrement the downtime depth variable and update status data if necessary */
00158         if(temp_downtime->is_in_effect==TRUE){
00159 
00160 #ifdef USE_EVENT_BROKER
00161                 /* send data to event broker */
00162                 attr=NEBATTR_DOWNTIME_STOP_CANCELLED;
00163                 broker_downtime_data(NEBTYPE_DOWNTIME_STOP,NEBFLAG_NONE,attr,temp_downtime->type,temp_downtime->host_name,temp_downtime->service_description,temp_downtime->entry_time,temp_downtime->author,temp_downtime->comment,temp_downtime->start_time,temp_downtime->end_time,temp_downtime->fixed,temp_downtime->triggered_by,temp_downtime->duration,temp_downtime->downtime_id,NULL);
00164 #endif
00165 
00166                 if(temp_downtime->type==HOST_DOWNTIME){
00167 
00168                         hst->scheduled_downtime_depth--;
00169                         update_host_status(hst,FALSE);
00170 
00171                         /* log a notice - this is parsed by the history CGI */
00172                         if(hst->scheduled_downtime_depth==0){
00173 
00174                                 logit(NSLOG_INFO_MESSAGE,FALSE,"HOST DOWNTIME ALERT: %s;CANCELLED; Scheduled downtime for host has been cancelled.\n",hst->name);
00175 
00176                                 /* send a notification */
00177                                 host_notification(hst,NOTIFICATION_DOWNTIMECANCELLED,NULL,NULL,NOTIFICATION_OPTION_NONE);
00178                                 }
00179                         }
00180 
00181                 else{
00182 
00183                         svc->scheduled_downtime_depth--;
00184                         update_service_status(svc,FALSE);
00185 
00186                         /* log a notice - this is parsed by the history CGI */
00187                         if(svc->scheduled_downtime_depth==0){
00188 
00189                                 logit(NSLOG_INFO_MESSAGE,FALSE,"SERVICE DOWNTIME ALERT: %s;%s;CANCELLED; Scheduled downtime for service has been cancelled.\n",svc->host_name,svc->description);
00190 
00191                                 /* send a notification */
00192                                 service_notification(svc,NOTIFICATION_DOWNTIMECANCELLED,NULL,NULL,NOTIFICATION_OPTION_NONE);
00193                                 }
00194                         }
00195                 }
00196 
00197         /* remove scheduled entry from event queue */
00198         for(temp_event=event_list_high;temp_event!=NULL;temp_event=temp_event->next){
00199                 if(temp_event->event_type!=EVENT_SCHEDULED_DOWNTIME)
00200                         continue;
00201                 if(((unsigned long)temp_event->event_data)==downtime_id)
00202                         break;
00203                 }
00204         if(temp_event!=NULL)
00205                 remove_event(temp_event,&event_list_high,&event_list_high_tail);
00206 
00207         /* delete downtime entry */
00208         if(temp_downtime->type==HOST_DOWNTIME)
00209                 delete_host_downtime(downtime_id);
00210         else
00211                 delete_service_downtime(downtime_id);
00212 
00213         /* unschedule all downtime entries that were triggered by this one */
00214         while(1){
00215 
00216                 for(temp_downtime=scheduled_downtime_list;temp_downtime!=NULL;temp_downtime=temp_downtime->next){
00217                         if(temp_downtime->triggered_by==downtime_id){
00218                                 unschedule_downtime(ANY_DOWNTIME,temp_downtime->downtime_id);
00219                                 break;
00220                                 }
00221                         }
00222 
00223                 if(temp_downtime==NULL)
00224                         break;
00225                 }
00226 
00227         return OK;
00228         }
00229 
00230 
00231 
00232 /* registers scheduled downtime (schedules it, adds comments, etc.) */
00233 int register_downtime(int type, unsigned long downtime_id){
00234         char *temp_buffer=NULL;
00235         char start_time_string[MAX_DATETIME_LENGTH]="";
00236         char end_time_string[MAX_DATETIME_LENGTH]="";
00237         scheduled_downtime *temp_downtime=NULL;
00238         host *hst=NULL;
00239         service *svc=NULL;
00240         char *type_string=NULL;
00241         int hours=0;
00242         int minutes=0;
00243         int seconds=0;
00244         unsigned long *new_downtime_id=NULL;
00245 
00246         log_debug_info(DEBUGL_FUNCTIONS,0,"register_downtime()\n");
00247 
00248         /* find the downtime entry in memory */
00249         temp_downtime=find_downtime(type,downtime_id);
00250         if(temp_downtime==NULL)
00251                 return ERROR;
00252 
00253         /* find the host or service associated with this downtime */
00254         if(temp_downtime->type==HOST_DOWNTIME){
00255                 if((hst=find_host(temp_downtime->host_name))==NULL)
00256                         return ERROR;
00257                 }
00258         else{
00259                 if((svc=find_service(temp_downtime->host_name,temp_downtime->service_description))==NULL)
00260                         return ERROR;
00261                 }
00262 
00263         /* create the comment */
00264         get_datetime_string(&(temp_downtime->start_time),start_time_string,MAX_DATETIME_LENGTH,SHORT_DATE_TIME);
00265         get_datetime_string(&(temp_downtime->end_time),end_time_string,MAX_DATETIME_LENGTH,SHORT_DATE_TIME);
00266         hours=temp_downtime->duration/3600;
00267         minutes=((temp_downtime->duration-(hours*3600))/60);
00268         seconds=temp_downtime->duration-(hours*3600)-(minutes*60);
00269         if(temp_downtime->type==HOST_DOWNTIME)
00270                 type_string="host";
00271         else
00272                 type_string="service";
00273         if(temp_downtime->fixed==TRUE)
00274                 dummy=asprintf(&temp_buffer,"This %s has been scheduled for fixed downtime from %s to %s.  Notifications for the %s will not be sent out during that time period.",type_string,start_time_string,end_time_string,type_string);
00275         else
00276                 dummy=asprintf(&temp_buffer,"This %s has been scheduled for flexible downtime starting between %s and %s and lasting for a period of %d hours and %d minutes.  Notifications for the %s will not be sent out during that time period.",type_string,start_time_string,end_time_string,hours,minutes,type_string);
00277 
00278 
00279         log_debug_info(DEBUGL_DOWNTIME,0,"Scheduled Downtime Details:\n");
00280         if(temp_downtime->type==HOST_DOWNTIME){
00281                 log_debug_info(DEBUGL_DOWNTIME,0," Type:        Host Downtime\n");
00282                 log_debug_info(DEBUGL_DOWNTIME,0," Host:        %s\n",hst->name);
00283                 }
00284         else{
00285                 log_debug_info(DEBUGL_DOWNTIME,0," Type:        Service Downtime\n");
00286                 log_debug_info(DEBUGL_DOWNTIME,0," Host:        %s\n",svc->host_name);
00287                 log_debug_info(DEBUGL_DOWNTIME,0," Service:     %s\n",svc->description);
00288                 }
00289         log_debug_info(DEBUGL_DOWNTIME,0," Fixed/Flex:  %s\n",(temp_downtime->fixed==TRUE)?"Fixed":"Flexible");
00290         log_debug_info(DEBUGL_DOWNTIME,0," Start:       %s\n",start_time_string);
00291         log_debug_info(DEBUGL_DOWNTIME,0," End:         %s\n",end_time_string);
00292         log_debug_info(DEBUGL_DOWNTIME,0," Duration:    %dh %dm %ds\n",hours,minutes,seconds);
00293         log_debug_info(DEBUGL_DOWNTIME,0," Downtime ID: %lu\n",temp_downtime->downtime_id);
00294         log_debug_info(DEBUGL_DOWNTIME,0," Trigger ID:  %lu\n",temp_downtime->triggered_by);
00295 
00296 
00297         /* add a non-persistent comment to the host or service regarding the scheduled outage */
00298         if(temp_downtime->type==SERVICE_DOWNTIME)
00299                 add_new_comment(SERVICE_COMMENT,DOWNTIME_COMMENT,svc->host_name,svc->description,time(NULL),"(Icinga Process)",temp_buffer,0,COMMENTSOURCE_INTERNAL,FALSE,(time_t)0,&(temp_downtime->comment_id));
00300         else
00301                 add_new_comment(HOST_COMMENT,DOWNTIME_COMMENT,hst->name,NULL,time(NULL),"(Icinga Process)",temp_buffer,0,COMMENTSOURCE_INTERNAL,FALSE,(time_t)0,&(temp_downtime->comment_id));
00302 
00303 
00304         /*** SCHEDULE DOWNTIME - FLEXIBLE (NON-FIXED) DOWNTIME IS HANDLED AT A LATER POINT ***/
00305 
00306         /* only non-triggered downtime is scheduled... */
00307         if(temp_downtime->triggered_by==0){
00308                 if((new_downtime_id=(unsigned long *)malloc(sizeof(unsigned long *)))){
00309                         *new_downtime_id=downtime_id;
00310                         schedule_new_event(EVENT_SCHEDULED_DOWNTIME,TRUE,temp_downtime->start_time,FALSE,0,NULL,FALSE,(void *)new_downtime_id,NULL,0);
00311                         }
00312                 }
00313 
00314 #ifdef PROBABLY_NOT_NEEDED
00315         /*** FLEXIBLE DOWNTIME SANITY CHECK - ADDED 02/17/2008 ****/
00316 
00317         /* if host/service is in a non-OK/UP state right now, see if we should start flexible time immediately */
00318         /* this is new logic added in 3.0rc3 */
00319         if(temp_downtime->fixed==FALSE){
00320                 if(temp_downtime->type==HOST_DOWNTIME)
00321                         check_pending_flex_host_downtime(hst);
00322                 else
00323                         check_pending_flex_service_downtime(svc);
00324                 }
00325 #endif
00326 
00327         return OK;
00328         }
00329 
00330 
00331 
00332 /* handles scheduled downtime (id passed from timed event queue) */
00333 int handle_scheduled_downtime_by_id(unsigned long downtime_id){
00334         scheduled_downtime *temp_downtime=NULL;
00335 
00336         /* find the downtime entry */
00337         if((temp_downtime=find_downtime(ANY_DOWNTIME,downtime_id))==NULL)
00338                 return ERROR;
00339 
00340         /* handle the downtime */
00341         return handle_scheduled_downtime(temp_downtime);
00342         }
00343         
00344 
00345 
00346 /* handles scheduled host or service downtime */
00347 int handle_scheduled_downtime(scheduled_downtime *temp_downtime){
00348         scheduled_downtime *this_downtime=NULL;
00349         host *hst=NULL;
00350         service *svc=NULL;
00351         time_t event_time=0L;
00352         time_t current_time=0L;
00353         unsigned long *new_downtime_id=NULL;
00354 #ifdef USE_EVENT_BROKER
00355         int attr=0;
00356 #endif
00357 
00358 
00359         log_debug_info(DEBUGL_FUNCTIONS,0,"handle_scheduled_downtime()\n");
00360 
00361         if(temp_downtime==NULL)
00362                 return ERROR;
00363 
00364         /* find the host or service associated with this downtime */
00365         if(temp_downtime->type==HOST_DOWNTIME){
00366                 if((hst=find_host(temp_downtime->host_name))==NULL)
00367                         return ERROR;
00368                 }
00369         else{
00370                 if((svc=find_service(temp_downtime->host_name,temp_downtime->service_description))==NULL)
00371                         return ERROR;
00372                 }
00373 
00374         /* if downtime if flexible and host/svc is in an ok state, don't do anything right now (wait for event handler to kick it off) */
00375         /* start_flex_downtime variable is set to TRUE by event handler functions */
00376         if(temp_downtime->fixed==FALSE){
00377 
00378                 /* we're not supposed to force a start of flex downtime... */
00379                 if(temp_downtime->start_flex_downtime==FALSE){
00380 
00381                         /* host is up or service is ok, so we don't really do anything right now */
00382                         if((temp_downtime->type==HOST_DOWNTIME && hst->current_state==HOST_UP) || (temp_downtime->type==SERVICE_DOWNTIME && svc->current_state==STATE_OK)){
00383 
00384                                 /* increment pending flex downtime counter */
00385                                 if(temp_downtime->type==HOST_DOWNTIME)
00386                                         hst->pending_flex_downtime++;
00387                                 else
00388                                         svc->pending_flex_downtime++;
00389                                 temp_downtime->incremented_pending_downtime=TRUE;
00390 
00391                                 /*** SINCE THE FLEX DOWNTIME MAY NEVER START, WE HAVE TO PROVIDE A WAY OF EXPIRING UNUSED DOWNTIME... ***/
00392 
00393                                 schedule_new_event(EVENT_EXPIRE_DOWNTIME,TRUE,(temp_downtime->end_time+1),FALSE,0,NULL,FALSE,NULL,NULL,0);
00394 
00395                                 return OK;
00396                         }
00397                 }
00398         }
00399 
00400         time(&current_time);
00401 
00402         /* have we come to the end of the scheduled downtime? */
00403         if(temp_downtime->is_in_effect==TRUE && current_time >= temp_downtime->end_time){
00404 
00405 #ifdef USE_EVENT_BROKER
00406                 /* send data to event broker */
00407                 attr=NEBATTR_DOWNTIME_STOP_NORMAL;
00408                 broker_downtime_data(NEBTYPE_DOWNTIME_STOP,NEBFLAG_NONE,attr,temp_downtime->type,temp_downtime->host_name,temp_downtime->service_description,temp_downtime->entry_time,temp_downtime->author,temp_downtime->comment,temp_downtime->start_time,temp_downtime->end_time,temp_downtime->fixed,temp_downtime->triggered_by,temp_downtime->duration,temp_downtime->downtime_id,NULL);
00409 #endif
00410 
00411                 /* decrement the downtime depth variable */
00412                 if(temp_downtime->type==HOST_DOWNTIME)
00413                         hst->scheduled_downtime_depth--;
00414                 else
00415                         svc->scheduled_downtime_depth--;
00416 
00417                 if(temp_downtime->type==HOST_DOWNTIME && hst->scheduled_downtime_depth==0){
00418 
00419                         log_debug_info(DEBUGL_DOWNTIME,0,"Host '%s' has exited from a period of scheduled downtime (id=%lu).\n",hst->name,temp_downtime->downtime_id);
00420 
00421                         /* log a notice - this one is parsed by the history CGI */
00422                         logit(NSLOG_INFO_MESSAGE,FALSE,"HOST DOWNTIME ALERT: %s;STOPPED; Host has exited from a period of scheduled downtime",hst->name);
00423 
00424                         /* send a notification */
00425                         host_notification(hst,NOTIFICATION_DOWNTIMEEND,temp_downtime->author,temp_downtime->comment,NOTIFICATION_OPTION_NONE);
00426                         }
00427 
00428                 else if(temp_downtime->type==SERVICE_DOWNTIME && svc->scheduled_downtime_depth==0){
00429 
00430                         log_debug_info(DEBUGL_DOWNTIME,0,"Service '%s' on host '%s' has exited from a period of scheduled downtime (id=%lu).\n",svc->description,svc->host_name,temp_downtime->downtime_id);
00431 
00432                         /* log a notice - this one is parsed by the history CGI */
00433                         logit(NSLOG_INFO_MESSAGE,FALSE,"SERVICE DOWNTIME ALERT: %s;%s;STOPPED; Service has exited from a period of scheduled downtime",svc->host_name,svc->description);
00434 
00435                         /* send a notification */
00436                         service_notification(svc,NOTIFICATION_DOWNTIMEEND,temp_downtime->author,temp_downtime->comment,NOTIFICATION_OPTION_NONE);
00437                         }
00438 
00439 
00440                 /* update the status data */
00441                 if(temp_downtime->type==HOST_DOWNTIME)
00442                         update_host_status(hst,FALSE);
00443                 else
00444                         update_service_status(svc,FALSE);
00445 
00446                 /* decrement pending flex downtime if necessary */
00447                 if(temp_downtime->fixed==FALSE && temp_downtime->incremented_pending_downtime==TRUE){
00448                         if(temp_downtime->type==HOST_DOWNTIME){
00449                                 if(hst->pending_flex_downtime>0)
00450                                         hst->pending_flex_downtime--;
00451                                 }
00452                         else{
00453                                 if(svc->pending_flex_downtime>0)
00454                                         svc->pending_flex_downtime--;
00455                                 }
00456                         }
00457 
00458                 /* handle (stop) downtime that is triggered by this one */
00459                 while(1){
00460 
00461                         /* list contents might change by recursive calls, so we use this inefficient method to prevent segfaults */
00462                         for(this_downtime=scheduled_downtime_list;this_downtime!=NULL;this_downtime=this_downtime->next){
00463                                 if(this_downtime->triggered_by==temp_downtime->downtime_id){
00464                                         handle_scheduled_downtime(this_downtime);
00465                                         break;
00466                                         }
00467                                 }
00468 
00469                         if(this_downtime==NULL)
00470                                 break;
00471                         }
00472 
00473                 /* delete downtime entry */
00474                 if(temp_downtime->type==HOST_DOWNTIME)
00475                         delete_host_downtime(temp_downtime->downtime_id);
00476                 else
00477                         delete_service_downtime(temp_downtime->downtime_id);
00478         }
00479 
00480         /* else we are just starting the scheduled downtime */
00481         else{
00482 
00483 #ifdef USE_EVENT_BROKER
00484                 /* send data to event broker */
00485                 broker_downtime_data(NEBTYPE_DOWNTIME_START,NEBFLAG_NONE,NEBATTR_NONE,temp_downtime->type,temp_downtime->host_name,temp_downtime->service_description,temp_downtime->entry_time,temp_downtime->author,temp_downtime->comment,temp_downtime->start_time,temp_downtime->end_time,temp_downtime->fixed,temp_downtime->triggered_by,temp_downtime->duration,temp_downtime->downtime_id,NULL);
00486 #endif
00487                 /* this happens after restart of icinga */
00488                 if (temp_downtime->is_in_effect!=TRUE) {
00489                         if(temp_downtime->type==HOST_DOWNTIME && hst->scheduled_downtime_depth==0){
00490 
00491                                 log_debug_info(DEBUGL_DOWNTIME,0,"Host '%s' has entered a period of scheduled downtime (id=%lu).\n",hst->name,temp_downtime->downtime_id);
00492 
00493                                 /* log a notice - this one is parsed by the history CGI */
00494                                 logit(NSLOG_INFO_MESSAGE,FALSE,"HOST DOWNTIME ALERT: %s;STARTED; Host has entered a period of scheduled downtime",hst->name);
00495 
00496                                 /* send a notification */
00497                                 host_notification(hst,NOTIFICATION_DOWNTIMESTART,temp_downtime->author,temp_downtime->comment,NOTIFICATION_OPTION_NONE);
00498                         }
00499 
00500                         else if(temp_downtime->type==SERVICE_DOWNTIME && svc->scheduled_downtime_depth==0){
00501 
00502                                 log_debug_info(DEBUGL_DOWNTIME,0,"Service '%s' on host '%s' has entered a period of scheduled downtime (id=%lu).\n",svc->description,svc->host_name,temp_downtime->downtime_id);
00503 
00504                                 /* log a notice - this one is parsed by the history CGI */
00505                                 logit(NSLOG_INFO_MESSAGE,FALSE,"SERVICE DOWNTIME ALERT: %s;%s;STARTED; Service has entered a period of scheduled downtime",svc->host_name,svc->description);
00506 
00507                                 /* send a notification */
00508                                 service_notification(svc,NOTIFICATION_DOWNTIMESTART,temp_downtime->author,temp_downtime->comment,NOTIFICATION_OPTION_NONE);
00509                         }
00510                 }
00511 
00512                 /* increment the downtime depth variable */
00513                 if(temp_downtime->type==HOST_DOWNTIME)
00514                         hst->scheduled_downtime_depth++;
00515                 else
00516                         svc->scheduled_downtime_depth++;
00517 
00518                 /* set the in effect flag */
00519                 temp_downtime->is_in_effect=TRUE;
00520 
00521                 /* update the status data */
00522                 if(temp_downtime->type==HOST_DOWNTIME)
00523                         update_host_status(hst,FALSE);
00524                 else
00525                         update_service_status(svc,FALSE);
00526 
00527                 /* schedule an event */
00528                 if(temp_downtime->fixed==FALSE)
00529                         event_time=(time_t)((unsigned long)time(NULL)+temp_downtime->duration);
00530                 else
00531                         event_time=temp_downtime->end_time;
00532 
00533                 if((new_downtime_id=(unsigned long *)malloc(sizeof(unsigned long *)))){
00534                         *new_downtime_id=temp_downtime->downtime_id;
00535                         schedule_new_event(EVENT_SCHEDULED_DOWNTIME,TRUE,event_time,FALSE,0,NULL,FALSE,(void *)new_downtime_id,NULL,0);
00536                 }
00537 
00538                 /* handle (start) downtime that is triggered by this one */
00539                 for(this_downtime=scheduled_downtime_list;this_downtime!=NULL;this_downtime=this_downtime->next){
00540                         if(this_downtime->triggered_by==temp_downtime->downtime_id)
00541                                 handle_scheduled_downtime(this_downtime);
00542                 }
00543         }
00544         
00545         return OK;
00546 }
00547 
00548 
00549 
00550 /* checks for flexible (non-fixed) host downtime that should start now */
00551 int check_pending_flex_host_downtime(host *hst){
00552         scheduled_downtime *temp_downtime=NULL;
00553         time_t current_time=0L;
00554 
00555 
00556         log_debug_info(DEBUGL_FUNCTIONS,0,"check_pending_flex_host_downtime()\n");
00557 
00558         if(hst==NULL)
00559                 return ERROR;
00560 
00561         time(&current_time);
00562 
00563         /* if host is currently up, nothing to do */
00564         if(hst->current_state==HOST_UP)
00565                 return OK;
00566 
00567         /* check all downtime entries */
00568         for(temp_downtime=scheduled_downtime_list;temp_downtime!=NULL;temp_downtime=temp_downtime->next){
00569 
00570                 if(temp_downtime->type!=HOST_DOWNTIME)
00571                         continue;
00572 
00573                 if(temp_downtime->fixed==TRUE)
00574                         continue;
00575 
00576                 if(temp_downtime->is_in_effect==TRUE)
00577                         continue;
00578 
00579                 /* triggered downtime entries should be ignored here */
00580                 if(temp_downtime->triggered_by!=0)
00581                         continue;
00582 
00583                 /* this entry matches our host! */
00584                 if(find_host(temp_downtime->host_name)==hst){
00585                         
00586                         /* if the time boundaries are okay, start this scheduled downtime */
00587                         if(temp_downtime->start_time<=current_time && current_time<=temp_downtime->end_time){
00588 
00589                                 log_debug_info(DEBUGL_DOWNTIME,0,"Flexible downtime (id=%lu) for host '%s' starting now...\n",temp_downtime->downtime_id,hst->name);
00590 
00591                                 temp_downtime->start_flex_downtime=TRUE;
00592                                 handle_scheduled_downtime(temp_downtime);
00593                                 }
00594                         }
00595                 }
00596 
00597         return OK;
00598         }
00599 
00600 
00601 /* checks for flexible (non-fixed) service downtime that should start now */
00602 int check_pending_flex_service_downtime(service *svc){
00603         scheduled_downtime *temp_downtime=NULL;
00604         time_t current_time=0L;
00605 
00606 
00607         log_debug_info(DEBUGL_FUNCTIONS,0,"check_pending_flex_service_downtime()\n");
00608 
00609         if(svc==NULL)
00610                 return ERROR;
00611 
00612         time(&current_time);
00613 
00614         /* if service is currently ok, nothing to do */
00615         if(svc->current_state==STATE_OK)
00616                 return OK;
00617 
00618         /* check all downtime entries */
00619         for(temp_downtime=scheduled_downtime_list;temp_downtime!=NULL;temp_downtime=temp_downtime->next){
00620 
00621                 if(temp_downtime->type!=SERVICE_DOWNTIME)
00622                         continue;
00623 
00624                 if(temp_downtime->fixed==TRUE)
00625                         continue;
00626 
00627                 if(temp_downtime->is_in_effect==TRUE)
00628                         continue;
00629 
00630                 /* triggered downtime entries should be ignored here */
00631                 if(temp_downtime->triggered_by!=0)
00632                         continue;
00633 
00634                 /* this entry matches our service! */
00635                 if(find_service(temp_downtime->host_name,temp_downtime->service_description)==svc){
00636 
00637                         /* if the time boundaries are okay, start this scheduled downtime */
00638                         if(temp_downtime->start_time<=current_time && current_time<=temp_downtime->end_time){
00639 
00640                                 log_debug_info(DEBUGL_DOWNTIME,0,"Flexible downtime (id=%lu) for service '%s' on host '%s' starting now...\n",temp_downtime->downtime_id,svc->description,svc->host_name);
00641 
00642                                 temp_downtime->start_flex_downtime=TRUE;
00643                                 handle_scheduled_downtime(temp_downtime);
00644                                 }
00645                         }
00646                 }
00647 
00648         return OK;
00649         }
00650 
00651 
00652 /* checks for (and removes) expired downtime entries */
00653 int check_for_expired_downtime(void){
00654         scheduled_downtime *temp_downtime=NULL;
00655         scheduled_downtime *next_downtime=NULL;
00656         time_t current_time=0L;
00657 
00658 
00659         log_debug_info(DEBUGL_FUNCTIONS,0,"check_for_expired_downtime()\n");
00660 
00661         time(&current_time);
00662 
00663         /* check all downtime entries... */
00664         for(temp_downtime=scheduled_downtime_list;temp_downtime!=NULL;temp_downtime=next_downtime){
00665 
00666                 next_downtime=temp_downtime->next;
00667 
00668                 /* this entry should be removed */
00669                 if(temp_downtime->is_in_effect==FALSE && temp_downtime->end_time<current_time){
00670 
00671                         log_debug_info(DEBUGL_DOWNTIME,0,"Expiring %s downtime (id=%lu)...\n",(temp_downtime->type==HOST_DOWNTIME)?"host":"service",temp_downtime->downtime_id);
00672 
00673                         /* delete the downtime entry */
00674                         if(temp_downtime->type==HOST_DOWNTIME)
00675                                 delete_host_downtime(temp_downtime->downtime_id);
00676                         else
00677                                 delete_service_downtime(temp_downtime->downtime_id);
00678                         }
00679                 }
00680 
00681         return OK;
00682         }
00683 
00684 
00685 
00686 /******************************************************************/
00687 /************************* SAVE FUNCTIONS *************************/
00688 /******************************************************************/
00689 
00690 
00691 /* save a host or service downtime */
00692 int add_new_downtime(int type, char *host_name, char *service_description, 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, unsigned long *downtime_id,int is_in_effect){
00693         int result=OK;
00694 
00695         if(type==HOST_DOWNTIME)
00696                 result=add_new_host_downtime(host_name,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,downtime_id,is_in_effect);
00697         else
00698                 result=add_new_service_downtime(host_name,service_description,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,downtime_id,is_in_effect);
00699 
00700         return result;
00701         }
00702 
00703 
00704 /* saves a host downtime entry */
00705 int add_new_host_downtime(char *host_name, 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, unsigned long *downtime_id,int is_in_effect){
00706         int result=OK;
00707         unsigned long new_downtime_id=0L;
00708 
00709         if(host_name==NULL)
00710                 return ERROR;
00711 
00712         /**** IMPLEMENTATION-SPECIFIC CALLS ****/
00713 #ifdef USE_XDDDEFAULT
00714         result=xdddefault_add_new_host_downtime(host_name,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&new_downtime_id,is_in_effect);
00715 #endif
00716 
00717         /* save downtime id */
00718         if(downtime_id!=NULL)
00719                 *downtime_id=new_downtime_id;
00720 
00721 #ifdef USE_EVENT_BROKER
00722         /* send data to event broker */
00723         broker_downtime_data(NEBTYPE_DOWNTIME_ADD,NEBFLAG_NONE,NEBATTR_NONE,HOST_DOWNTIME,host_name,NULL,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,new_downtime_id,NULL);
00724 #endif
00725 
00726         return result;
00727         }
00728 
00729 
00730 /* saves a service downtime entry */
00731 int add_new_service_downtime(char *host_name, char *service_description, 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, unsigned long *downtime_id,int is_in_effect){
00732         int result=OK;
00733         unsigned long new_downtime_id=0L;
00734 
00735         if(host_name==NULL || service_description==NULL)
00736                 return ERROR;
00737 
00738         /**** IMPLEMENTATION-SPECIFIC CALLS ****/
00739 #ifdef USE_XDDDEFAULT
00740         result=xdddefault_add_new_service_downtime(host_name,service_description,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&new_downtime_id,is_in_effect);
00741 #endif
00742 
00743         /* save downtime id */
00744         if(downtime_id!=NULL)
00745                 *downtime_id=new_downtime_id;
00746 
00747 #ifdef USE_EVENT_BROKER
00748         /* send data to event broker */
00749         broker_downtime_data(NEBTYPE_DOWNTIME_ADD,NEBFLAG_NONE,NEBATTR_NONE,SERVICE_DOWNTIME,host_name,service_description,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,new_downtime_id,NULL);
00750 #endif
00751 
00752         return result;
00753         }
00754 
00755 
00756 
00757 /******************************************************************/
00758 /*********************** DELETION FUNCTIONS ***********************/
00759 /******************************************************************/
00760 
00761 
00762 /* deletes a scheduled host or service downtime entry from the list in memory */
00763 int delete_downtime(int type,unsigned long downtime_id){
00764         int result=OK;
00765         scheduled_downtime *this_downtime=NULL;
00766         scheduled_downtime *last_downtime=NULL;
00767         scheduled_downtime *next_downtime=NULL;
00768 
00769         /* find the downtime we should remove */
00770         for(this_downtime=scheduled_downtime_list,last_downtime=scheduled_downtime_list;this_downtime!=NULL;this_downtime=next_downtime){
00771                 next_downtime=this_downtime->next;
00772 
00773                 /* we found the downtime we should delete */
00774                 if(this_downtime->downtime_id==downtime_id && this_downtime->type==type)
00775                         break;
00776 
00777                 last_downtime=this_downtime;
00778                 }
00779 
00780         /* remove the downtime from the list in memory */
00781         if(this_downtime!=NULL){
00782 
00783                 /* first remove the comment associated with this downtime */
00784                 if(this_downtime->type==HOST_DOWNTIME)
00785                         delete_host_comment(this_downtime->comment_id);
00786                 else
00787                         delete_service_comment(this_downtime->comment_id);
00788 
00789 #ifdef USE_EVENT_BROKER
00790                 /* send data to event broker */
00791                 broker_downtime_data(NEBTYPE_DOWNTIME_DELETE,NEBFLAG_NONE,NEBATTR_NONE,type,this_downtime->host_name,this_downtime->service_description,this_downtime->entry_time,this_downtime->author,this_downtime->comment,this_downtime->start_time,this_downtime->end_time,this_downtime->fixed,this_downtime->triggered_by,this_downtime->duration,downtime_id,NULL);
00792 #endif
00793 
00794                 if(scheduled_downtime_list==this_downtime)
00795                         scheduled_downtime_list=this_downtime->next;
00796                 else
00797                         last_downtime->next=next_downtime;
00798                 
00799                 /* free memory */
00800                 my_free(this_downtime->host_name);
00801                 my_free(this_downtime->service_description);
00802                 my_free(this_downtime->author);
00803                 my_free(this_downtime->comment);
00804                 my_free(this_downtime);
00805 
00806                 result=OK;
00807                 }
00808         else
00809                 result=ERROR;
00810         
00811         return result;
00812         }
00813 
00814 
00815 /* deletes a scheduled host downtime entry */
00816 int delete_host_downtime(unsigned long downtime_id){
00817         int result=OK;
00818 
00819         /* delete the downtime from memory */
00820         delete_downtime(HOST_DOWNTIME,downtime_id);
00821         
00822         /**** IMPLEMENTATION-SPECIFIC CALLS ****/
00823 #ifdef USE_XDDDEFAULT
00824         result=xdddefault_delete_host_downtime(downtime_id);
00825 #endif
00826 
00827         return result;
00828         }
00829 
00830 
00831 /* deletes a scheduled service downtime entry */
00832 int delete_service_downtime(unsigned long downtime_id){
00833         int result=OK;
00834 
00835         /* delete the downtime from memory */
00836         delete_downtime(SERVICE_DOWNTIME,downtime_id);
00837         
00838         /**** IMPLEMENTATION-SPECIFIC CALLS ****/
00839 #ifdef USE_XDDDEFAULT
00840         result=xdddefault_delete_service_downtime(downtime_id);
00841 #endif
00842 
00843         return result;
00844         }
00845 
00846 /* 
00847 Deletes all host and service downtimes on a host by hostname, optionally filtered by service description, start time and comment. 
00848 All char* must be set or NULL - "" will silently fail to match
00849 Returns number deleted 
00850 */
00851 int delete_downtime_by_hostname_service_description_start_time_comment(char *hostname, char *service_description, time_t start_time, char *comment){
00852         scheduled_downtime *temp_downtime;
00853         int deleted=0;
00854 
00855         /* Do not allow deletion of everything - must have at least 1 filter on */
00856         if(hostname==NULL && service_description==NULL && start_time==0 && comment==NULL)
00857                 return deleted;
00858 
00859         for(temp_downtime=scheduled_downtime_list;temp_downtime!=NULL;temp_downtime=temp_downtime->next){
00860                 if(start_time!=0 && temp_downtime->start_time!=start_time) {
00861                         continue;
00862                 }
00863                 if(comment!=NULL && strcmp(temp_downtime->comment,comment)!=0)
00864                         continue;
00865                 if(temp_downtime->type==HOST_DOWNTIME) {
00866                         /* If service is specified, then do not delete the host downtime */
00867                         if(service_description!=NULL)
00868                                 continue;
00869                         if(hostname!=NULL && strcmp(temp_downtime->host_name,hostname)!=0)
00870                                 continue;
00871                         }
00872                 else if(temp_downtime->type==SERVICE_DOWNTIME) {
00873                         if(hostname!=NULL && strcmp(temp_downtime->host_name,hostname)!=0)
00874                                 continue;
00875                         if(service_description!=NULL && strcmp(temp_downtime->service_description,service_description)!=0)
00876                                 continue;
00877                         }
00878                 
00879                 unschedule_downtime(temp_downtime->type,temp_downtime->downtime_id);
00880                 deleted++;
00881                 }
00882         return deleted;
00883         }
00884 
00885 #endif
00886 
00887 
00888 
00889 
00890 
00891 /******************************************************************/
00892 /******************** ADDITION FUNCTIONS **************************/
00893 /******************************************************************/
00894 
00895 /* adds a host downtime entry to the list in memory */
00896 int add_host_downtime(char *host_name, 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, unsigned long downtime_id,int is_in_effect){
00897         int result=OK;
00898 
00899         result=add_downtime(HOST_DOWNTIME,host_name,NULL,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,downtime_id,is_in_effect);
00900 
00901         return result;
00902         }
00903 
00904 
00905 /* adds a service downtime entry to the list in memory */
00906 int add_service_downtime(char *host_name, char *svc_description, 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, unsigned long downtime_id,int is_in_effect){
00907         int result=OK;
00908 
00909         result=add_downtime(SERVICE_DOWNTIME,host_name,svc_description,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,downtime_id,is_in_effect);
00910 
00911         return result;
00912         }
00913 
00914 
00915 /* adds a host or service downtime entry to the list in memory */
00916 int add_downtime(int downtime_type, char *host_name, char *svc_description, 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, unsigned long downtime_id,int is_in_effect){
00917         scheduled_downtime *new_downtime=NULL;
00918         scheduled_downtime *last_downtime=NULL;
00919         scheduled_downtime *temp_downtime=NULL;
00920         int result=OK;
00921 
00922         /* don't add triggered downtimes that don't have a valid parent */
00923         if(triggered_by>0  && find_downtime(ANY_DOWNTIME,triggered_by)==NULL)
00924                 return ERROR;
00925 
00926         /* we don't have enough info */
00927         if(host_name==NULL || (downtime_type==SERVICE_DOWNTIME && svc_description==NULL))
00928                 return ERROR;
00929 
00930         /* allocate memory for the downtime */
00931         if((new_downtime=(scheduled_downtime *)calloc(1, sizeof(scheduled_downtime)))==NULL)
00932                 return ERROR;
00933 
00934         /* duplicate vars */
00935         if((new_downtime->host_name=(char *)strdup(host_name))==NULL)
00936                 result=ERROR;
00937         if(downtime_type==SERVICE_DOWNTIME){
00938                 if((new_downtime->service_description=(char *)strdup(svc_description))==NULL)
00939                         result=ERROR;
00940                 }
00941         if(author){
00942                 if((new_downtime->author=(char *)strdup(author))==NULL)
00943                         result=ERROR;
00944                 }
00945         if(comment_data){
00946                 if((new_downtime->comment=(char *)strdup(comment_data))==NULL)
00947                         result=ERROR;
00948                 }
00949 
00950         /* handle errors */
00951         if(result==ERROR){
00952                 my_free(new_downtime->comment);
00953                 my_free(new_downtime->author);
00954                 my_free(new_downtime->service_description);
00955                 my_free(new_downtime->host_name);
00956                 my_free(new_downtime);
00957                 return ERROR;
00958                 }
00959 
00960         new_downtime->type=downtime_type;
00961         new_downtime->entry_time=entry_time;
00962         new_downtime->start_time=start_time;
00963         new_downtime->end_time=end_time;
00964         new_downtime->fixed=(fixed>0)?TRUE:FALSE;
00965         new_downtime->triggered_by=triggered_by;
00966         new_downtime->duration=duration;
00967         new_downtime->downtime_id=downtime_id;
00968         new_downtime->is_in_effect=is_in_effect;
00969 
00970         if(defer_downtime_sorting){
00971                 new_downtime->next=scheduled_downtime_list;
00972                 scheduled_downtime_list=new_downtime;
00973         }
00974         else{
00975                 /* add new downtime to downtime list, sorted by start time */
00976                 last_downtime=scheduled_downtime_list;
00977                 for(temp_downtime=scheduled_downtime_list;temp_downtime!=NULL;temp_downtime=temp_downtime->next){
00978                         if(new_downtime->start_time<temp_downtime->start_time){
00979                                 new_downtime->next=temp_downtime;
00980                                 if(temp_downtime==scheduled_downtime_list)
00981                                         scheduled_downtime_list=new_downtime;
00982                                 else
00983                                         last_downtime->next=new_downtime;
00984                                 break;
00985                                 }
00986                         else
00987                                 last_downtime=temp_downtime;
00988                         }
00989                 if(scheduled_downtime_list==NULL){
00990                         new_downtime->next=NULL;
00991                         scheduled_downtime_list=new_downtime;
00992                         }
00993                 else if(temp_downtime==NULL){
00994                         new_downtime->next=NULL;
00995                         last_downtime->next=new_downtime;
00996                         }
00997                 }
00998 #ifdef NSCORE
00999 #ifdef USE_EVENT_BROKER
01000         /* send data to event broker */
01001         broker_downtime_data(NEBTYPE_DOWNTIME_LOAD,NEBFLAG_NONE,NEBATTR_NONE,downtime_type,host_name,svc_description,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,downtime_id,NULL);
01002 #endif
01003 #endif
01004 
01005         return OK;
01006         }
01007 
01008 static int downtime_compar(const void *p1, const void *p2){
01009         scheduled_downtime *d1 = *(scheduled_downtime **)p1;
01010         scheduled_downtime *d2 = *(scheduled_downtime **)p2;
01011         return (d1->start_time < d2->start_time) ? -1 : (d1->start_time - d2->start_time);
01012         }
01013 
01014 int sort_downtime(void){
01015         scheduled_downtime **array, *temp_downtime;
01016         unsigned long i=0, unsorted_downtimes=0;
01017 
01018         if(!defer_downtime_sorting)
01019                 return OK;
01020         defer_downtime_sorting=0;
01021 
01022         temp_downtime = scheduled_downtime_list;
01023         while(temp_downtime!=NULL) {
01024                 temp_downtime = temp_downtime->next;
01025                 unsorted_downtimes++;
01026                 }
01027 
01028         if(!unsorted_downtimes)
01029                 return OK;
01030 
01031         if(!(array=malloc(sizeof(*array)*unsorted_downtimes)))
01032                 return ERROR;
01033         while(scheduled_downtime_list){
01034                 array[i++]=scheduled_downtime_list;
01035                 scheduled_downtime_list=scheduled_downtime_list->next;
01036         }
01037 
01038         qsort((void *)array, i, sizeof(*array), downtime_compar);
01039         scheduled_downtime_list = temp_downtime = array[0];
01040         for (i=1; i<unsorted_downtimes;i++){
01041                 temp_downtime->next = array[i];
01042                 temp_downtime = temp_downtime->next;
01043                 }
01044         temp_downtime->next = NULL;
01045         my_free(array);
01046         return OK;
01047         }
01048 
01049 
01050 
01051 /******************************************************************/
01052 /************************ SEARCH FUNCTIONS ************************/
01053 /******************************************************************/
01054 
01055 /* finds a specific downtime entry */
01056 scheduled_downtime *find_downtime(int type, unsigned long downtime_id){
01057         scheduled_downtime *temp_downtime=NULL;
01058 
01059         for(temp_downtime=scheduled_downtime_list;temp_downtime!=NULL;temp_downtime=temp_downtime->next){
01060                 if(type!=ANY_DOWNTIME && temp_downtime->type!=type)
01061                         continue;
01062                 if(temp_downtime->downtime_id==downtime_id)
01063                         return temp_downtime;
01064                 }
01065 
01066         return NULL;
01067         }
01068 
01069 
01070 /* finds a specific host downtime entry */
01071 scheduled_downtime *find_host_downtime(unsigned long downtime_id){
01072 
01073         return find_downtime(HOST_DOWNTIME,downtime_id);
01074         }
01075 
01076 
01077 /* finds a specific service downtime entry */
01078 scheduled_downtime *find_service_downtime(unsigned long downtime_id){
01079 
01080         return find_downtime(SERVICE_DOWNTIME,downtime_id);
01081         }
01082 
01083 
01084 /* finds a specific downtime entry by similar content (in a distributed environment, downtime_ids are not synchronised) */
01085 scheduled_downtime *find_downtime_by_similar_content(int type, char *host_name, char *service_description, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long duration){
01086         scheduled_downtime *temp_downtime=NULL;
01087 
01088         if(service_description==NULL) {
01089                 if(type==ANY_DOWNTIME)
01090                         type=HOST_DOWNTIME;
01091 
01092                 /* Must specify a service_description if you are searching services - obviously! */
01093                 if(type==SERVICE_DOWNTIME)
01094                         return NULL;
01095                 }
01096 
01097         for(temp_downtime=scheduled_downtime_list;temp_downtime!=NULL;temp_downtime=temp_downtime->next){
01098                 
01099                 if(type!=ANY_DOWNTIME && temp_downtime->type!=type)
01100                         continue;
01101 
01102                 if(temp_downtime->start_time==start_time 
01103                         && temp_downtime->end_time==end_time 
01104                         && temp_downtime->fixed==fixed
01105                         && temp_downtime->duration==duration
01106                         && strcmp(temp_downtime->host_name,host_name)==0 
01107                         && (service_description==NULL || (temp_downtime->type == SERVICE_DOWNTIME && strcmp(temp_downtime->service_description,service_description)==0)) 
01108                         && strcmp(temp_downtime->author,author)==0 
01109                         && strcmp(temp_downtime->comment,comment_data)==0)
01110                         return temp_downtime;
01111                         }
01112 
01113         return NULL;
01114         }
01115 
01116 
01117 /******************************************************************/
01118 /********************* CLEANUP FUNCTIONS **************************/
01119 /******************************************************************/
01120 
01121 /* frees memory allocated for the scheduled downtime data */
01122 void free_downtime_data(void){
01123         scheduled_downtime *this_downtime=NULL;
01124         scheduled_downtime *next_downtime=NULL;
01125 
01126         /* free memory for the scheduled_downtime list */
01127         for(this_downtime=scheduled_downtime_list;this_downtime!=NULL;this_downtime=next_downtime){
01128                 next_downtime=this_downtime->next;
01129                 my_free(this_downtime->host_name);
01130                 my_free(this_downtime->service_description);
01131                 my_free(this_downtime->author);
01132                 my_free(this_downtime->comment);
01133                 my_free(this_downtime);
01134                 }
01135 
01136         /* reset list pointer */
01137         scheduled_downtime_list=NULL;
01138 
01139         return;
01140         }
 All Data Structures Files Functions Variables Typedefs Defines