if(start_time>=end_time || end_time<=time(NULL))
return ERROR;
/* add a new downtime entry */
add_new_downtime(type,host_name,service_description,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&downtime_id);
/* register the scheduled downtime */
register_downtime(type,downtime_id);
/* return downtime id */
if(new_downtime_id!=NULL)
*new_downtime_id=downtime_id;
return OK;
}
/* unschedules a host or service downtime */
int unschedule_downtime(int type,unsigned long downtime_id){
scheduled_downtime *temp_downtime;
host *hst=NULL;
service *svc=NULL;
timed_event *temp_event;
char temp_buffer[MAX_INPUT_BUFFER];
#ifdef USE_EVENT_BROKER
int attr;
#endif
/* find the downtime entry in the list in memory */
temp_downtime=find_downtime(type,downtime_id);
if(temp_downtime==NULL)
return ERROR;
/* find the host or service associated with this downtime */
if(temp_downtime->type==HOST_DOWNTIME){
hst=find_host(temp_downtime->host_name);
if(hst==NULL)
return ERROR;
}
else{
svc=find_service(temp_downtime->host_name,temp_downtime->service_description);
if(svc==NULL)
return ERROR;
}
/* decrement pending flex downtime if necessary ... */
if(temp_downtime->fixed==FALSE && temp_downtime->incremented_pending_downtime==TRUE){
if(temp_downtime->type==HOST_DOWNTIME)
hst->pending_flex_downtime--;
else
svc->pending_flex_downtime--;
}
/* decrement the downtime depth variable and update status data if necessary */
if(temp_downtime->is_in_effect==TRUE){
#ifdef USE_EVENT_BROKER
/* send data to event broker */
attr=NEBATTR_DOWNTIME_STOP_CANCELLED;
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);
#endif
if(temp_downtime->type==HOST_DOWNTIME){
hst->scheduled_downtime_depth--;
update_host_status(hst,FALSE);
/* log a notice - this is parsed by the history CGI */
if(hst->scheduled_downtime_depth==0){
snprintf(temp_buffer,sizeof(temp_buffer),"HOST DOWNTIME ALERT: %s;CANCELLED; Scheduled downtime for host has been
cancelled.\n",hst->name);
temp_buffer[sizeof(temp_buffer)-1]='\x0';
write_to_all_logs(temp_buffer,NSLOG_INFO_MESSAGE);
}
}
else{
svc->scheduled_downtime_depth--;
update_service_status(svc,FALSE);
/* log a notice - this is parsed by the history CGI */
if(svc->scheduled_downtime_depth==0){
snprintf(temp_buffer,sizeof(temp_buffer),"SERVICE DOWNTIME ALERT: %s;%s;CANCELLED; Scheduled downtime for service has
been cancelled.\n",svc->host_name,svc->description);
temp_buffer[sizeof(temp_buffer)-1]='\x0';
write_to_all_logs(temp_buffer,NSLOG_INFO_MESSAGE);
}
}
}
/* remove scheduled entry from event queue */
for(temp_event=event_list_high;temp_event!=NULL;temp_event=temp_event->next){
if(temp_event->event_type!=EVENT_SCHEDULED_DOWNTIME)
continue;
if(((unsigned long)temp_event->event_data)==downtime_id)
break;
}
if(temp_event!=NULL)
remove_event(temp_event,&event_list_high);
=2= |