66
65
/* initialize downtime data */
67
int xdddefault_initialize_downtime_data(char *main_config_file){
68
scheduled_downtime *temp_downtime=NULL;
66
int xdddefault_initialize_downtime_data(char *main_config_file) {
67
scheduled_downtime *temp_downtime = NULL;
70
69
/* clean up the old downtime data */
71
70
xdddefault_validate_downtime_data();
73
72
/* find the new starting index for downtime id if its missing*/
74
if(next_downtime_id==0L){
75
for(temp_downtime=scheduled_downtime_list;temp_downtime!=NULL;temp_downtime=temp_downtime->next){
76
if(temp_downtime->downtime_id>=next_downtime_id)
77
next_downtime_id=temp_downtime->downtime_id+1;
73
if(next_downtime_id == 0L) {
74
for(temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
75
if(temp_downtime->downtime_id >= next_downtime_id)
76
next_downtime_id = temp_downtime->downtime_id + 1;
81
80
/* initialize next downtime id if necessary */
82
if(next_downtime_id==0L)
81
if(next_downtime_id == 0L)
90
89
/* removes invalid and old downtime entries from the downtime file */
91
int xdddefault_validate_downtime_data(void){
90
int xdddefault_validate_downtime_data(void) {
92
91
scheduled_downtime *temp_downtime;
93
92
scheduled_downtime *next_downtime;
94
int update_file=FALSE;
93
int update_file = FALSE;
97
96
/* remove stale downtimes */
98
for(temp_downtime=scheduled_downtime_list;temp_downtime!=NULL;temp_downtime=next_downtime){
97
for(temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = next_downtime) {
100
next_downtime=temp_downtime->next;
99
next_downtime = temp_downtime->next;
103
102
/* delete downtimes with invalid host names */
104
if(find_host(temp_downtime->host_name)==NULL)
103
if(find_host(temp_downtime->host_name) == NULL)
107
106
/* delete downtimes with invalid service descriptions */
108
if(temp_downtime->type==SERVICE_DOWNTIME && find_service(temp_downtime->host_name,temp_downtime->service_description)==NULL)
107
if(temp_downtime->type == SERVICE_DOWNTIME && find_service(temp_downtime->host_name, temp_downtime->service_description) == NULL)
111
110
/* delete downtimes that have expired */
112
if(temp_downtime->end_time<time(NULL))
111
if(temp_downtime->end_time < time(NULL))
115
114
/* delete the downtime */
118
delete_downtime(temp_downtime->type,temp_downtime->downtime_id);
117
delete_downtime(temp_downtime->type, temp_downtime->downtime_id);
122
121
/* remove triggered downtimes without valid parents */
123
for(temp_downtime=scheduled_downtime_list;temp_downtime!=NULL;temp_downtime=next_downtime){
125
next_downtime=temp_downtime->next;
128
if(temp_downtime->triggered_by==0)
122
for(temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = next_downtime) {
124
next_downtime = temp_downtime->next;
127
if(temp_downtime->triggered_by == 0)
131
if(find_host_downtime(temp_downtime->triggered_by)==NULL && find_service_downtime(temp_downtime->triggered_by)==NULL)
130
if(find_host_downtime(temp_downtime->triggered_by) == NULL && find_service_downtime(temp_downtime->triggered_by) == NULL)
134
133
/* delete the downtime */
137
delete_downtime(temp_downtime->type,temp_downtime->downtime_id);
136
delete_downtime(temp_downtime->type, temp_downtime->downtime_id);
141
140
/* update downtime file */
142
if(update_file==TRUE)
141
if(update_file == TRUE)
143
142
xdddefault_save_downtime_data();
150
149
/* removes invalid and old downtime entries from the downtime file */
151
int xdddefault_cleanup_downtime_data(char *main_config_file){
150
int xdddefault_cleanup_downtime_data(char *main_config_file) {
153
152
/* we don't need to do any cleanup... */
161
160
/******************************************************************/
163
162
/* adds a new scheduled host downtime entry */
164
int xdddefault_add_new_host_downtime(char *host_name, time_t entry_time, char *author, char *comment, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *downtime_id){
163
int xdddefault_add_new_host_downtime(char *host_name, time_t entry_time, char *author, char *comment, 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){
166
165
/* find the next valid downtime id */
167
while(find_host_downtime(next_downtime_id)!=NULL)
166
while(find_host_downtime(next_downtime_id) != NULL)
168
167
next_downtime_id++;
170
169
/* add downtime to list in memory */
171
add_host_downtime(host_name,entry_time,author,comment,start_time,end_time,fixed,triggered_by,duration,next_downtime_id);
170
add_host_downtime(host_name, entry_time, author, comment, start_time, end_time, fixed, triggered_by, duration, next_downtime_id, is_in_effect);
173
172
/* update downtime file */
174
173
xdddefault_save_downtime_data();
176
175
/* return the id for the downtime we are about to add (this happens in the main code) */
177
if(downtime_id!=NULL)
178
*downtime_id=next_downtime_id;
176
if(downtime_id != NULL)
177
*downtime_id = next_downtime_id;
180
179
/* increment the downtime id */
181
180
next_downtime_id++;
188
187
/* adds a new scheduled service downtime entry */
189
int xdddefault_add_new_service_downtime(char *host_name, char *service_description, time_t entry_time, char *author, char *comment, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *downtime_id){
188
int xdddefault_add_new_service_downtime(char *host_name, char *service_description, time_t entry_time, char *author, char *comment, 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){
191
190
/* find the next valid downtime id */
192
while(find_service_downtime(next_downtime_id)!=NULL)
191
while(find_service_downtime(next_downtime_id) != NULL)
193
192
next_downtime_id++;
195
194
/* add downtime to list in memory */
196
add_service_downtime(host_name,service_description,entry_time,author,comment,start_time,end_time,fixed,triggered_by,duration,next_downtime_id);
195
add_service_downtime(host_name, service_description, entry_time, author, comment, start_time, end_time, fixed, triggered_by, duration, next_downtime_id, is_in_effect);
198
197
/* update downtime file */
199
198
xdddefault_save_downtime_data();
201
200
/* return the id for the downtime we are about to add (this happens in the main code) */
202
if(downtime_id!=NULL)
203
*downtime_id=next_downtime_id;
201
if(downtime_id != NULL)
202
*downtime_id = next_downtime_id;
205
204
/* increment the downtime id */
206
205
next_downtime_id++;
212
211
/******************************************************************/
214
213
/******************************************************************/
216
215
/* deletes a scheduled host downtime entry */
217
int xdddefault_delete_host_downtime(unsigned long downtime_id){
216
int xdddefault_delete_host_downtime(unsigned long downtime_id) {
220
result=xdddefault_delete_downtime(HOST_DOWNTIME,downtime_id);
219
result = xdddefault_delete_downtime(HOST_DOWNTIME, downtime_id);
226
225
/* deletes a scheduled service downtime entry */
227
int xdddefault_delete_service_downtime(unsigned long downtime_id){
226
int xdddefault_delete_service_downtime(unsigned long downtime_id) {
230
result=xdddefault_delete_downtime(SERVICE_DOWNTIME,downtime_id);
229
result = xdddefault_delete_downtime(SERVICE_DOWNTIME, downtime_id);
236
235
/* deletes a scheduled host or service downtime entry */
237
int xdddefault_delete_downtime(int type, unsigned long downtime_id){
236
int xdddefault_delete_downtime(int type, unsigned long downtime_id) {
239
238
/* rewrite the downtime file (downtime was already removed from memory) */
240
239
xdddefault_save_downtime_data();