~yolanda.robla/ubuntu/saucy/nagios3/dep-8-tests

« back to all changes in this revision

Viewing changes to base/commands.c

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
extern FILE     *command_file_fp;
81
81
extern int      command_file_fd;
82
82
 
83
 
passive_check_result    *passive_check_result_list=NULL;
84
 
passive_check_result    *passive_check_result_list_tail=NULL;
 
83
passive_check_result    *passive_check_result_list = NULL;
 
84
passive_check_result    *passive_check_result_list_tail = NULL;
85
85
 
86
86
extern pthread_t       worker_threads[TOTAL_WORKER_THREADS];
87
87
extern circular_buffer external_command_buffer;
95
95
 
96
96
 
97
97
/* checks for the existence of the external command file and processes all commands found in it */
98
 
int check_for_external_commands(void){
99
 
        char *buffer=NULL;
100
 
        int update_status=FALSE;
 
98
int check_for_external_commands(void) {
 
99
        char *buffer = NULL;
 
100
        int update_status = FALSE;
101
101
 
102
 
        log_debug_info(DEBUGL_FUNCTIONS,0,"check_for_external_commands()\n");
 
102
        log_debug_info(DEBUGL_FUNCTIONS, 0, "check_for_external_commands()\n");
103
103
 
104
104
        /* bail out if we shouldn't be checking for external commands */
105
 
        if(check_external_commands==FALSE)
 
105
        if(check_external_commands == FALSE)
106
106
                return ERROR;
107
107
 
108
108
        /* update last command check time */
109
 
        last_command_check=time(NULL);
 
109
        last_command_check = time(NULL);
110
110
 
111
111
        /* update the status log with new program information */
112
112
        /* go easy on the frequency of this if we're checking often - only update program status every 10 seconds.... */
113
 
        if(last_command_check<(last_command_status_update+10))
114
 
                update_status=FALSE;
 
113
        if(last_command_check < (last_command_status_update + 10))
 
114
                update_status = FALSE;
115
115
        else
116
 
                update_status=TRUE;
117
 
        if(update_status==TRUE){
118
 
                last_command_status_update=last_command_check;
 
116
                update_status = TRUE;
 
117
        if(update_status == TRUE) {
 
118
                last_command_status_update = last_command_check;
119
119
                update_program_status(FALSE);
120
 
                }
 
120
                }
121
121
 
122
122
        /* reset passive check result list pointers */
123
 
        passive_check_result_list=NULL;
124
 
        passive_check_result_list_tail=NULL;
 
123
        passive_check_result_list = NULL;
 
124
        passive_check_result_list_tail = NULL;
125
125
 
126
126
        /* process all commands found in the buffer */
127
 
        while(1){
 
127
        while(1) {
128
128
 
129
129
                /* get a lock on the buffer */
130
130
                pthread_mutex_lock(&external_command_buffer.buffer_lock);
131
131
 
132
132
                /* if no items present, bail out */
133
 
                if(external_command_buffer.items<=0){
 
133
                if(external_command_buffer.items <= 0) {
134
134
                        pthread_mutex_unlock(&external_command_buffer.buffer_lock);
135
135
                        break;
136
 
                        }
 
136
                        }
137
137
 
138
138
                if(external_command_buffer.buffer[external_command_buffer.tail])
139
 
                        buffer=strdup(((char **)external_command_buffer.buffer)[external_command_buffer.tail]);
 
139
                        buffer = strdup(((char **)external_command_buffer.buffer)[external_command_buffer.tail]);
140
140
 
141
141
                /* free memory allocated for buffer slot */
142
142
                my_free(((char **)external_command_buffer.buffer)[external_command_buffer.tail]);
143
143
 
144
144
                /* adjust tail counter and number of items */
145
 
                external_command_buffer.tail=(external_command_buffer.tail + 1) % external_command_buffer_slots;
 
145
                external_command_buffer.tail = (external_command_buffer.tail + 1) % external_command_buffer_slots;
146
146
                external_command_buffer.items--;
147
147
 
148
148
                /* release the lock on the buffer */
153
153
 
154
154
                /* free memory */
155
155
                my_free(buffer);
156
 
                }
 
156
                }
157
157
 
158
158
        /**** PROCESS ALL PASSIVE HOST AND SERVICE CHECK RESULTS AT ONE TIME ****/
159
 
        if(passive_check_result_list!=NULL)
 
159
        if(passive_check_result_list != NULL)
160
160
                process_passive_checks();
161
161
 
162
162
        return OK;
163
 
        }
 
163
        }
164
164
 
165
165
 
166
166
 
167
167
/* processes all external commands in a (regular) file */
168
 
int process_external_commands_from_file(char *fname, int delete_file){
169
 
        mmapfile *thefile=NULL;
170
 
        char *input=NULL;
171
 
 
172
 
 
173
 
        log_debug_info(DEBUGL_FUNCTIONS,0,"process_external_commands_from_file()\n");
174
 
 
175
 
        if(fname==NULL)
 
168
int process_external_commands_from_file(char *fname, int delete_file) {
 
169
        mmapfile *thefile = NULL;
 
170
        char *input = NULL;
 
171
 
 
172
 
 
173
        log_debug_info(DEBUGL_FUNCTIONS, 0, "process_external_commands_from_file()\n");
 
174
 
 
175
        if(fname == NULL)
176
176
                return ERROR;
177
177
 
178
 
        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");
 
178
        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");
179
179
 
180
180
        /* open the config file for reading */
181
 
        if((thefile=mmap_fopen(fname))==NULL){
182
 
                logit(NSLOG_INFO_MESSAGE,FALSE,"Error: Cannot open file '%s' to process external commands!",fname);
 
181
        if((thefile = mmap_fopen(fname)) == NULL) {
 
182
                logit(NSLOG_INFO_MESSAGE, FALSE, "Error: Cannot open file '%s' to process external commands!", fname);
183
183
                return ERROR;
184
184
                }
185
185
 
186
186
        /* process all commands in the file */
187
 
        while(1){
 
187
        while(1) {
188
188
 
189
189
                /* free memory */
190
190
                my_free(input);
191
191
 
192
192
                /* read the next line */
193
 
                if((input=mmap_fgets(thefile))==NULL)
 
193
                if((input = mmap_fgets(thefile)) == NULL)
194
194
                        break;
195
195
 
196
196
                /* process the command */
197
197
                process_external_command1(input);
198
 
                }
 
198
                }
199
199
 
200
200
        /* close the file */
201
201
        mmap_fclose(thefile);
202
202
 
203
203
        /* delete the file */
204
 
        if(delete_file==TRUE)
 
204
        if(delete_file == TRUE)
205
205
                unlink(fname);
206
206
 
207
207
        return OK;
208
 
        }
 
208
        }
209
209
 
210
210
 
211
211
 
212
212
/* top-level external command processor */
213
 
int process_external_command1(char *cmd){
214
 
        char *temp_buffer=NULL;
215
 
        char *command_id=NULL;
216
 
        char *args=NULL;
217
 
        time_t entry_time=0L;
218
 
        int command_type=CMD_NONE;
219
 
        char *temp_ptr=NULL;
220
 
 
221
 
        log_debug_info(DEBUGL_FUNCTIONS,0,"process_external_command1()\n");
222
 
 
223
 
        if(cmd==NULL)
 
213
int process_external_command1(char *cmd) {
 
214
        char *temp_buffer = NULL;
 
215
        char *command_id = NULL;
 
216
        char *args = NULL;
 
217
        time_t entry_time = 0L;
 
218
        int command_type = CMD_NONE;
 
219
        char *temp_ptr = NULL;
 
220
 
 
221
        log_debug_info(DEBUGL_FUNCTIONS, 0, "process_external_command1()\n");
 
222
 
 
223
        if(cmd == NULL)
224
224
                return ERROR;
225
225
 
226
226
        /* strip the command of newlines and carriage returns */
227
227
        strip(cmd);
228
228
 
229
 
        log_debug_info(DEBUGL_EXTERNALCOMMANDS,2,"Raw command entry: %s\n",cmd);
 
229
        log_debug_info(DEBUGL_EXTERNALCOMMANDS, 2, "Raw command entry: %s\n", cmd);
230
230
 
231
231
        /* get the command entry time */
232
 
        if((temp_ptr=my_strtok(cmd,"["))==NULL)
233
 
                return ERROR;
234
 
        if((temp_ptr=my_strtok(NULL,"]"))==NULL)
235
 
                return ERROR;
236
 
        entry_time=(time_t)strtoul(temp_ptr,NULL,10);
 
232
        if((temp_ptr = my_strtok(cmd, "[")) == NULL)
 
233
                return ERROR;
 
234
        if((temp_ptr = my_strtok(NULL, "]")) == NULL)
 
235
                return ERROR;
 
236
        entry_time = (time_t)strtoul(temp_ptr, NULL, 10);
237
237
 
238
238
        /* get the command identifier */
239
 
        if((temp_ptr=my_strtok(NULL,";"))==NULL)
 
239
        if((temp_ptr = my_strtok(NULL, ";")) == NULL)
240
240
                return ERROR;
241
 
        if((command_id=(char *)strdup(temp_ptr+1))==NULL)
 
241
        if((command_id = (char *)strdup(temp_ptr + 1)) == NULL)
242
242
                return ERROR;
243
243
 
244
244
        /* get the command arguments */
245
 
        if((temp_ptr=my_strtok(NULL,"\n"))==NULL)
246
 
                args=(char *)strdup("");
 
245
        if((temp_ptr = my_strtok(NULL, "\n")) == NULL)
 
246
                args = (char *)strdup("");
247
247
        else
248
 
                args=(char *)strdup(temp_ptr);
249
 
        if(args==NULL){
 
248
                args = (char *)strdup(temp_ptr);
 
249
        if(args == NULL) {
250
250
                my_free(command_id);
251
251
                return ERROR;
252
 
                }
 
252
                }
253
253
 
254
254
        /* decide what type of command this is... */
255
255
 
256
256
        /**************************/
257
257
        /**** PROCESS COMMANDS ****/
258
258
        /**************************/
259
 
        
260
 
        if(!strcmp(command_id,"ENTER_STANDBY_MODE") || !strcmp(command_id,"DISABLE_NOTIFICATIONS"))
261
 
                command_type=CMD_DISABLE_NOTIFICATIONS;
262
 
        else if(!strcmp(command_id,"ENTER_ACTIVE_MODE") || !strcmp(command_id,"ENABLE_NOTIFICATIONS"))
263
 
                command_type=CMD_ENABLE_NOTIFICATIONS;
264
 
 
265
 
        else if(!strcmp(command_id,"SHUTDOWN_PROGRAM") || !strcmp(command_id,"SHUTDOWN_PROCESS"))
266
 
                command_type=CMD_SHUTDOWN_PROCESS;
267
 
        else if(!strcmp(command_id,"RESTART_PROGRAM") || !strcmp(command_id,"RESTART_PROCESS"))
268
 
                command_type=CMD_RESTART_PROCESS;
269
 
 
270
 
        else if(!strcmp(command_id,"SAVE_STATE_INFORMATION"))
271
 
                command_type=CMD_SAVE_STATE_INFORMATION;
272
 
        else if(!strcmp(command_id,"READ_STATE_INFORMATION"))
273
 
                command_type=CMD_READ_STATE_INFORMATION;
274
 
 
275
 
        else if(!strcmp(command_id,"ENABLE_EVENT_HANDLERS"))
276
 
                command_type=CMD_ENABLE_EVENT_HANDLERS;
277
 
        else if(!strcmp(command_id,"DISABLE_EVENT_HANDLERS"))
278
 
                command_type=CMD_DISABLE_EVENT_HANDLERS;
279
 
 
280
 
        else if(!strcmp(command_id,"FLUSH_PENDING_COMMANDS"))
281
 
                command_type=CMD_FLUSH_PENDING_COMMANDS;
282
 
 
283
 
        else if(!strcmp(command_id,"ENABLE_FAILURE_PREDICTION"))
284
 
                command_type=CMD_ENABLE_FAILURE_PREDICTION;
285
 
        else if(!strcmp(command_id,"DISABLE_FAILURE_PREDICTION"))
286
 
                command_type=CMD_DISABLE_FAILURE_PREDICTION;
287
 
 
288
 
        else if(!strcmp(command_id,"ENABLE_PERFORMANCE_DATA"))
289
 
                command_type=CMD_ENABLE_PERFORMANCE_DATA;
290
 
        else if(!strcmp(command_id,"DISABLE_PERFORMANCE_DATA"))
291
 
                command_type=CMD_DISABLE_PERFORMANCE_DATA;
292
 
 
293
 
        else if(!strcmp(command_id,"START_EXECUTING_HOST_CHECKS"))
294
 
                command_type=CMD_START_EXECUTING_HOST_CHECKS;
295
 
        else if(!strcmp(command_id,"STOP_EXECUTING_HOST_CHECKS"))
296
 
                command_type=CMD_STOP_EXECUTING_HOST_CHECKS;
297
 
 
298
 
        else if(!strcmp(command_id,"START_EXECUTING_SVC_CHECKS"))
299
 
                command_type=CMD_START_EXECUTING_SVC_CHECKS;
300
 
        else if(!strcmp(command_id,"STOP_EXECUTING_SVC_CHECKS"))
301
 
                command_type=CMD_STOP_EXECUTING_SVC_CHECKS;
302
 
 
303
 
        else if(!strcmp(command_id,"START_ACCEPTING_PASSIVE_HOST_CHECKS"))
304
 
                command_type=CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS;
305
 
        else if(!strcmp(command_id,"STOP_ACCEPTING_PASSIVE_HOST_CHECKS"))
306
 
                command_type=CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS;
307
 
 
308
 
        else if(!strcmp(command_id,"START_ACCEPTING_PASSIVE_SVC_CHECKS"))
309
 
                command_type=CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS;
310
 
        else if(!strcmp(command_id,"STOP_ACCEPTING_PASSIVE_SVC_CHECKS"))
311
 
                command_type=CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS;
312
 
 
313
 
        else if(!strcmp(command_id,"START_OBSESSING_OVER_HOST_CHECKS"))
314
 
                command_type=CMD_START_OBSESSING_OVER_HOST_CHECKS;
315
 
        else if(!strcmp(command_id,"STOP_OBSESSING_OVER_HOST_CHECKS"))
316
 
                command_type=CMD_STOP_OBSESSING_OVER_HOST_CHECKS;
317
 
 
318
 
        else if(!strcmp(command_id,"START_OBSESSING_OVER_SVC_CHECKS"))
319
 
                command_type=CMD_START_OBSESSING_OVER_SVC_CHECKS;
320
 
        else if(!strcmp(command_id,"STOP_OBSESSING_OVER_SVC_CHECKS"))
321
 
                command_type=CMD_STOP_OBSESSING_OVER_SVC_CHECKS;
322
 
 
323
 
        else if(!strcmp(command_id,"ENABLE_FLAP_DETECTION"))
324
 
                command_type=CMD_ENABLE_FLAP_DETECTION;
325
 
        else if(!strcmp(command_id,"DISABLE_FLAP_DETECTION"))
326
 
                command_type=CMD_DISABLE_FLAP_DETECTION;
327
 
 
328
 
        else if(!strcmp(command_id,"CHANGE_GLOBAL_HOST_EVENT_HANDLER"))
329
 
                command_type=CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER;
330
 
        else if(!strcmp(command_id,"CHANGE_GLOBAL_SVC_EVENT_HANDLER"))
331
 
                command_type=CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER;
332
 
 
333
 
        else if(!strcmp(command_id,"ENABLE_SERVICE_FRESHNESS_CHECKS"))
334
 
                command_type=CMD_ENABLE_SERVICE_FRESHNESS_CHECKS;
335
 
        else if(!strcmp(command_id,"DISABLE_SERVICE_FRESHNESS_CHECKS"))
336
 
                command_type=CMD_DISABLE_SERVICE_FRESHNESS_CHECKS;
337
 
 
338
 
        else if(!strcmp(command_id,"ENABLE_HOST_FRESHNESS_CHECKS"))
339
 
                command_type=CMD_ENABLE_HOST_FRESHNESS_CHECKS;
340
 
        else if(!strcmp(command_id,"DISABLE_HOST_FRESHNESS_CHECKS"))
341
 
                command_type=CMD_DISABLE_HOST_FRESHNESS_CHECKS;
 
259
 
 
260
        if(!strcmp(command_id, "ENTER_STANDBY_MODE") || !strcmp(command_id, "DISABLE_NOTIFICATIONS"))
 
261
                command_type = CMD_DISABLE_NOTIFICATIONS;
 
262
        else if(!strcmp(command_id, "ENTER_ACTIVE_MODE") || !strcmp(command_id, "ENABLE_NOTIFICATIONS"))
 
263
                command_type = CMD_ENABLE_NOTIFICATIONS;
 
264
 
 
265
        else if(!strcmp(command_id, "SHUTDOWN_PROGRAM") || !strcmp(command_id, "SHUTDOWN_PROCESS"))
 
266
                command_type = CMD_SHUTDOWN_PROCESS;
 
267
        else if(!strcmp(command_id, "RESTART_PROGRAM") || !strcmp(command_id, "RESTART_PROCESS"))
 
268
                command_type = CMD_RESTART_PROCESS;
 
269
 
 
270
        else if(!strcmp(command_id, "SAVE_STATE_INFORMATION"))
 
271
                command_type = CMD_SAVE_STATE_INFORMATION;
 
272
        else if(!strcmp(command_id, "READ_STATE_INFORMATION"))
 
273
                command_type = CMD_READ_STATE_INFORMATION;
 
274
 
 
275
        else if(!strcmp(command_id, "ENABLE_EVENT_HANDLERS"))
 
276
                command_type = CMD_ENABLE_EVENT_HANDLERS;
 
277
        else if(!strcmp(command_id, "DISABLE_EVENT_HANDLERS"))
 
278
                command_type = CMD_DISABLE_EVENT_HANDLERS;
 
279
 
 
280
        else if(!strcmp(command_id, "FLUSH_PENDING_COMMANDS"))
 
281
                command_type = CMD_FLUSH_PENDING_COMMANDS;
 
282
 
 
283
        else if(!strcmp(command_id, "ENABLE_FAILURE_PREDICTION"))
 
284
                command_type = CMD_ENABLE_FAILURE_PREDICTION;
 
285
        else if(!strcmp(command_id, "DISABLE_FAILURE_PREDICTION"))
 
286
                command_type = CMD_DISABLE_FAILURE_PREDICTION;
 
287
 
 
288
        else if(!strcmp(command_id, "ENABLE_PERFORMANCE_DATA"))
 
289
                command_type = CMD_ENABLE_PERFORMANCE_DATA;
 
290
        else if(!strcmp(command_id, "DISABLE_PERFORMANCE_DATA"))
 
291
                command_type = CMD_DISABLE_PERFORMANCE_DATA;
 
292
 
 
293
        else if(!strcmp(command_id, "START_EXECUTING_HOST_CHECKS"))
 
294
                command_type = CMD_START_EXECUTING_HOST_CHECKS;
 
295
        else if(!strcmp(command_id, "STOP_EXECUTING_HOST_CHECKS"))
 
296
                command_type = CMD_STOP_EXECUTING_HOST_CHECKS;
 
297
 
 
298
        else if(!strcmp(command_id, "START_EXECUTING_SVC_CHECKS"))
 
299
                command_type = CMD_START_EXECUTING_SVC_CHECKS;
 
300
        else if(!strcmp(command_id, "STOP_EXECUTING_SVC_CHECKS"))
 
301
                command_type = CMD_STOP_EXECUTING_SVC_CHECKS;
 
302
 
 
303
        else if(!strcmp(command_id, "START_ACCEPTING_PASSIVE_HOST_CHECKS"))
 
304
                command_type = CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS;
 
305
        else if(!strcmp(command_id, "STOP_ACCEPTING_PASSIVE_HOST_CHECKS"))
 
306
                command_type = CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS;
 
307
 
 
308
        else if(!strcmp(command_id, "START_ACCEPTING_PASSIVE_SVC_CHECKS"))
 
309
                command_type = CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS;
 
310
        else if(!strcmp(command_id, "STOP_ACCEPTING_PASSIVE_SVC_CHECKS"))
 
311
                command_type = CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS;
 
312
 
 
313
        else if(!strcmp(command_id, "START_OBSESSING_OVER_HOST_CHECKS"))
 
314
                command_type = CMD_START_OBSESSING_OVER_HOST_CHECKS;
 
315
        else if(!strcmp(command_id, "STOP_OBSESSING_OVER_HOST_CHECKS"))
 
316
                command_type = CMD_STOP_OBSESSING_OVER_HOST_CHECKS;
 
317
 
 
318
        else if(!strcmp(command_id, "START_OBSESSING_OVER_SVC_CHECKS"))
 
319
                command_type = CMD_START_OBSESSING_OVER_SVC_CHECKS;
 
320
        else if(!strcmp(command_id, "STOP_OBSESSING_OVER_SVC_CHECKS"))
 
321
                command_type = CMD_STOP_OBSESSING_OVER_SVC_CHECKS;
 
322
 
 
323
        else if(!strcmp(command_id, "ENABLE_FLAP_DETECTION"))
 
324
                command_type = CMD_ENABLE_FLAP_DETECTION;
 
325
        else if(!strcmp(command_id, "DISABLE_FLAP_DETECTION"))
 
326
                command_type = CMD_DISABLE_FLAP_DETECTION;
 
327
 
 
328
        else if(!strcmp(command_id, "CHANGE_GLOBAL_HOST_EVENT_HANDLER"))
 
329
                command_type = CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER;
 
330
        else if(!strcmp(command_id, "CHANGE_GLOBAL_SVC_EVENT_HANDLER"))
 
331
                command_type = CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER;
 
332
 
 
333
        else if(!strcmp(command_id, "ENABLE_SERVICE_FRESHNESS_CHECKS"))
 
334
                command_type = CMD_ENABLE_SERVICE_FRESHNESS_CHECKS;
 
335
        else if(!strcmp(command_id, "DISABLE_SERVICE_FRESHNESS_CHECKS"))
 
336
                command_type = CMD_DISABLE_SERVICE_FRESHNESS_CHECKS;
 
337
 
 
338
        else if(!strcmp(command_id, "ENABLE_HOST_FRESHNESS_CHECKS"))
 
339
                command_type = CMD_ENABLE_HOST_FRESHNESS_CHECKS;
 
340
        else if(!strcmp(command_id, "DISABLE_HOST_FRESHNESS_CHECKS"))
 
341
                command_type = CMD_DISABLE_HOST_FRESHNESS_CHECKS;
342
342
 
343
343
 
344
344
        /*******************************/
345
345
        /**** HOST-RELATED COMMANDS ****/
346
346
        /*******************************/
347
347
 
348
 
        else if(!strcmp(command_id,"ADD_HOST_COMMENT"))
349
 
                command_type=CMD_ADD_HOST_COMMENT;
350
 
        else if(!strcmp(command_id,"DEL_HOST_COMMENT"))
351
 
                command_type=CMD_DEL_HOST_COMMENT;
352
 
        else if(!strcmp(command_id,"DEL_ALL_HOST_COMMENTS"))
353
 
                command_type=CMD_DEL_ALL_HOST_COMMENTS;
354
 
 
355
 
        else if(!strcmp(command_id,"DELAY_HOST_NOTIFICATION"))
356
 
                command_type=CMD_DELAY_HOST_NOTIFICATION;
357
 
 
358
 
        else if(!strcmp(command_id,"ENABLE_HOST_NOTIFICATIONS"))
359
 
                command_type=CMD_ENABLE_HOST_NOTIFICATIONS;
360
 
        else if(!strcmp(command_id,"DISABLE_HOST_NOTIFICATIONS"))
361
 
                command_type=CMD_DISABLE_HOST_NOTIFICATIONS;
362
 
 
363
 
        else if(!strcmp(command_id,"ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST"))
364
 
                command_type=CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST;
365
 
        else if(!strcmp(command_id,"DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST"))
366
 
                command_type=CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST;
367
 
 
368
 
        else if(!strcmp(command_id,"ENABLE_HOST_AND_CHILD_NOTIFICATIONS"))
369
 
                command_type=CMD_ENABLE_HOST_AND_CHILD_NOTIFICATIONS;
370
 
        else if(!strcmp(command_id,"DISABLE_HOST_AND_CHILD_NOTIFICATIONS"))
371
 
                command_type=CMD_DISABLE_HOST_AND_CHILD_NOTIFICATIONS;
372
 
 
373
 
        else if(!strcmp(command_id,"ENABLE_HOST_SVC_NOTIFICATIONS"))
374
 
                command_type=CMD_ENABLE_HOST_SVC_NOTIFICATIONS;
375
 
        else if(!strcmp(command_id,"DISABLE_HOST_SVC_NOTIFICATIONS"))
376
 
                command_type=CMD_DISABLE_HOST_SVC_NOTIFICATIONS;
377
 
 
378
 
        else if(!strcmp(command_id,"ENABLE_HOST_SVC_CHECKS"))
379
 
                command_type=CMD_ENABLE_HOST_SVC_CHECKS;
380
 
        else if(!strcmp(command_id,"DISABLE_HOST_SVC_CHECKS"))
381
 
                command_type=CMD_DISABLE_HOST_SVC_CHECKS;
382
 
 
383
 
        else if(!strcmp(command_id,"ENABLE_PASSIVE_HOST_CHECKS"))
384
 
                command_type=CMD_ENABLE_PASSIVE_HOST_CHECKS;
385
 
        else if(!strcmp(command_id,"DISABLE_PASSIVE_HOST_CHECKS"))
386
 
                command_type=CMD_DISABLE_PASSIVE_HOST_CHECKS;
387
 
        
388
 
        else if(!strcmp(command_id,"SCHEDULE_HOST_SVC_CHECKS"))
389
 
                command_type=CMD_SCHEDULE_HOST_SVC_CHECKS;
390
 
        else if(!strcmp(command_id,"SCHEDULE_FORCED_HOST_SVC_CHECKS"))
391
 
                command_type=CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS;
392
 
 
393
 
        else if(!strcmp(command_id,"ACKNOWLEDGE_HOST_PROBLEM"))
394
 
                command_type=CMD_ACKNOWLEDGE_HOST_PROBLEM;
395
 
        else if(!strcmp(command_id,"REMOVE_HOST_ACKNOWLEDGEMENT"))
396
 
                command_type=CMD_REMOVE_HOST_ACKNOWLEDGEMENT;
397
 
 
398
 
        else if(!strcmp(command_id,"ENABLE_HOST_EVENT_HANDLER"))
399
 
                command_type=CMD_ENABLE_HOST_EVENT_HANDLER;
400
 
        else if(!strcmp(command_id,"DISABLE_HOST_EVENT_HANDLER"))
401
 
                command_type=CMD_DISABLE_HOST_EVENT_HANDLER;
402
 
 
403
 
        else if(!strcmp(command_id,"ENABLE_HOST_CHECK"))
404
 
                command_type=CMD_ENABLE_HOST_CHECK;
405
 
        else if(!strcmp(command_id,"DISABLE_HOST_CHECK"))
406
 
                command_type=CMD_DISABLE_HOST_CHECK;
407
 
 
408
 
        else if(!strcmp(command_id,"SCHEDULE_HOST_CHECK"))
409
 
                command_type=CMD_SCHEDULE_HOST_CHECK;
410
 
        else if(!strcmp(command_id,"SCHEDULE_FORCED_HOST_CHECK"))
411
 
                command_type=CMD_SCHEDULE_FORCED_HOST_CHECK;
412
 
 
413
 
        else if(!strcmp(command_id,"SCHEDULE_HOST_DOWNTIME"))
414
 
                command_type=CMD_SCHEDULE_HOST_DOWNTIME;
415
 
        else if(!strcmp(command_id,"SCHEDULE_HOST_SVC_DOWNTIME"))
416
 
                command_type=CMD_SCHEDULE_HOST_SVC_DOWNTIME;
417
 
        else if(!strcmp(command_id,"DEL_HOST_DOWNTIME"))
418
 
                command_type=CMD_DEL_HOST_DOWNTIME;
419
 
 
420
 
        else if(!strcmp(command_id,"ENABLE_HOST_FLAP_DETECTION"))
421
 
                command_type=CMD_ENABLE_HOST_FLAP_DETECTION;
422
 
        else if(!strcmp(command_id,"DISABLE_HOST_FLAP_DETECTION"))
423
 
                command_type=CMD_DISABLE_HOST_FLAP_DETECTION;
424
 
 
425
 
        else if(!strcmp(command_id,"START_OBSESSING_OVER_HOST"))
426
 
                command_type=CMD_START_OBSESSING_OVER_HOST;
427
 
        else if(!strcmp(command_id,"STOP_OBSESSING_OVER_HOST"))
428
 
                command_type=CMD_STOP_OBSESSING_OVER_HOST;
429
 
 
430
 
        else if(!strcmp(command_id,"CHANGE_HOST_EVENT_HANDLER"))
431
 
                command_type=CMD_CHANGE_HOST_EVENT_HANDLER;
432
 
        else if(!strcmp(command_id,"CHANGE_HOST_CHECK_COMMAND"))
433
 
                command_type=CMD_CHANGE_HOST_CHECK_COMMAND;
434
 
 
435
 
        else if(!strcmp(command_id,"CHANGE_NORMAL_HOST_CHECK_INTERVAL"))
436
 
                command_type=CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL;
437
 
        else if(!strcmp(command_id,"CHANGE_RETRY_HOST_CHECK_INTERVAL"))
438
 
                command_type=CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL;
439
 
 
440
 
        else if(!strcmp(command_id,"CHANGE_MAX_HOST_CHECK_ATTEMPTS"))
441
 
                command_type=CMD_CHANGE_MAX_HOST_CHECK_ATTEMPTS;
442
 
 
443
 
        else if(!strcmp(command_id,"SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME"))
444
 
                command_type=CMD_SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME;
445
 
 
446
 
        else if(!strcmp(command_id,"SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME"))
447
 
                command_type=CMD_SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME;
448
 
 
449
 
        else if(!strcmp(command_id,"SET_HOST_NOTIFICATION_NUMBER"))
450
 
                command_type=CMD_SET_HOST_NOTIFICATION_NUMBER;
451
 
 
452
 
        else if(!strcmp(command_id,"CHANGE_HOST_CHECK_TIMEPERIOD"))
453
 
                command_type=CMD_CHANGE_HOST_CHECK_TIMEPERIOD;
454
 
 
455
 
        else if (!strcmp(command_id,"CHANGE_CUSTOM_HOST_VAR"))
456
 
                command_type=CMD_CHANGE_CUSTOM_HOST_VAR;
457
 
 
458
 
        else if (!strcmp(command_id,"SEND_CUSTOM_HOST_NOTIFICATION"))
459
 
                command_type=CMD_SEND_CUSTOM_HOST_NOTIFICATION;
460
 
 
461
 
        else if(!strcmp(command_id,"CHANGE_HOST_NOTIFICATION_TIMEPERIOD"))
462
 
                command_type=CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD;
463
 
 
464
 
        else if(!strcmp(command_id,"CHANGE_HOST_MODATTR"))
465
 
                command_type=CMD_CHANGE_HOST_MODATTR;
 
348
        else if(!strcmp(command_id, "ADD_HOST_COMMENT"))
 
349
                command_type = CMD_ADD_HOST_COMMENT;
 
350
        else if(!strcmp(command_id, "DEL_HOST_COMMENT"))
 
351
                command_type = CMD_DEL_HOST_COMMENT;
 
352
        else if(!strcmp(command_id, "DEL_ALL_HOST_COMMENTS"))
 
353
                command_type = CMD_DEL_ALL_HOST_COMMENTS;
 
354
 
 
355
        else if(!strcmp(command_id, "DELAY_HOST_NOTIFICATION"))
 
356
                command_type = CMD_DELAY_HOST_NOTIFICATION;
 
357
 
 
358
        else if(!strcmp(command_id, "ENABLE_HOST_NOTIFICATIONS"))
 
359
                command_type = CMD_ENABLE_HOST_NOTIFICATIONS;
 
360
        else if(!strcmp(command_id, "DISABLE_HOST_NOTIFICATIONS"))
 
361
                command_type = CMD_DISABLE_HOST_NOTIFICATIONS;
 
362
 
 
363
        else if(!strcmp(command_id, "ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST"))
 
364
                command_type = CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST;
 
365
        else if(!strcmp(command_id, "DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST"))
 
366
                command_type = CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST;
 
367
 
 
368
        else if(!strcmp(command_id, "ENABLE_HOST_AND_CHILD_NOTIFICATIONS"))
 
369
                command_type = CMD_ENABLE_HOST_AND_CHILD_NOTIFICATIONS;
 
370
        else if(!strcmp(command_id, "DISABLE_HOST_AND_CHILD_NOTIFICATIONS"))
 
371
                command_type = CMD_DISABLE_HOST_AND_CHILD_NOTIFICATIONS;
 
372
 
 
373
        else if(!strcmp(command_id, "ENABLE_HOST_SVC_NOTIFICATIONS"))
 
374
                command_type = CMD_ENABLE_HOST_SVC_NOTIFICATIONS;
 
375
        else if(!strcmp(command_id, "DISABLE_HOST_SVC_NOTIFICATIONS"))
 
376
                command_type = CMD_DISABLE_HOST_SVC_NOTIFICATIONS;
 
377
 
 
378
        else if(!strcmp(command_id, "ENABLE_HOST_SVC_CHECKS"))
 
379
                command_type = CMD_ENABLE_HOST_SVC_CHECKS;
 
380
        else if(!strcmp(command_id, "DISABLE_HOST_SVC_CHECKS"))
 
381
                command_type = CMD_DISABLE_HOST_SVC_CHECKS;
 
382
 
 
383
        else if(!strcmp(command_id, "ENABLE_PASSIVE_HOST_CHECKS"))
 
384
                command_type = CMD_ENABLE_PASSIVE_HOST_CHECKS;
 
385
        else if(!strcmp(command_id, "DISABLE_PASSIVE_HOST_CHECKS"))
 
386
                command_type = CMD_DISABLE_PASSIVE_HOST_CHECKS;
 
387
 
 
388
        else if(!strcmp(command_id, "SCHEDULE_HOST_SVC_CHECKS"))
 
389
                command_type = CMD_SCHEDULE_HOST_SVC_CHECKS;
 
390
        else if(!strcmp(command_id, "SCHEDULE_FORCED_HOST_SVC_CHECKS"))
 
391
                command_type = CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS;
 
392
 
 
393
        else if(!strcmp(command_id, "ACKNOWLEDGE_HOST_PROBLEM"))
 
394
                command_type = CMD_ACKNOWLEDGE_HOST_PROBLEM;
 
395
        else if(!strcmp(command_id, "REMOVE_HOST_ACKNOWLEDGEMENT"))
 
396
                command_type = CMD_REMOVE_HOST_ACKNOWLEDGEMENT;
 
397
 
 
398
        else if(!strcmp(command_id, "ENABLE_HOST_EVENT_HANDLER"))
 
399
                command_type = CMD_ENABLE_HOST_EVENT_HANDLER;
 
400
        else if(!strcmp(command_id, "DISABLE_HOST_EVENT_HANDLER"))
 
401
                command_type = CMD_DISABLE_HOST_EVENT_HANDLER;
 
402
 
 
403
        else if(!strcmp(command_id, "ENABLE_HOST_CHECK"))
 
404
                command_type = CMD_ENABLE_HOST_CHECK;
 
405
        else if(!strcmp(command_id, "DISABLE_HOST_CHECK"))
 
406
                command_type = CMD_DISABLE_HOST_CHECK;
 
407
 
 
408
        else if(!strcmp(command_id, "SCHEDULE_HOST_CHECK"))
 
409
                command_type = CMD_SCHEDULE_HOST_CHECK;
 
410
        else if(!strcmp(command_id, "SCHEDULE_FORCED_HOST_CHECK"))
 
411
                command_type = CMD_SCHEDULE_FORCED_HOST_CHECK;
 
412
 
 
413
        else if(!strcmp(command_id, "SCHEDULE_HOST_DOWNTIME"))
 
414
                command_type = CMD_SCHEDULE_HOST_DOWNTIME;
 
415
        else if(!strcmp(command_id, "SCHEDULE_HOST_SVC_DOWNTIME"))
 
416
                command_type = CMD_SCHEDULE_HOST_SVC_DOWNTIME;
 
417
        else if(!strcmp(command_id, "DEL_HOST_DOWNTIME"))
 
418
                command_type = CMD_DEL_HOST_DOWNTIME;
 
419
        else if(!strcmp(command_id, "DEL_DOWNTIME_BY_HOST_NAME"))
 
420
                command_type = CMD_DEL_DOWNTIME_BY_HOST_NAME;
 
421
        else if(!strcmp(command_id, "DEL_DOWNTIME_BY_HOSTGROUP_NAME"))
 
422
                command_type = CMD_DEL_DOWNTIME_BY_HOSTGROUP_NAME;
 
423
        else if(!strcmp(command_id, "DEL_DOWNTIME_BY_START_TIME_COMMENT"))
 
424
                command_type = CMD_DEL_DOWNTIME_BY_START_TIME_COMMENT;
 
425
 
 
426
        else if(!strcmp(command_id, "ENABLE_HOST_FLAP_DETECTION"))
 
427
                command_type = CMD_ENABLE_HOST_FLAP_DETECTION;
 
428
        else if(!strcmp(command_id, "DISABLE_HOST_FLAP_DETECTION"))
 
429
                command_type = CMD_DISABLE_HOST_FLAP_DETECTION;
 
430
 
 
431
        else if(!strcmp(command_id, "START_OBSESSING_OVER_HOST"))
 
432
                command_type = CMD_START_OBSESSING_OVER_HOST;
 
433
        else if(!strcmp(command_id, "STOP_OBSESSING_OVER_HOST"))
 
434
                command_type = CMD_STOP_OBSESSING_OVER_HOST;
 
435
 
 
436
        else if(!strcmp(command_id, "CHANGE_HOST_EVENT_HANDLER"))
 
437
                command_type = CMD_CHANGE_HOST_EVENT_HANDLER;
 
438
        else if(!strcmp(command_id, "CHANGE_HOST_CHECK_COMMAND"))
 
439
                command_type = CMD_CHANGE_HOST_CHECK_COMMAND;
 
440
 
 
441
        else if(!strcmp(command_id, "CHANGE_NORMAL_HOST_CHECK_INTERVAL"))
 
442
                command_type = CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL;
 
443
        else if(!strcmp(command_id, "CHANGE_RETRY_HOST_CHECK_INTERVAL"))
 
444
                command_type = CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL;
 
445
 
 
446
        else if(!strcmp(command_id, "CHANGE_MAX_HOST_CHECK_ATTEMPTS"))
 
447
                command_type = CMD_CHANGE_MAX_HOST_CHECK_ATTEMPTS;
 
448
 
 
449
        else if(!strcmp(command_id, "SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME"))
 
450
                command_type = CMD_SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME;
 
451
 
 
452
        else if(!strcmp(command_id, "SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME"))
 
453
                command_type = CMD_SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME;
 
454
 
 
455
        else if(!strcmp(command_id, "SET_HOST_NOTIFICATION_NUMBER"))
 
456
                command_type = CMD_SET_HOST_NOTIFICATION_NUMBER;
 
457
 
 
458
        else if(!strcmp(command_id, "CHANGE_HOST_CHECK_TIMEPERIOD"))
 
459
                command_type = CMD_CHANGE_HOST_CHECK_TIMEPERIOD;
 
460
 
 
461
        else if(!strcmp(command_id, "CHANGE_CUSTOM_HOST_VAR"))
 
462
                command_type = CMD_CHANGE_CUSTOM_HOST_VAR;
 
463
 
 
464
        else if(!strcmp(command_id, "SEND_CUSTOM_HOST_NOTIFICATION"))
 
465
                command_type = CMD_SEND_CUSTOM_HOST_NOTIFICATION;
 
466
 
 
467
        else if(!strcmp(command_id, "CHANGE_HOST_NOTIFICATION_TIMEPERIOD"))
 
468
                command_type = CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD;
 
469
 
 
470
        else if(!strcmp(command_id, "CHANGE_HOST_MODATTR"))
 
471
                command_type = CMD_CHANGE_HOST_MODATTR;
466
472
 
467
473
 
468
474
        /************************************/
469
475
        /**** HOSTGROUP-RELATED COMMANDS ****/
470
476
        /************************************/
471
477
 
472
 
        else if(!strcmp(command_id,"ENABLE_HOSTGROUP_HOST_NOTIFICATIONS"))
473
 
                command_type=CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS;
474
 
        else if(!strcmp(command_id,"DISABLE_HOSTGROUP_HOST_NOTIFICATIONS"))
475
 
                command_type=CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS;
476
 
 
477
 
        else if(!strcmp(command_id,"ENABLE_HOSTGROUP_SVC_NOTIFICATIONS"))
478
 
                command_type=CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS;
479
 
        else if(!strcmp(command_id,"DISABLE_HOSTGROUP_SVC_NOTIFICATIONS"))
480
 
                command_type=CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS;
481
 
 
482
 
        else if(!strcmp(command_id,"ENABLE_HOSTGROUP_HOST_CHECKS"))
483
 
                command_type=CMD_ENABLE_HOSTGROUP_HOST_CHECKS;
484
 
        else if(!strcmp(command_id,"DISABLE_HOSTGROUP_HOST_CHECKS"))
485
 
                command_type=CMD_DISABLE_HOSTGROUP_HOST_CHECKS;
486
 
 
487
 
        else if(!strcmp(command_id,"ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS"))
488
 
                command_type=CMD_ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS;
489
 
        else if(!strcmp(command_id,"DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS"))
490
 
                command_type=CMD_DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS;
491
 
 
492
 
        else if(!strcmp(command_id,"ENABLE_HOSTGROUP_SVC_CHECKS"))
493
 
                command_type=CMD_ENABLE_HOSTGROUP_SVC_CHECKS;
494
 
        else if(!strcmp(command_id,"DISABLE_HOSTGROUP_SVC_CHECKS"))
495
 
                command_type=CMD_DISABLE_HOSTGROUP_SVC_CHECKS;
496
 
 
497
 
        else if(!strcmp(command_id,"ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS"))
498
 
                command_type=CMD_ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS;
499
 
        else if(!strcmp(command_id,"DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS"))
500
 
                command_type=CMD_DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS;
501
 
 
502
 
        else if(!strcmp(command_id,"SCHEDULE_HOSTGROUP_HOST_DOWNTIME"))
503
 
                command_type=CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME;
504
 
        else if(!strcmp(command_id,"SCHEDULE_HOSTGROUP_SVC_DOWNTIME"))
505
 
                command_type=CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME;
 
478
        else if(!strcmp(command_id, "ENABLE_HOSTGROUP_HOST_NOTIFICATIONS"))
 
479
                command_type = CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS;
 
480
        else if(!strcmp(command_id, "DISABLE_HOSTGROUP_HOST_NOTIFICATIONS"))
 
481
                command_type = CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS;
 
482
 
 
483
        else if(!strcmp(command_id, "ENABLE_HOSTGROUP_SVC_NOTIFICATIONS"))
 
484
                command_type = CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS;
 
485
        else if(!strcmp(command_id, "DISABLE_HOSTGROUP_SVC_NOTIFICATIONS"))
 
486
                command_type = CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS;
 
487
 
 
488
        else if(!strcmp(command_id, "ENABLE_HOSTGROUP_HOST_CHECKS"))
 
489
                command_type = CMD_ENABLE_HOSTGROUP_HOST_CHECKS;
 
490
        else if(!strcmp(command_id, "DISABLE_HOSTGROUP_HOST_CHECKS"))
 
491
                command_type = CMD_DISABLE_HOSTGROUP_HOST_CHECKS;
 
492
 
 
493
        else if(!strcmp(command_id, "ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS"))
 
494
                command_type = CMD_ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS;
 
495
        else if(!strcmp(command_id, "DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS"))
 
496
                command_type = CMD_DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS;
 
497
 
 
498
        else if(!strcmp(command_id, "ENABLE_HOSTGROUP_SVC_CHECKS"))
 
499
                command_type = CMD_ENABLE_HOSTGROUP_SVC_CHECKS;
 
500
        else if(!strcmp(command_id, "DISABLE_HOSTGROUP_SVC_CHECKS"))
 
501
                command_type = CMD_DISABLE_HOSTGROUP_SVC_CHECKS;
 
502
 
 
503
        else if(!strcmp(command_id, "ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS"))
 
504
                command_type = CMD_ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS;
 
505
        else if(!strcmp(command_id, "DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS"))
 
506
                command_type = CMD_DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS;
 
507
 
 
508
        else if(!strcmp(command_id, "SCHEDULE_HOSTGROUP_HOST_DOWNTIME"))
 
509
                command_type = CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME;
 
510
        else if(!strcmp(command_id, "SCHEDULE_HOSTGROUP_SVC_DOWNTIME"))
 
511
                command_type = CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME;
506
512
 
507
513
 
508
514
        /**********************************/
509
515
        /**** SERVICE-RELATED COMMANDS ****/
510
516
        /**********************************/
511
517
 
512
 
        else if(!strcmp(command_id,"ADD_SVC_COMMENT"))
513
 
                command_type=CMD_ADD_SVC_COMMENT;
514
 
        else if(!strcmp(command_id,"DEL_SVC_COMMENT"))
515
 
                command_type=CMD_DEL_SVC_COMMENT;
516
 
        else if(!strcmp(command_id,"DEL_ALL_SVC_COMMENTS"))
517
 
                command_type=CMD_DEL_ALL_SVC_COMMENTS;
518
 
 
519
 
        else if(!strcmp(command_id,"SCHEDULE_SVC_CHECK"))
520
 
                command_type=CMD_SCHEDULE_SVC_CHECK;
521
 
        else if(!strcmp(command_id,"SCHEDULE_FORCED_SVC_CHECK"))
522
 
                command_type=CMD_SCHEDULE_FORCED_SVC_CHECK;
523
 
 
524
 
        else if(!strcmp(command_id,"ENABLE_SVC_CHECK"))
525
 
                command_type=CMD_ENABLE_SVC_CHECK;
526
 
        else if(!strcmp(command_id,"DISABLE_SVC_CHECK"))
527
 
                command_type=CMD_DISABLE_SVC_CHECK;
528
 
 
529
 
        else if(!strcmp(command_id,"ENABLE_PASSIVE_SVC_CHECKS"))
530
 
                command_type=CMD_ENABLE_PASSIVE_SVC_CHECKS;
531
 
        else if(!strcmp(command_id,"DISABLE_PASSIVE_SVC_CHECKS"))
532
 
                command_type=CMD_DISABLE_PASSIVE_SVC_CHECKS;
533
 
 
534
 
        else if(!strcmp(command_id,"DELAY_SVC_NOTIFICATION"))
535
 
                command_type=CMD_DELAY_SVC_NOTIFICATION;
536
 
        else if(!strcmp(command_id,"ENABLE_SVC_NOTIFICATIONS"))
537
 
                command_type=CMD_ENABLE_SVC_NOTIFICATIONS;
538
 
        else if(!strcmp(command_id,"DISABLE_SVC_NOTIFICATIONS"))
539
 
                command_type=CMD_DISABLE_SVC_NOTIFICATIONS;
540
 
 
541
 
        else if(!strcmp(command_id,"PROCESS_SERVICE_CHECK_RESULT"))
542
 
                command_type=CMD_PROCESS_SERVICE_CHECK_RESULT;
543
 
        else if(!strcmp(command_id,"PROCESS_HOST_CHECK_RESULT"))
544
 
                command_type=CMD_PROCESS_HOST_CHECK_RESULT;
545
 
 
546
 
        else if(!strcmp(command_id,"ENABLE_SVC_EVENT_HANDLER"))
547
 
                command_type=CMD_ENABLE_SVC_EVENT_HANDLER;
548
 
        else if(!strcmp(command_id,"DISABLE_SVC_EVENT_HANDLER"))
549
 
                command_type=CMD_DISABLE_SVC_EVENT_HANDLER;
550
 
 
551
 
        else if(!strcmp(command_id,"ENABLE_SVC_FLAP_DETECTION"))
552
 
                command_type=CMD_ENABLE_SVC_FLAP_DETECTION;
553
 
        else if(!strcmp(command_id,"DISABLE_SVC_FLAP_DETECTION"))
554
 
                command_type=CMD_DISABLE_SVC_FLAP_DETECTION;
555
 
 
556
 
        else if(!strcmp(command_id,"SCHEDULE_SVC_DOWNTIME"))
557
 
                command_type=CMD_SCHEDULE_SVC_DOWNTIME;
558
 
        else if(!strcmp(command_id,"DEL_SVC_DOWNTIME"))
559
 
                command_type=CMD_DEL_SVC_DOWNTIME;
560
 
 
561
 
        else if(!strcmp(command_id,"ACKNOWLEDGE_SVC_PROBLEM"))
562
 
                command_type=CMD_ACKNOWLEDGE_SVC_PROBLEM;
563
 
        else if(!strcmp(command_id,"REMOVE_SVC_ACKNOWLEDGEMENT"))
564
 
                command_type=CMD_REMOVE_SVC_ACKNOWLEDGEMENT;
565
 
 
566
 
        else if(!strcmp(command_id,"START_OBSESSING_OVER_SVC"))
567
 
                command_type=CMD_START_OBSESSING_OVER_SVC;
568
 
        else if(!strcmp(command_id,"STOP_OBSESSING_OVER_SVC"))
569
 
                command_type=CMD_STOP_OBSESSING_OVER_SVC;
570
 
 
571
 
        else if(!strcmp(command_id,"CHANGE_SVC_EVENT_HANDLER"))
572
 
                command_type=CMD_CHANGE_SVC_EVENT_HANDLER;
573
 
        else if(!strcmp(command_id,"CHANGE_SVC_CHECK_COMMAND"))
574
 
                command_type=CMD_CHANGE_SVC_CHECK_COMMAND;
575
 
 
576
 
        else if(!strcmp(command_id,"CHANGE_NORMAL_SVC_CHECK_INTERVAL"))
577
 
                command_type=CMD_CHANGE_NORMAL_SVC_CHECK_INTERVAL;
578
 
        else if(!strcmp(command_id,"CHANGE_RETRY_SVC_CHECK_INTERVAL"))
579
 
                command_type=CMD_CHANGE_RETRY_SVC_CHECK_INTERVAL;
580
 
 
581
 
        else if(!strcmp(command_id,"CHANGE_MAX_SVC_CHECK_ATTEMPTS"))
582
 
                command_type=CMD_CHANGE_MAX_SVC_CHECK_ATTEMPTS;
583
 
 
584
 
        else if(!strcmp(command_id,"SET_SVC_NOTIFICATION_NUMBER"))
585
 
                command_type=CMD_SET_SVC_NOTIFICATION_NUMBER;
586
 
 
587
 
        else if(!strcmp(command_id,"CHANGE_SVC_CHECK_TIMEPERIOD"))
588
 
                command_type=CMD_CHANGE_SVC_CHECK_TIMEPERIOD;
589
 
 
590
 
        else if (!strcmp(command_id,"CHANGE_CUSTOM_SVC_VAR"))
591
 
                command_type=CMD_CHANGE_CUSTOM_SVC_VAR;
592
 
 
593
 
        else if (!strcmp(command_id,"CHANGE_CUSTOM_CONTACT_VAR"))
594
 
                command_type=CMD_CHANGE_CUSTOM_CONTACT_VAR;
595
 
 
596
 
        else if (!strcmp(command_id,"SEND_CUSTOM_SVC_NOTIFICATION"))
597
 
                command_type=CMD_SEND_CUSTOM_SVC_NOTIFICATION;
598
 
 
599
 
        else if(!strcmp(command_id,"CHANGE_SVC_NOTIFICATION_TIMEPERIOD"))
600
 
                command_type=CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD;
601
 
 
602
 
        else if(!strcmp(command_id,"CHANGE_SVC_MODATTR"))
603
 
                command_type=CMD_CHANGE_SVC_MODATTR;
 
518
        else if(!strcmp(command_id, "ADD_SVC_COMMENT"))
 
519
                command_type = CMD_ADD_SVC_COMMENT;
 
520
        else if(!strcmp(command_id, "DEL_SVC_COMMENT"))
 
521
                command_type = CMD_DEL_SVC_COMMENT;
 
522
        else if(!strcmp(command_id, "DEL_ALL_SVC_COMMENTS"))
 
523
                command_type = CMD_DEL_ALL_SVC_COMMENTS;
 
524
 
 
525
        else if(!strcmp(command_id, "SCHEDULE_SVC_CHECK"))
 
526
                command_type = CMD_SCHEDULE_SVC_CHECK;
 
527
        else if(!strcmp(command_id, "SCHEDULE_FORCED_SVC_CHECK"))
 
528
                command_type = CMD_SCHEDULE_FORCED_SVC_CHECK;
 
529
 
 
530
        else if(!strcmp(command_id, "ENABLE_SVC_CHECK"))
 
531
                command_type = CMD_ENABLE_SVC_CHECK;
 
532
        else if(!strcmp(command_id, "DISABLE_SVC_CHECK"))
 
533
                command_type = CMD_DISABLE_SVC_CHECK;
 
534
 
 
535
        else if(!strcmp(command_id, "ENABLE_PASSIVE_SVC_CHECKS"))
 
536
                command_type = CMD_ENABLE_PASSIVE_SVC_CHECKS;
 
537
        else if(!strcmp(command_id, "DISABLE_PASSIVE_SVC_CHECKS"))
 
538
                command_type = CMD_DISABLE_PASSIVE_SVC_CHECKS;
 
539
 
 
540
        else if(!strcmp(command_id, "DELAY_SVC_NOTIFICATION"))
 
541
                command_type = CMD_DELAY_SVC_NOTIFICATION;
 
542
        else if(!strcmp(command_id, "ENABLE_SVC_NOTIFICATIONS"))
 
543
                command_type = CMD_ENABLE_SVC_NOTIFICATIONS;
 
544
        else if(!strcmp(command_id, "DISABLE_SVC_NOTIFICATIONS"))
 
545
                command_type = CMD_DISABLE_SVC_NOTIFICATIONS;
 
546
 
 
547
        else if(!strcmp(command_id, "PROCESS_SERVICE_CHECK_RESULT"))
 
548
                command_type = CMD_PROCESS_SERVICE_CHECK_RESULT;
 
549
        else if(!strcmp(command_id, "PROCESS_HOST_CHECK_RESULT"))
 
550
                command_type = CMD_PROCESS_HOST_CHECK_RESULT;
 
551
 
 
552
        else if(!strcmp(command_id, "ENABLE_SVC_EVENT_HANDLER"))
 
553
                command_type = CMD_ENABLE_SVC_EVENT_HANDLER;
 
554
        else if(!strcmp(command_id, "DISABLE_SVC_EVENT_HANDLER"))
 
555
                command_type = CMD_DISABLE_SVC_EVENT_HANDLER;
 
556
 
 
557
        else if(!strcmp(command_id, "ENABLE_SVC_FLAP_DETECTION"))
 
558
                command_type = CMD_ENABLE_SVC_FLAP_DETECTION;
 
559
        else if(!strcmp(command_id, "DISABLE_SVC_FLAP_DETECTION"))
 
560
                command_type = CMD_DISABLE_SVC_FLAP_DETECTION;
 
561
 
 
562
        else if(!strcmp(command_id, "SCHEDULE_SVC_DOWNTIME"))
 
563
                command_type = CMD_SCHEDULE_SVC_DOWNTIME;
 
564
        else if(!strcmp(command_id, "DEL_SVC_DOWNTIME"))
 
565
                command_type = CMD_DEL_SVC_DOWNTIME;
 
566
 
 
567
        else if(!strcmp(command_id, "ACKNOWLEDGE_SVC_PROBLEM"))
 
568
                command_type = CMD_ACKNOWLEDGE_SVC_PROBLEM;
 
569
        else if(!strcmp(command_id, "REMOVE_SVC_ACKNOWLEDGEMENT"))
 
570
                command_type = CMD_REMOVE_SVC_ACKNOWLEDGEMENT;
 
571
 
 
572
        else if(!strcmp(command_id, "START_OBSESSING_OVER_SVC"))
 
573
                command_type = CMD_START_OBSESSING_OVER_SVC;
 
574
        else if(!strcmp(command_id, "STOP_OBSESSING_OVER_SVC"))
 
575
                command_type = CMD_STOP_OBSESSING_OVER_SVC;
 
576
 
 
577
        else if(!strcmp(command_id, "CHANGE_SVC_EVENT_HANDLER"))
 
578
                command_type = CMD_CHANGE_SVC_EVENT_HANDLER;
 
579
        else if(!strcmp(command_id, "CHANGE_SVC_CHECK_COMMAND"))
 
580
                command_type = CMD_CHANGE_SVC_CHECK_COMMAND;
 
581
 
 
582
        else if(!strcmp(command_id, "CHANGE_NORMAL_SVC_CHECK_INTERVAL"))
 
583
                command_type = CMD_CHANGE_NORMAL_SVC_CHECK_INTERVAL;
 
584
        else if(!strcmp(command_id, "CHANGE_RETRY_SVC_CHECK_INTERVAL"))
 
585
                command_type = CMD_CHANGE_RETRY_SVC_CHECK_INTERVAL;
 
586
 
 
587
        else if(!strcmp(command_id, "CHANGE_MAX_SVC_CHECK_ATTEMPTS"))
 
588
                command_type = CMD_CHANGE_MAX_SVC_CHECK_ATTEMPTS;
 
589
 
 
590
        else if(!strcmp(command_id, "SET_SVC_NOTIFICATION_NUMBER"))
 
591
                command_type = CMD_SET_SVC_NOTIFICATION_NUMBER;
 
592
 
 
593
        else if(!strcmp(command_id, "CHANGE_SVC_CHECK_TIMEPERIOD"))
 
594
                command_type = CMD_CHANGE_SVC_CHECK_TIMEPERIOD;
 
595
 
 
596
        else if(!strcmp(command_id, "CHANGE_CUSTOM_SVC_VAR"))
 
597
                command_type = CMD_CHANGE_CUSTOM_SVC_VAR;
 
598
 
 
599
        else if(!strcmp(command_id, "CHANGE_CUSTOM_CONTACT_VAR"))
 
600
                command_type = CMD_CHANGE_CUSTOM_CONTACT_VAR;
 
601
 
 
602
        else if(!strcmp(command_id, "SEND_CUSTOM_SVC_NOTIFICATION"))
 
603
                command_type = CMD_SEND_CUSTOM_SVC_NOTIFICATION;
 
604
 
 
605
        else if(!strcmp(command_id, "CHANGE_SVC_NOTIFICATION_TIMEPERIOD"))
 
606
                command_type = CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD;
 
607
 
 
608
        else if(!strcmp(command_id, "CHANGE_SVC_MODATTR"))
 
609
                command_type = CMD_CHANGE_SVC_MODATTR;
604
610
 
605
611
 
606
612
        /***************************************/
607
613
        /**** SERVICEGROUP-RELATED COMMANDS ****/
608
614
        /***************************************/
609
615
 
610
 
        else if(!strcmp(command_id,"ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS"))
611
 
                command_type=CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS;
612
 
        else if(!strcmp(command_id,"DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS"))
613
 
                command_type=CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS;
614
 
 
615
 
        else if(!strcmp(command_id,"ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS"))
616
 
                command_type=CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS;
617
 
        else if(!strcmp(command_id,"DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS"))
618
 
                command_type=CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS;
619
 
 
620
 
        else if(!strcmp(command_id,"ENABLE_SERVICEGROUP_HOST_CHECKS"))
621
 
                command_type=CMD_ENABLE_SERVICEGROUP_HOST_CHECKS;
622
 
        else if(!strcmp(command_id,"DISABLE_SERVICEGROUP_HOST_CHECKS"))
623
 
                command_type=CMD_DISABLE_SERVICEGROUP_HOST_CHECKS;
624
 
 
625
 
        else if(!strcmp(command_id,"ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS"))
626
 
                command_type=CMD_ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS;
627
 
        else if(!strcmp(command_id,"DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS"))
628
 
                command_type=CMD_DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS;
629
 
 
630
 
        else if(!strcmp(command_id,"ENABLE_SERVICEGROUP_SVC_CHECKS"))
631
 
                command_type=CMD_ENABLE_SERVICEGROUP_SVC_CHECKS;
632
 
        else if(!strcmp(command_id,"DISABLE_SERVICEGROUP_SVC_CHECKS"))
633
 
                command_type=CMD_DISABLE_SERVICEGROUP_SVC_CHECKS;
634
 
 
635
 
        else if(!strcmp(command_id,"ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS"))
636
 
                command_type=CMD_ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS;
637
 
        else if(!strcmp(command_id,"DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS"))
638
 
                command_type=CMD_DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS;
639
 
 
640
 
        else if(!strcmp(command_id,"SCHEDULE_SERVICEGROUP_HOST_DOWNTIME"))
641
 
                command_type=CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME;
642
 
        else if(!strcmp(command_id,"SCHEDULE_SERVICEGROUP_SVC_DOWNTIME"))
643
 
                command_type=CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME;
 
616
        else if(!strcmp(command_id, "ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS"))
 
617
                command_type = CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS;
 
618
        else if(!strcmp(command_id, "DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS"))
 
619
                command_type = CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS;
 
620
 
 
621
        else if(!strcmp(command_id, "ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS"))
 
622
                command_type = CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS;
 
623
        else if(!strcmp(command_id, "DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS"))
 
624
                command_type = CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS;
 
625
 
 
626
        else if(!strcmp(command_id, "ENABLE_SERVICEGROUP_HOST_CHECKS"))
 
627
                command_type = CMD_ENABLE_SERVICEGROUP_HOST_CHECKS;
 
628
        else if(!strcmp(command_id, "DISABLE_SERVICEGROUP_HOST_CHECKS"))
 
629
                command_type = CMD_DISABLE_SERVICEGROUP_HOST_CHECKS;
 
630
 
 
631
        else if(!strcmp(command_id, "ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS"))
 
632
                command_type = CMD_ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS;
 
633
        else if(!strcmp(command_id, "DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS"))
 
634
                command_type = CMD_DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS;
 
635
 
 
636
        else if(!strcmp(command_id, "ENABLE_SERVICEGROUP_SVC_CHECKS"))
 
637
                command_type = CMD_ENABLE_SERVICEGROUP_SVC_CHECKS;
 
638
        else if(!strcmp(command_id, "DISABLE_SERVICEGROUP_SVC_CHECKS"))
 
639
                command_type = CMD_DISABLE_SERVICEGROUP_SVC_CHECKS;
 
640
 
 
641
        else if(!strcmp(command_id, "ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS"))
 
642
                command_type = CMD_ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS;
 
643
        else if(!strcmp(command_id, "DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS"))
 
644
                command_type = CMD_DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS;
 
645
 
 
646
        else if(!strcmp(command_id, "SCHEDULE_SERVICEGROUP_HOST_DOWNTIME"))
 
647
                command_type = CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME;
 
648
        else if(!strcmp(command_id, "SCHEDULE_SERVICEGROUP_SVC_DOWNTIME"))
 
649
                command_type = CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME;
644
650
 
645
651
 
646
652
        /**********************************/
647
653
        /**** CONTACT-RELATED COMMANDS ****/
648
654
        /**********************************/
649
655
 
650
 
        else if(!strcmp(command_id,"ENABLE_CONTACT_HOST_NOTIFICATIONS"))
651
 
                command_type=CMD_ENABLE_CONTACT_HOST_NOTIFICATIONS;
652
 
        else if(!strcmp(command_id,"DISABLE_CONTACT_HOST_NOTIFICATIONS"))
653
 
                command_type=CMD_DISABLE_CONTACT_HOST_NOTIFICATIONS;
654
 
 
655
 
        else if(!strcmp(command_id,"ENABLE_CONTACT_SVC_NOTIFICATIONS"))
656
 
                command_type=CMD_ENABLE_CONTACT_SVC_NOTIFICATIONS;
657
 
        else if(!strcmp(command_id,"DISABLE_CONTACT_SVC_NOTIFICATIONS"))
658
 
                command_type=CMD_DISABLE_CONTACT_SVC_NOTIFICATIONS;
659
 
 
660
 
        else if(!strcmp(command_id,"CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD"))
661
 
                command_type=CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD;
662
 
 
663
 
        else if(!strcmp(command_id,"CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD"))
664
 
                command_type=CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD;
665
 
 
666
 
        else if(!strcmp(command_id,"CHANGE_CONTACT_MODATTR"))
667
 
                command_type=CMD_CHANGE_CONTACT_MODATTR;
668
 
        else if(!strcmp(command_id,"CHANGE_CONTACT_MODHATTR"))
669
 
                command_type=CMD_CHANGE_CONTACT_MODHATTR;
670
 
        else if(!strcmp(command_id,"CHANGE_CONTACT_MODSATTR"))
671
 
                command_type=CMD_CHANGE_CONTACT_MODSATTR;
 
656
        else if(!strcmp(command_id, "ENABLE_CONTACT_HOST_NOTIFICATIONS"))
 
657
                command_type = CMD_ENABLE_CONTACT_HOST_NOTIFICATIONS;
 
658
        else if(!strcmp(command_id, "DISABLE_CONTACT_HOST_NOTIFICATIONS"))
 
659
                command_type = CMD_DISABLE_CONTACT_HOST_NOTIFICATIONS;
 
660
 
 
661
        else if(!strcmp(command_id, "ENABLE_CONTACT_SVC_NOTIFICATIONS"))
 
662
                command_type = CMD_ENABLE_CONTACT_SVC_NOTIFICATIONS;
 
663
        else if(!strcmp(command_id, "DISABLE_CONTACT_SVC_NOTIFICATIONS"))
 
664
                command_type = CMD_DISABLE_CONTACT_SVC_NOTIFICATIONS;
 
665
 
 
666
        else if(!strcmp(command_id, "CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD"))
 
667
                command_type = CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD;
 
668
 
 
669
        else if(!strcmp(command_id, "CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD"))
 
670
                command_type = CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD;
 
671
 
 
672
        else if(!strcmp(command_id, "CHANGE_CONTACT_MODATTR"))
 
673
                command_type = CMD_CHANGE_CONTACT_MODATTR;
 
674
        else if(!strcmp(command_id, "CHANGE_CONTACT_MODHATTR"))
 
675
                command_type = CMD_CHANGE_CONTACT_MODHATTR;
 
676
        else if(!strcmp(command_id, "CHANGE_CONTACT_MODSATTR"))
 
677
                command_type = CMD_CHANGE_CONTACT_MODSATTR;
672
678
 
673
679
        /***************************************/
674
680
        /**** CONTACTGROUP-RELATED COMMANDS ****/
675
681
        /***************************************/
676
682
 
677
 
        else if(!strcmp(command_id,"ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS"))
678
 
                command_type=CMD_ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS;
679
 
        else if(!strcmp(command_id,"DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS"))
680
 
                command_type=CMD_DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS;
 
683
        else if(!strcmp(command_id, "ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS"))
 
684
                command_type = CMD_ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS;
 
685
        else if(!strcmp(command_id, "DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS"))
 
686
                command_type = CMD_DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS;
681
687
 
682
 
        else if(!strcmp(command_id,"ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS"))
683
 
                command_type=CMD_ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS;
684
 
        else if(!strcmp(command_id,"DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS"))
685
 
                command_type=CMD_DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS;
 
688
        else if(!strcmp(command_id, "ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS"))
 
689
                command_type = CMD_ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS;
 
690
        else if(!strcmp(command_id, "DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS"))
 
691
                command_type = CMD_DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS;
686
692
 
687
693
 
688
694
        /**************************/
689
695
        /****** MISC COMMANDS *****/
690
696
        /**************************/
691
697
 
692
 
        else if(!strcmp(command_id,"PROCESS_FILE"))
693
 
                command_type=CMD_PROCESS_FILE;
694
 
 
695
 
        
 
698
        else if(!strcmp(command_id, "PROCESS_FILE"))
 
699
                command_type = CMD_PROCESS_FILE;
 
700
 
 
701
 
696
702
 
697
703
        /****************************/
698
704
        /****** CUSTOM COMMANDS *****/
699
705
        /****************************/
700
706
 
701
 
        else if(command_id[0]=='_')
702
 
                command_type=CMD_CUSTOM_COMMAND;
 
707
        else if(command_id[0] == '_')
 
708
                command_type = CMD_CUSTOM_COMMAND;
703
709
 
704
710
 
705
711
 
706
712
        /**** UNKNOWN COMMAND ****/
707
 
        else{
 
713
        else {
708
714
                /* log the bad external command */
709
 
                logit(NSLOG_EXTERNAL_COMMAND | NSLOG_RUNTIME_WARNING,TRUE,"Warning: Unrecognized external command -> %s;%s\n",command_id,args);
 
715
                logit(NSLOG_EXTERNAL_COMMAND | NSLOG_RUNTIME_WARNING, TRUE, "Warning: Unrecognized external command -> %s;%s\n", command_id, args);
710
716
 
711
717
                /* free memory */
712
718
                my_free(command_id);
713
719
                my_free(args);
714
720
 
715
721
                return ERROR;
716
 
                }
 
722
                }
717
723
 
718
724
        /* update statistics for external commands */
719
 
        update_check_stats(EXTERNAL_COMMAND_STATS,time(NULL));
 
725
        update_check_stats(EXTERNAL_COMMAND_STATS, time(NULL));
720
726
 
721
727
        /* log the external command */
722
 
        asprintf(&temp_buffer,"EXTERNAL COMMAND: %s;%s\n",command_id,args);
723
 
        if(command_type==CMD_PROCESS_SERVICE_CHECK_RESULT || command_type==CMD_PROCESS_HOST_CHECK_RESULT){
 
728
        asprintf(&temp_buffer, "EXTERNAL COMMAND: %s;%s\n", command_id, args);
 
729
        if(command_type == CMD_PROCESS_SERVICE_CHECK_RESULT || command_type == CMD_PROCESS_HOST_CHECK_RESULT) {
724
730
                /* passive checks are logged in checks.c as well, as some my bypass external commands by getting dropped in checkresults dir */
725
 
                if(log_passive_checks==TRUE)
726
 
                        write_to_all_logs(temp_buffer,NSLOG_PASSIVE_CHECK);
727
 
                }
728
 
        else{
729
 
                if(log_external_commands==TRUE)
730
 
                        write_to_all_logs(temp_buffer,NSLOG_EXTERNAL_COMMAND);
731
 
                }
 
731
                if(log_passive_checks == TRUE)
 
732
                        write_to_all_logs(temp_buffer, NSLOG_PASSIVE_CHECK);
 
733
                }
 
734
        else {
 
735
                if(log_external_commands == TRUE)
 
736
                        write_to_all_logs(temp_buffer, NSLOG_EXTERNAL_COMMAND);
 
737
                }
732
738
        my_free(temp_buffer);
733
739
 
734
740
#ifdef USE_EVENT_BROKER
735
741
        /* send data to event broker */
736
 
        broker_external_command(NEBTYPE_EXTERNALCOMMAND_START,NEBFLAG_NONE,NEBATTR_NONE,command_type,entry_time,command_id,args,NULL);
 
742
        broker_external_command(NEBTYPE_EXTERNALCOMMAND_START, NEBFLAG_NONE, NEBATTR_NONE, command_type, entry_time, command_id, args, NULL);
737
743
#endif
738
744
 
739
745
        /* process the command */
740
 
        process_external_command2(command_type,entry_time,args);
 
746
        process_external_command2(command_type, entry_time, args);
741
747
 
742
748
#ifdef USE_EVENT_BROKER
743
749
        /* send data to event broker */
744
 
        broker_external_command(NEBTYPE_EXTERNALCOMMAND_END,NEBFLAG_NONE,NEBATTR_NONE,command_type,entry_time,command_id,args,NULL);
 
750
        broker_external_command(NEBTYPE_EXTERNALCOMMAND_END, NEBFLAG_NONE, NEBATTR_NONE, command_type, entry_time, command_id, args, NULL);
745
751
#endif
746
752
 
747
753
        /* free memory */
749
755
        my_free(args);
750
756
 
751
757
        return OK;
752
 
        }
 
758
        }
753
759
 
754
760
 
755
761
 
756
762
/* top-level processor for a single external command */
757
 
int process_external_command2(int cmd, time_t entry_time, char *args){
758
 
 
759
 
        log_debug_info(DEBUGL_FUNCTIONS,0,"process_external_command2()\n");
760
 
 
761
 
        log_debug_info(DEBUGL_EXTERNALCOMMANDS,1,"External Command Type: %d\n",cmd);
762
 
        log_debug_info(DEBUGL_EXTERNALCOMMANDS,1,"Command Entry Time: %lu\n",(unsigned long)entry_time);
763
 
        log_debug_info(DEBUGL_EXTERNALCOMMANDS,1,"Command Arguments: %s\n",(args==NULL)?"":args);
 
763
int process_external_command2(int cmd, time_t entry_time, char *args) {
 
764
 
 
765
        log_debug_info(DEBUGL_FUNCTIONS, 0, "process_external_command2()\n");
 
766
 
 
767
        log_debug_info(DEBUGL_EXTERNALCOMMANDS, 1, "External Command Type: %d\n", cmd);
 
768
        log_debug_info(DEBUGL_EXTERNALCOMMANDS, 1, "Command Entry Time: %lu\n", (unsigned long)entry_time);
 
769
        log_debug_info(DEBUGL_EXTERNALCOMMANDS, 1, "Command Arguments: %s\n", (args == NULL) ? "" : args);
764
770
 
765
771
        /* how shall we execute the command? */
766
 
        switch(cmd){
767
 
 
768
 
                /***************************/
769
 
                /***** SYSTEM COMMANDS *****/
770
 
                /***************************/
771
 
 
772
 
        case CMD_SHUTDOWN_PROCESS:
773
 
        case CMD_RESTART_PROCESS:
774
 
                cmd_signal_process(cmd,args);
775
 
                break;
776
 
 
777
 
        case CMD_SAVE_STATE_INFORMATION:
778
 
                save_state_information(FALSE);
779
 
                break;
780
 
 
781
 
        case CMD_READ_STATE_INFORMATION:
782
 
                read_initial_state_information();
783
 
                break;
784
 
 
785
 
        case CMD_ENABLE_NOTIFICATIONS:
786
 
                enable_all_notifications();
787
 
                break;
788
 
 
789
 
        case CMD_DISABLE_NOTIFICATIONS:
790
 
                disable_all_notifications();
791
 
                break;
792
 
 
793
 
        case CMD_START_EXECUTING_SVC_CHECKS:
794
 
                start_executing_service_checks();
795
 
                break;
796
 
 
797
 
        case CMD_STOP_EXECUTING_SVC_CHECKS:
798
 
                stop_executing_service_checks();
799
 
                break;
800
 
 
801
 
        case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
802
 
                start_accepting_passive_service_checks();
803
 
                break;
804
 
 
805
 
        case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
806
 
                stop_accepting_passive_service_checks();
807
 
                break;
808
 
 
809
 
        case CMD_START_OBSESSING_OVER_SVC_CHECKS:
810
 
                start_obsessing_over_service_checks();
811
 
                break;
812
 
 
813
 
        case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
814
 
                stop_obsessing_over_service_checks();
815
 
                break;
816
 
 
817
 
        case CMD_START_EXECUTING_HOST_CHECKS:
818
 
                start_executing_host_checks();
819
 
                break;
820
 
 
821
 
        case CMD_STOP_EXECUTING_HOST_CHECKS:
822
 
                stop_executing_host_checks();
823
 
                break;
824
 
 
825
 
        case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
826
 
                start_accepting_passive_host_checks();
827
 
                break;
828
 
 
829
 
        case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
830
 
                stop_accepting_passive_host_checks();
831
 
                break;
832
 
 
833
 
        case CMD_START_OBSESSING_OVER_HOST_CHECKS:
834
 
                start_obsessing_over_host_checks();
835
 
                break;
836
 
 
837
 
        case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
838
 
                stop_obsessing_over_host_checks();
839
 
                break;
840
 
 
841
 
        case CMD_ENABLE_EVENT_HANDLERS:
842
 
                start_using_event_handlers();
843
 
                break;
844
 
 
845
 
        case CMD_DISABLE_EVENT_HANDLERS:
846
 
                stop_using_event_handlers();
847
 
                break;
848
 
 
849
 
        case CMD_ENABLE_FLAP_DETECTION:
850
 
                enable_flap_detection_routines();
851
 
                break;
852
 
 
853
 
        case CMD_DISABLE_FLAP_DETECTION:
854
 
                disable_flap_detection_routines();
855
 
                break;
856
 
 
857
 
        case CMD_ENABLE_SERVICE_FRESHNESS_CHECKS:
858
 
                enable_service_freshness_checks();
859
 
                break;
860
 
        
861
 
        case CMD_DISABLE_SERVICE_FRESHNESS_CHECKS:
862
 
                disable_service_freshness_checks();
863
 
                break;
864
 
        
865
 
        case CMD_ENABLE_HOST_FRESHNESS_CHECKS:
866
 
                enable_host_freshness_checks();
867
 
                break;
868
 
        
869
 
        case CMD_DISABLE_HOST_FRESHNESS_CHECKS:
870
 
                disable_host_freshness_checks();
871
 
                break;
872
 
        
873
 
        case CMD_ENABLE_FAILURE_PREDICTION:
874
 
                enable_all_failure_prediction();
875
 
                break;
876
 
                
877
 
        case CMD_DISABLE_FAILURE_PREDICTION:
878
 
                disable_all_failure_prediction();
879
 
                break;
880
 
 
881
 
        case CMD_ENABLE_PERFORMANCE_DATA:
882
 
                enable_performance_data();
883
 
                break;
884
 
 
885
 
        case CMD_DISABLE_PERFORMANCE_DATA:
886
 
                disable_performance_data();
887
 
                break;
888
 
 
889
 
 
890
 
                /***************************/
891
 
                /*****  HOST COMMANDS  *****/
892
 
                /***************************/
893
 
 
894
 
        case CMD_ENABLE_HOST_CHECK:
895
 
        case CMD_DISABLE_HOST_CHECK:
896
 
        case CMD_ENABLE_PASSIVE_HOST_CHECKS:
897
 
        case CMD_DISABLE_PASSIVE_HOST_CHECKS:
898
 
        case CMD_ENABLE_HOST_SVC_CHECKS:
899
 
        case CMD_DISABLE_HOST_SVC_CHECKS:
900
 
        case CMD_ENABLE_HOST_NOTIFICATIONS:
901
 
        case CMD_DISABLE_HOST_NOTIFICATIONS:
902
 
        case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
903
 
        case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
904
 
        case CMD_ENABLE_HOST_AND_CHILD_NOTIFICATIONS:
905
 
        case CMD_DISABLE_HOST_AND_CHILD_NOTIFICATIONS:
906
 
        case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
907
 
        case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
908
 
        case CMD_ENABLE_HOST_FLAP_DETECTION:
909
 
        case CMD_DISABLE_HOST_FLAP_DETECTION:
910
 
        case CMD_ENABLE_HOST_EVENT_HANDLER:
911
 
        case CMD_DISABLE_HOST_EVENT_HANDLER:
912
 
        case CMD_START_OBSESSING_OVER_HOST:
913
 
        case CMD_STOP_OBSESSING_OVER_HOST:
914
 
        case CMD_SET_HOST_NOTIFICATION_NUMBER:
915
 
        case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
916
 
                process_host_command(cmd,entry_time,args);
917
 
                break;
918
 
 
919
 
 
920
 
                /*****************************/
921
 
                /***** HOSTGROUP COMMANDS ****/
922
 
                /*****************************/
923
 
 
924
 
        case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
925
 
        case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
926
 
        case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
927
 
        case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
928
 
        case CMD_ENABLE_HOSTGROUP_HOST_CHECKS:
929
 
        case CMD_DISABLE_HOSTGROUP_HOST_CHECKS:
930
 
        case CMD_ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS:
931
 
        case CMD_DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS:
932
 
        case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
933
 
        case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
934
 
        case CMD_ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS:
935
 
        case CMD_DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS:
936
 
                process_hostgroup_command(cmd,entry_time,args);
937
 
                break;
938
 
 
939
 
 
940
 
                /***************************/
941
 
                /***** SERVICE COMMANDS ****/
942
 
                /***************************/
943
 
 
944
 
        case CMD_ENABLE_SVC_CHECK:
945
 
        case CMD_DISABLE_SVC_CHECK:
946
 
        case CMD_ENABLE_PASSIVE_SVC_CHECKS:
947
 
        case CMD_DISABLE_PASSIVE_SVC_CHECKS:
948
 
        case CMD_ENABLE_SVC_NOTIFICATIONS:
949
 
        case CMD_DISABLE_SVC_NOTIFICATIONS:
950
 
        case CMD_ENABLE_SVC_FLAP_DETECTION:
951
 
        case CMD_DISABLE_SVC_FLAP_DETECTION:
952
 
        case CMD_ENABLE_SVC_EVENT_HANDLER:
953
 
        case CMD_DISABLE_SVC_EVENT_HANDLER:
954
 
        case CMD_START_OBSESSING_OVER_SVC:
955
 
        case CMD_STOP_OBSESSING_OVER_SVC:
956
 
        case CMD_SET_SVC_NOTIFICATION_NUMBER:
957
 
        case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
958
 
                process_service_command(cmd,entry_time,args);
959
 
                break;
960
 
 
961
 
 
962
 
                /********************************/
963
 
                /***** SERVICEGROUP COMMANDS ****/
964
 
                /********************************/
965
 
 
966
 
        case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
967
 
        case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
968
 
        case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
969
 
        case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
970
 
        case CMD_ENABLE_SERVICEGROUP_HOST_CHECKS:
971
 
        case CMD_DISABLE_SERVICEGROUP_HOST_CHECKS:
972
 
        case CMD_ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS:
973
 
        case CMD_DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS:
974
 
        case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
975
 
        case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
976
 
        case CMD_ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
977
 
        case CMD_DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
978
 
                process_servicegroup_command(cmd,entry_time,args);
979
 
                break;
980
 
 
981
 
 
982
 
                /**********************************/
983
 
                /**** CONTACT-RELATED COMMANDS ****/
984
 
                /**********************************/
985
 
 
986
 
        case CMD_ENABLE_CONTACT_HOST_NOTIFICATIONS:
987
 
        case CMD_DISABLE_CONTACT_HOST_NOTIFICATIONS:
988
 
        case CMD_ENABLE_CONTACT_SVC_NOTIFICATIONS:
989
 
        case CMD_DISABLE_CONTACT_SVC_NOTIFICATIONS:
990
 
                process_contact_command(cmd,entry_time,args);
991
 
                break;
992
 
 
993
 
 
994
 
                /***************************************/
995
 
                /**** CONTACTGROUP-RELATED COMMANDS ****/
996
 
                /***************************************/
997
 
 
998
 
        case CMD_ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS:
999
 
        case CMD_DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS:
1000
 
        case CMD_ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
1001
 
        case CMD_DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
1002
 
                process_contactgroup_command(cmd,entry_time,args);
1003
 
                break;
1004
 
 
1005
 
 
1006
 
                /***************************/
1007
 
                /**** UNSORTED COMMANDS ****/
1008
 
                /***************************/
1009
 
 
1010
 
 
1011
 
        case CMD_ADD_HOST_COMMENT:
1012
 
        case CMD_ADD_SVC_COMMENT:
1013
 
                cmd_add_comment(cmd,entry_time,args);
1014
 
                break;
1015
 
 
1016
 
        case CMD_DEL_HOST_COMMENT:
1017
 
        case CMD_DEL_SVC_COMMENT:
1018
 
                cmd_delete_comment(cmd,args);
1019
 
                break;
1020
 
 
1021
 
        case CMD_DELAY_HOST_NOTIFICATION:
1022
 
        case CMD_DELAY_SVC_NOTIFICATION:
1023
 
                cmd_delay_notification(cmd,args);
1024
 
                break;
1025
 
 
1026
 
        case CMD_SCHEDULE_SVC_CHECK:
1027
 
        case CMD_SCHEDULE_FORCED_SVC_CHECK:
1028
 
                cmd_schedule_check(cmd,args);
1029
 
                break;
1030
 
 
1031
 
        case CMD_SCHEDULE_HOST_SVC_CHECKS:
1032
 
        case CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS:
1033
 
                cmd_schedule_check(cmd,args);
1034
 
                break;
1035
 
 
1036
 
        case CMD_DEL_ALL_HOST_COMMENTS:
1037
 
        case CMD_DEL_ALL_SVC_COMMENTS:
1038
 
                cmd_delete_all_comments(cmd,args);
1039
 
                break;
1040
 
 
1041
 
        case CMD_PROCESS_SERVICE_CHECK_RESULT:
1042
 
                cmd_process_service_check_result(cmd,entry_time,args);
1043
 
                break;
1044
 
 
1045
 
        case CMD_PROCESS_HOST_CHECK_RESULT:
1046
 
                cmd_process_host_check_result(cmd,entry_time,args);
1047
 
                break;
1048
 
 
1049
 
        case CMD_ACKNOWLEDGE_HOST_PROBLEM:
1050
 
        case CMD_ACKNOWLEDGE_SVC_PROBLEM:
1051
 
                cmd_acknowledge_problem(cmd,args);
1052
 
                break;
1053
 
 
1054
 
        case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
1055
 
        case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
1056
 
                cmd_remove_acknowledgement(cmd,args);
1057
 
                break;
1058
 
 
1059
 
        case CMD_SCHEDULE_HOST_DOWNTIME:
1060
 
        case CMD_SCHEDULE_SVC_DOWNTIME:
1061
 
        case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
1062
 
        case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
1063
 
        case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
1064
 
        case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
1065
 
        case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
1066
 
        case CMD_SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME:
1067
 
        case CMD_SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME:
1068
 
                cmd_schedule_downtime(cmd,entry_time,args);
1069
 
                break;
1070
 
 
1071
 
        case CMD_DEL_HOST_DOWNTIME:
1072
 
        case CMD_DEL_SVC_DOWNTIME:
1073
 
                cmd_delete_downtime(cmd,args);
1074
 
                break;
1075
 
 
1076
 
        case CMD_CANCEL_ACTIVE_HOST_SVC_DOWNTIME:
1077
 
        case CMD_CANCEL_PENDING_HOST_SVC_DOWNTIME:
1078
 
                break;
1079
 
 
1080
 
        case CMD_SCHEDULE_HOST_CHECK:
1081
 
        case CMD_SCHEDULE_FORCED_HOST_CHECK:
1082
 
                cmd_schedule_check(cmd,args);
1083
 
                break;
1084
 
 
1085
 
        case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
1086
 
        case CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER:
1087
 
        case CMD_CHANGE_HOST_EVENT_HANDLER:
1088
 
        case CMD_CHANGE_SVC_EVENT_HANDLER:
1089
 
        case CMD_CHANGE_HOST_CHECK_COMMAND:
1090
 
        case CMD_CHANGE_SVC_CHECK_COMMAND:
1091
 
        case CMD_CHANGE_HOST_CHECK_TIMEPERIOD:
1092
 
        case CMD_CHANGE_SVC_CHECK_TIMEPERIOD:
1093
 
        case CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD:
1094
 
        case CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD:
1095
 
        case CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD:
1096
 
        case CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD:
1097
 
                cmd_change_object_char_var(cmd,args);
1098
 
                break;
1099
 
 
1100
 
        case CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL:
1101
 
        case CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL:
1102
 
        case CMD_CHANGE_NORMAL_SVC_CHECK_INTERVAL:
1103
 
        case CMD_CHANGE_RETRY_SVC_CHECK_INTERVAL:
1104
 
        case CMD_CHANGE_MAX_HOST_CHECK_ATTEMPTS:
1105
 
        case CMD_CHANGE_MAX_SVC_CHECK_ATTEMPTS:
1106
 
        case CMD_CHANGE_HOST_MODATTR:
1107
 
        case CMD_CHANGE_SVC_MODATTR:
1108
 
        case CMD_CHANGE_CONTACT_MODATTR:
1109
 
        case CMD_CHANGE_CONTACT_MODHATTR:
1110
 
        case CMD_CHANGE_CONTACT_MODSATTR:
1111
 
                cmd_change_object_int_var(cmd,args);
1112
 
                break;
1113
 
 
1114
 
        case CMD_CHANGE_CUSTOM_HOST_VAR:
1115
 
        case CMD_CHANGE_CUSTOM_SVC_VAR:
1116
 
        case CMD_CHANGE_CUSTOM_CONTACT_VAR:
1117
 
                cmd_change_object_custom_var(cmd,args);
1118
 
                break;
1119
 
 
1120
 
 
1121
 
                /***********************/
1122
 
                /**** MISC COMMANDS ****/
1123
 
                /***********************/
1124
 
 
1125
 
 
1126
 
        case CMD_PROCESS_FILE:
1127
 
                cmd_process_external_commands_from_file(cmd,args);
1128
 
                break;
1129
 
 
1130
 
 
1131
 
                /*************************/
1132
 
                /**** CUSTOM COMMANDS ****/
1133
 
                /*************************/
1134
 
 
1135
 
 
1136
 
        case CMD_CUSTOM_COMMAND:
1137
 
                /* custom commands aren't handled internally by Nagios, but may be by NEB modules */
1138
 
                break;
1139
 
 
1140
 
        default:
1141
 
                return ERROR;
1142
 
                break;
1143
 
                }
1144
 
 
1145
 
        return OK;
1146
 
        }
1147
 
 
1148
 
 
1149
 
/* processes an external host command */
1150
 
int process_host_command(int cmd, time_t entry_time, char *args){
1151
 
        char *host_name=NULL;
1152
 
        host *temp_host=NULL;
1153
 
        service *temp_service=NULL;
1154
 
        servicesmember *temp_servicesmember=NULL;
1155
 
        char *str=NULL;
1156
 
        char *buf[2]={NULL,NULL};
1157
 
        int intval=0;
1158
 
 
1159
 
        printf("ARGS: %s\n",args);
1160
 
 
1161
 
        /* get the host name */
1162
 
        if((host_name=my_strtok(args,";"))==NULL)
1163
 
                return ERROR;
1164
 
 
1165
 
        /* find the host */
1166
 
        if((temp_host=find_host(host_name))==NULL)
1167
 
                return ERROR;
1168
 
 
1169
 
        switch(cmd){
1170
 
 
1171
 
        case CMD_ENABLE_HOST_NOTIFICATIONS:
1172
 
                enable_host_notifications(temp_host);
1173
 
                break;
1174
 
 
1175
 
        case CMD_DISABLE_HOST_NOTIFICATIONS:
1176
 
                disable_host_notifications(temp_host);
1177
 
                break;
1178
 
 
1179
 
        case CMD_ENABLE_HOST_AND_CHILD_NOTIFICATIONS:
1180
 
                enable_and_propagate_notifications(temp_host,0,TRUE,TRUE,FALSE);
1181
 
                break;
1182
 
 
1183
 
        case CMD_DISABLE_HOST_AND_CHILD_NOTIFICATIONS:
1184
 
                disable_and_propagate_notifications(temp_host,0,TRUE,TRUE,FALSE);
1185
 
                break;
1186
 
 
1187
 
        case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
1188
 
                enable_and_propagate_notifications(temp_host,0,FALSE,TRUE,TRUE);
1189
 
                break;
1190
 
 
1191
 
        case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
1192
 
                disable_and_propagate_notifications(temp_host,0,FALSE,TRUE,TRUE);
1193
 
                break;
1194
 
 
1195
 
        case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
1196
 
        case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
1197
 
                for(temp_servicesmember=temp_host->services;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
1198
 
                        if((temp_service=temp_servicesmember->service_ptr)==NULL)
1199
 
                                continue;
1200
 
                        if(cmd==CMD_ENABLE_HOST_SVC_NOTIFICATIONS)
1201
 
                                enable_service_notifications(temp_service);
1202
 
                        else
1203
 
                                disable_service_notifications(temp_service);
1204
 
                        }
1205
 
                break;
1206
 
 
1207
 
        case CMD_ENABLE_HOST_SVC_CHECKS:
1208
 
        case CMD_DISABLE_HOST_SVC_CHECKS:
1209
 
                for(temp_servicesmember=temp_host->services;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
1210
 
                        if((temp_service=temp_servicesmember->service_ptr)==NULL)
1211
 
                                continue;
1212
 
                        if(cmd==CMD_ENABLE_HOST_SVC_CHECKS)
1213
 
                                enable_service_checks(temp_service);
1214
 
                        else
1215
 
                                disable_service_checks(temp_service);
1216
 
                        } 
1217
 
                break;
1218
 
 
1219
 
        case CMD_ENABLE_HOST_CHECK:
1220
 
                enable_host_checks(temp_host);
1221
 
                break;
1222
 
 
1223
 
        case CMD_DISABLE_HOST_CHECK:
1224
 
                disable_host_checks(temp_host);
1225
 
                break;
1226
 
 
1227
 
        case CMD_ENABLE_HOST_EVENT_HANDLER:
1228
 
                enable_host_event_handler(temp_host);
1229
 
                break;
1230
 
 
1231
 
        case CMD_DISABLE_HOST_EVENT_HANDLER:
1232
 
                disable_host_event_handler(temp_host);
1233
 
                break;
1234
 
 
1235
 
        case CMD_ENABLE_HOST_FLAP_DETECTION:
1236
 
                enable_host_flap_detection(temp_host);
1237
 
                break;
1238
 
 
1239
 
        case CMD_DISABLE_HOST_FLAP_DETECTION:
1240
 
                disable_host_flap_detection(temp_host);
1241
 
                break;
1242
 
 
1243
 
        case CMD_ENABLE_PASSIVE_HOST_CHECKS:
1244
 
                enable_passive_host_checks(temp_host);
1245
 
                break;
1246
 
 
1247
 
        case CMD_DISABLE_PASSIVE_HOST_CHECKS:
1248
 
                disable_passive_host_checks(temp_host);
1249
 
                break;
1250
 
 
1251
 
        case CMD_START_OBSESSING_OVER_HOST:
1252
 
                start_obsessing_over_host(temp_host);
1253
 
                break;
1254
 
 
1255
 
        case CMD_STOP_OBSESSING_OVER_HOST:
1256
 
                stop_obsessing_over_host(temp_host);
1257
 
                break;
1258
 
 
1259
 
        case CMD_SET_HOST_NOTIFICATION_NUMBER:
1260
 
                if((str=my_strtok(NULL,";"))){
1261
 
                        intval=atoi(str);
1262
 
                        set_host_notification_number(temp_host,intval);
1263
 
                        }
1264
 
                break;
1265
 
 
1266
 
        case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
1267
 
                if((str=my_strtok(NULL,";")))
1268
 
                        intval=atoi(str);
1269
 
                str=my_strtok(NULL,";");
1270
 
                if(str)
1271
 
                        buf[0]=strdup(str);
1272
 
                str=my_strtok(NULL,";");
1273
 
                if(str)
1274
 
                        buf[1]=strdup(str);
1275
 
                if(buf[0] && buf[1])
1276
 
                        host_notification(temp_host,NOTIFICATION_CUSTOM,buf[0],buf[1],intval);
1277
 
                break;
1278
 
 
1279
 
        default:
1280
 
                break;
1281
 
                }
1282
 
 
1283
 
        return OK;
1284
 
        }
1285
 
 
1286
 
 
1287
 
/* processes an external hostgroup command */
1288
 
int process_hostgroup_command(int cmd, time_t entry_time, char *args){
1289
 
        char *hostgroup_name=NULL;
1290
 
        hostgroup *temp_hostgroup=NULL;
1291
 
        hostsmember *temp_member=NULL;
1292
 
        host *temp_host=NULL;
1293
 
        service *temp_service=NULL;
1294
 
        servicesmember *temp_servicesmember=NULL;
1295
 
 
1296
 
        /* get the hostgroup name */
1297
 
        if((hostgroup_name=my_strtok(args,";"))==NULL)
1298
 
                return ERROR;
1299
 
 
1300
 
        /* find the hostgroup */
1301
 
        if((temp_hostgroup=find_hostgroup(hostgroup_name))==NULL)
1302
 
                return ERROR;
1303
 
 
1304
 
        /* loop through all hosts in the hostgroup */
1305
 
        for(temp_member=temp_hostgroup->members;temp_member!=NULL;temp_member=temp_member->next){
1306
 
 
1307
 
                if((temp_host=(host *)temp_member->host_ptr)==NULL)
1308
 
                        continue;
1309
 
 
1310
 
                switch(cmd){
 
772
        switch(cmd) {
 
773
 
 
774
                        /***************************/
 
775
                        /***** SYSTEM COMMANDS *****/
 
776
                        /***************************/
 
777
 
 
778
                case CMD_SHUTDOWN_PROCESS:
 
779
                case CMD_RESTART_PROCESS:
 
780
                        cmd_signal_process(cmd, args);
 
781
                        break;
 
782
 
 
783
                case CMD_SAVE_STATE_INFORMATION:
 
784
                        save_state_information(FALSE);
 
785
                        break;
 
786
 
 
787
                case CMD_READ_STATE_INFORMATION:
 
788
                        read_initial_state_information();
 
789
                        break;
 
790
 
 
791
                case CMD_ENABLE_NOTIFICATIONS:
 
792
                        enable_all_notifications();
 
793
                        break;
 
794
 
 
795
                case CMD_DISABLE_NOTIFICATIONS:
 
796
                        disable_all_notifications();
 
797
                        break;
 
798
 
 
799
                case CMD_START_EXECUTING_SVC_CHECKS:
 
800
                        start_executing_service_checks();
 
801
                        break;
 
802
 
 
803
                case CMD_STOP_EXECUTING_SVC_CHECKS:
 
804
                        stop_executing_service_checks();
 
805
                        break;
 
806
 
 
807
                case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
 
808
                        start_accepting_passive_service_checks();
 
809
                        break;
 
810
 
 
811
                case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
 
812
                        stop_accepting_passive_service_checks();
 
813
                        break;
 
814
 
 
815
                case CMD_START_OBSESSING_OVER_SVC_CHECKS:
 
816
                        start_obsessing_over_service_checks();
 
817
                        break;
 
818
 
 
819
                case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
 
820
                        stop_obsessing_over_service_checks();
 
821
                        break;
 
822
 
 
823
                case CMD_START_EXECUTING_HOST_CHECKS:
 
824
                        start_executing_host_checks();
 
825
                        break;
 
826
 
 
827
                case CMD_STOP_EXECUTING_HOST_CHECKS:
 
828
                        stop_executing_host_checks();
 
829
                        break;
 
830
 
 
831
                case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
 
832
                        start_accepting_passive_host_checks();
 
833
                        break;
 
834
 
 
835
                case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
 
836
                        stop_accepting_passive_host_checks();
 
837
                        break;
 
838
 
 
839
                case CMD_START_OBSESSING_OVER_HOST_CHECKS:
 
840
                        start_obsessing_over_host_checks();
 
841
                        break;
 
842
 
 
843
                case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
 
844
                        stop_obsessing_over_host_checks();
 
845
                        break;
 
846
 
 
847
                case CMD_ENABLE_EVENT_HANDLERS:
 
848
                        start_using_event_handlers();
 
849
                        break;
 
850
 
 
851
                case CMD_DISABLE_EVENT_HANDLERS:
 
852
                        stop_using_event_handlers();
 
853
                        break;
 
854
 
 
855
                case CMD_ENABLE_FLAP_DETECTION:
 
856
                        enable_flap_detection_routines();
 
857
                        break;
 
858
 
 
859
                case CMD_DISABLE_FLAP_DETECTION:
 
860
                        disable_flap_detection_routines();
 
861
                        break;
 
862
 
 
863
                case CMD_ENABLE_SERVICE_FRESHNESS_CHECKS:
 
864
                        enable_service_freshness_checks();
 
865
                        break;
 
866
 
 
867
                case CMD_DISABLE_SERVICE_FRESHNESS_CHECKS:
 
868
                        disable_service_freshness_checks();
 
869
                        break;
 
870
 
 
871
                case CMD_ENABLE_HOST_FRESHNESS_CHECKS:
 
872
                        enable_host_freshness_checks();
 
873
                        break;
 
874
 
 
875
                case CMD_DISABLE_HOST_FRESHNESS_CHECKS:
 
876
                        disable_host_freshness_checks();
 
877
                        break;
 
878
 
 
879
                case CMD_ENABLE_FAILURE_PREDICTION:
 
880
                        enable_all_failure_prediction();
 
881
                        break;
 
882
 
 
883
                case CMD_DISABLE_FAILURE_PREDICTION:
 
884
                        disable_all_failure_prediction();
 
885
                        break;
 
886
 
 
887
                case CMD_ENABLE_PERFORMANCE_DATA:
 
888
                        enable_performance_data();
 
889
                        break;
 
890
 
 
891
                case CMD_DISABLE_PERFORMANCE_DATA:
 
892
                        disable_performance_data();
 
893
                        break;
 
894
 
 
895
 
 
896
                        /***************************/
 
897
                        /*****  HOST COMMANDS  *****/
 
898
                        /***************************/
 
899
 
 
900
                case CMD_ENABLE_HOST_CHECK:
 
901
                case CMD_DISABLE_HOST_CHECK:
 
902
                case CMD_ENABLE_PASSIVE_HOST_CHECKS:
 
903
                case CMD_DISABLE_PASSIVE_HOST_CHECKS:
 
904
                case CMD_ENABLE_HOST_SVC_CHECKS:
 
905
                case CMD_DISABLE_HOST_SVC_CHECKS:
 
906
                case CMD_ENABLE_HOST_NOTIFICATIONS:
 
907
                case CMD_DISABLE_HOST_NOTIFICATIONS:
 
908
                case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
 
909
                case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
 
910
                case CMD_ENABLE_HOST_AND_CHILD_NOTIFICATIONS:
 
911
                case CMD_DISABLE_HOST_AND_CHILD_NOTIFICATIONS:
 
912
                case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
 
913
                case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
 
914
                case CMD_ENABLE_HOST_FLAP_DETECTION:
 
915
                case CMD_DISABLE_HOST_FLAP_DETECTION:
 
916
                case CMD_ENABLE_HOST_EVENT_HANDLER:
 
917
                case CMD_DISABLE_HOST_EVENT_HANDLER:
 
918
                case CMD_START_OBSESSING_OVER_HOST:
 
919
                case CMD_STOP_OBSESSING_OVER_HOST:
 
920
                case CMD_SET_HOST_NOTIFICATION_NUMBER:
 
921
                case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
 
922
                        process_host_command(cmd, entry_time, args);
 
923
                        break;
 
924
 
 
925
 
 
926
                        /*****************************/
 
927
                        /***** HOSTGROUP COMMANDS ****/
 
928
                        /*****************************/
1311
929
 
1312
930
                case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
1313
 
                        enable_host_notifications(temp_host);
1314
 
                        break;
1315
 
 
1316
931
                case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
1317
 
                        disable_host_notifications(temp_host);
1318
 
                        break;
1319
 
 
 
932
                case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
 
933
                case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
1320
934
                case CMD_ENABLE_HOSTGROUP_HOST_CHECKS:
1321
 
                        enable_host_checks(temp_host);
1322
 
                        break;
1323
 
 
1324
935
                case CMD_DISABLE_HOSTGROUP_HOST_CHECKS:
1325
 
                        disable_host_checks(temp_host);
1326
 
                        break;
1327
 
 
1328
936
                case CMD_ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS:
1329
 
                        enable_passive_host_checks(temp_host);
1330
 
                        break;
1331
 
 
1332
937
                case CMD_DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS:
1333
 
                        disable_passive_host_checks(temp_host);
 
938
                case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
 
939
                case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
 
940
                case CMD_ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS:
 
941
                case CMD_DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS:
 
942
                        process_hostgroup_command(cmd, entry_time, args);
 
943
                        break;
 
944
 
 
945
 
 
946
                        /***************************/
 
947
                        /***** SERVICE COMMANDS ****/
 
948
                        /***************************/
 
949
 
 
950
                case CMD_ENABLE_SVC_CHECK:
 
951
                case CMD_DISABLE_SVC_CHECK:
 
952
                case CMD_ENABLE_PASSIVE_SVC_CHECKS:
 
953
                case CMD_DISABLE_PASSIVE_SVC_CHECKS:
 
954
                case CMD_ENABLE_SVC_NOTIFICATIONS:
 
955
                case CMD_DISABLE_SVC_NOTIFICATIONS:
 
956
                case CMD_ENABLE_SVC_FLAP_DETECTION:
 
957
                case CMD_DISABLE_SVC_FLAP_DETECTION:
 
958
                case CMD_ENABLE_SVC_EVENT_HANDLER:
 
959
                case CMD_DISABLE_SVC_EVENT_HANDLER:
 
960
                case CMD_START_OBSESSING_OVER_SVC:
 
961
                case CMD_STOP_OBSESSING_OVER_SVC:
 
962
                case CMD_SET_SVC_NOTIFICATION_NUMBER:
 
963
                case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
 
964
                        process_service_command(cmd, entry_time, args);
 
965
                        break;
 
966
 
 
967
 
 
968
                        /********************************/
 
969
                        /***** SERVICEGROUP COMMANDS ****/
 
970
                        /********************************/
 
971
 
 
972
                case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
 
973
                case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
 
974
                case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
 
975
                case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
 
976
                case CMD_ENABLE_SERVICEGROUP_HOST_CHECKS:
 
977
                case CMD_DISABLE_SERVICEGROUP_HOST_CHECKS:
 
978
                case CMD_ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS:
 
979
                case CMD_DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS:
 
980
                case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
 
981
                case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
 
982
                case CMD_ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
 
983
                case CMD_DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
 
984
                        process_servicegroup_command(cmd, entry_time, args);
 
985
                        break;
 
986
 
 
987
 
 
988
                        /**********************************/
 
989
                        /**** CONTACT-RELATED COMMANDS ****/
 
990
                        /**********************************/
 
991
 
 
992
                case CMD_ENABLE_CONTACT_HOST_NOTIFICATIONS:
 
993
                case CMD_DISABLE_CONTACT_HOST_NOTIFICATIONS:
 
994
                case CMD_ENABLE_CONTACT_SVC_NOTIFICATIONS:
 
995
                case CMD_DISABLE_CONTACT_SVC_NOTIFICATIONS:
 
996
                        process_contact_command(cmd, entry_time, args);
 
997
                        break;
 
998
 
 
999
 
 
1000
                        /***************************************/
 
1001
                        /**** CONTACTGROUP-RELATED COMMANDS ****/
 
1002
                        /***************************************/
 
1003
 
 
1004
                case CMD_ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS:
 
1005
                case CMD_DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS:
 
1006
                case CMD_ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
 
1007
                case CMD_DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
 
1008
                        process_contactgroup_command(cmd, entry_time, args);
 
1009
                        break;
 
1010
 
 
1011
 
 
1012
                        /***************************/
 
1013
                        /**** UNSORTED COMMANDS ****/
 
1014
                        /***************************/
 
1015
 
 
1016
 
 
1017
                case CMD_ADD_HOST_COMMENT:
 
1018
                case CMD_ADD_SVC_COMMENT:
 
1019
                        cmd_add_comment(cmd, entry_time, args);
 
1020
                        break;
 
1021
 
 
1022
                case CMD_DEL_HOST_COMMENT:
 
1023
                case CMD_DEL_SVC_COMMENT:
 
1024
                        cmd_delete_comment(cmd, args);
 
1025
                        break;
 
1026
 
 
1027
                case CMD_DELAY_HOST_NOTIFICATION:
 
1028
                case CMD_DELAY_SVC_NOTIFICATION:
 
1029
                        cmd_delay_notification(cmd, args);
 
1030
                        break;
 
1031
 
 
1032
                case CMD_SCHEDULE_SVC_CHECK:
 
1033
                case CMD_SCHEDULE_FORCED_SVC_CHECK:
 
1034
                        cmd_schedule_check(cmd, args);
 
1035
                        break;
 
1036
 
 
1037
                case CMD_SCHEDULE_HOST_SVC_CHECKS:
 
1038
                case CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS:
 
1039
                        cmd_schedule_check(cmd, args);
 
1040
                        break;
 
1041
 
 
1042
                case CMD_DEL_ALL_HOST_COMMENTS:
 
1043
                case CMD_DEL_ALL_SVC_COMMENTS:
 
1044
                        cmd_delete_all_comments(cmd, args);
 
1045
                        break;
 
1046
 
 
1047
                case CMD_PROCESS_SERVICE_CHECK_RESULT:
 
1048
                        cmd_process_service_check_result(cmd, entry_time, args);
 
1049
                        break;
 
1050
 
 
1051
                case CMD_PROCESS_HOST_CHECK_RESULT:
 
1052
                        cmd_process_host_check_result(cmd, entry_time, args);
 
1053
                        break;
 
1054
 
 
1055
                case CMD_ACKNOWLEDGE_HOST_PROBLEM:
 
1056
                case CMD_ACKNOWLEDGE_SVC_PROBLEM:
 
1057
                        cmd_acknowledge_problem(cmd, args);
 
1058
                        break;
 
1059
 
 
1060
                case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
 
1061
                case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
 
1062
                        cmd_remove_acknowledgement(cmd, args);
 
1063
                        break;
 
1064
 
 
1065
                case CMD_SCHEDULE_HOST_DOWNTIME:
 
1066
                case CMD_SCHEDULE_SVC_DOWNTIME:
 
1067
                case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
 
1068
                case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
 
1069
                case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
 
1070
                case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
 
1071
                case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
 
1072
                case CMD_SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME:
 
1073
                case CMD_SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME:
 
1074
                        cmd_schedule_downtime(cmd, entry_time, args);
 
1075
                        break;
 
1076
 
 
1077
                case CMD_DEL_HOST_DOWNTIME:
 
1078
                case CMD_DEL_SVC_DOWNTIME:
 
1079
                        cmd_delete_downtime(cmd, args);
 
1080
                        break;
 
1081
 
 
1082
                case CMD_DEL_DOWNTIME_BY_HOST_NAME:
 
1083
                        cmd_delete_downtime_by_host_name(cmd, args);
 
1084
                        break;
 
1085
 
 
1086
                case CMD_DEL_DOWNTIME_BY_HOSTGROUP_NAME:
 
1087
                        cmd_delete_downtime_by_hostgroup_name(cmd, args);
 
1088
                        break;
 
1089
 
 
1090
                case CMD_DEL_DOWNTIME_BY_START_TIME_COMMENT:
 
1091
                        cmd_delete_downtime_by_start_time_comment(cmd, args);
 
1092
                        break;
 
1093
 
 
1094
                case CMD_CANCEL_ACTIVE_HOST_SVC_DOWNTIME:
 
1095
                case CMD_CANCEL_PENDING_HOST_SVC_DOWNTIME:
 
1096
                        break;
 
1097
 
 
1098
                case CMD_SCHEDULE_HOST_CHECK:
 
1099
                case CMD_SCHEDULE_FORCED_HOST_CHECK:
 
1100
                        cmd_schedule_check(cmd, args);
 
1101
                        break;
 
1102
 
 
1103
                case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
 
1104
                case CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER:
 
1105
                case CMD_CHANGE_HOST_EVENT_HANDLER:
 
1106
                case CMD_CHANGE_SVC_EVENT_HANDLER:
 
1107
                case CMD_CHANGE_HOST_CHECK_COMMAND:
 
1108
                case CMD_CHANGE_SVC_CHECK_COMMAND:
 
1109
                case CMD_CHANGE_HOST_CHECK_TIMEPERIOD:
 
1110
                case CMD_CHANGE_SVC_CHECK_TIMEPERIOD:
 
1111
                case CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD:
 
1112
                case CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD:
 
1113
                case CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD:
 
1114
                case CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD:
 
1115
                        cmd_change_object_char_var(cmd, args);
 
1116
                        break;
 
1117
 
 
1118
                case CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL:
 
1119
                case CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL:
 
1120
                case CMD_CHANGE_NORMAL_SVC_CHECK_INTERVAL:
 
1121
                case CMD_CHANGE_RETRY_SVC_CHECK_INTERVAL:
 
1122
                case CMD_CHANGE_MAX_HOST_CHECK_ATTEMPTS:
 
1123
                case CMD_CHANGE_MAX_SVC_CHECK_ATTEMPTS:
 
1124
                case CMD_CHANGE_HOST_MODATTR:
 
1125
                case CMD_CHANGE_SVC_MODATTR:
 
1126
                case CMD_CHANGE_CONTACT_MODATTR:
 
1127
                case CMD_CHANGE_CONTACT_MODHATTR:
 
1128
                case CMD_CHANGE_CONTACT_MODSATTR:
 
1129
                        cmd_change_object_int_var(cmd, args);
 
1130
                        break;
 
1131
 
 
1132
                case CMD_CHANGE_CUSTOM_HOST_VAR:
 
1133
                case CMD_CHANGE_CUSTOM_SVC_VAR:
 
1134
                case CMD_CHANGE_CUSTOM_CONTACT_VAR:
 
1135
                        cmd_change_object_custom_var(cmd, args);
 
1136
                        break;
 
1137
 
 
1138
 
 
1139
                        /***********************/
 
1140
                        /**** MISC COMMANDS ****/
 
1141
                        /***********************/
 
1142
 
 
1143
 
 
1144
                case CMD_PROCESS_FILE:
 
1145
                        cmd_process_external_commands_from_file(cmd, args);
 
1146
                        break;
 
1147
 
 
1148
 
 
1149
                        /*************************/
 
1150
                        /**** CUSTOM COMMANDS ****/
 
1151
                        /*************************/
 
1152
 
 
1153
 
 
1154
                case CMD_CUSTOM_COMMAND:
 
1155
                        /* custom commands aren't handled internally by Nagios, but may be by NEB modules */
1334
1156
                        break;
1335
1157
 
1336
1158
                default:
1337
 
 
1338
 
                        /* loop through all services on the host */
1339
 
                        for(temp_servicesmember=temp_host->services;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
1340
 
                                if((temp_service=temp_servicesmember->service_ptr)==NULL)
 
1159
                        return ERROR;
 
1160
                        break;
 
1161
                }
 
1162
 
 
1163
        return OK;
 
1164
        }
 
1165
 
 
1166
 
 
1167
/* processes an external host command */
 
1168
int process_host_command(int cmd, time_t entry_time, char *args) {
 
1169
        char *host_name = NULL;
 
1170
        host *temp_host = NULL;
 
1171
        service *temp_service = NULL;
 
1172
        servicesmember *temp_servicesmember = NULL;
 
1173
        char *str = NULL;
 
1174
        char *buf[2] = {NULL, NULL};
 
1175
        int intval = 0;
 
1176
 
 
1177
        printf("ARGS: %s\n", args);
 
1178
 
 
1179
        /* get the host name */
 
1180
        if((host_name = my_strtok(args, ";")) == NULL)
 
1181
                return ERROR;
 
1182
 
 
1183
        /* find the host */
 
1184
        if((temp_host = find_host(host_name)) == NULL)
 
1185
                return ERROR;
 
1186
 
 
1187
        switch(cmd) {
 
1188
 
 
1189
                case CMD_ENABLE_HOST_NOTIFICATIONS:
 
1190
                        enable_host_notifications(temp_host);
 
1191
                        break;
 
1192
 
 
1193
                case CMD_DISABLE_HOST_NOTIFICATIONS:
 
1194
                        disable_host_notifications(temp_host);
 
1195
                        break;
 
1196
 
 
1197
                case CMD_ENABLE_HOST_AND_CHILD_NOTIFICATIONS:
 
1198
                        enable_and_propagate_notifications(temp_host, 0, TRUE, TRUE, FALSE);
 
1199
                        break;
 
1200
 
 
1201
                case CMD_DISABLE_HOST_AND_CHILD_NOTIFICATIONS:
 
1202
                        disable_and_propagate_notifications(temp_host, 0, TRUE, TRUE, FALSE);
 
1203
                        break;
 
1204
 
 
1205
                case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
 
1206
                        enable_and_propagate_notifications(temp_host, 0, FALSE, TRUE, TRUE);
 
1207
                        break;
 
1208
 
 
1209
                case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
 
1210
                        disable_and_propagate_notifications(temp_host, 0, FALSE, TRUE, TRUE);
 
1211
                        break;
 
1212
 
 
1213
                case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
 
1214
                case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
 
1215
                        for(temp_servicesmember = temp_host->services; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {
 
1216
                                if((temp_service = temp_servicesmember->service_ptr) == NULL)
1341
1217
                                        continue;
1342
 
                                        
1343
 
                                switch(cmd){
1344
 
 
1345
 
                                case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
 
1218
                                if(cmd == CMD_ENABLE_HOST_SVC_NOTIFICATIONS)
1346
1219
                                        enable_service_notifications(temp_service);
1347
 
                                        break;
1348
 
 
1349
 
                                case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
 
1220
                                else
1350
1221
                                        disable_service_notifications(temp_service);
1351
 
                                        break;
 
1222
                                }
 
1223
                        break;
1352
1224
 
1353
 
                                case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
 
1225
                case CMD_ENABLE_HOST_SVC_CHECKS:
 
1226
                case CMD_DISABLE_HOST_SVC_CHECKS:
 
1227
                        for(temp_servicesmember = temp_host->services; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {
 
1228
                                if((temp_service = temp_servicesmember->service_ptr) == NULL)
 
1229
                                        continue;
 
1230
                                if(cmd == CMD_ENABLE_HOST_SVC_CHECKS)
1354
1231
                                        enable_service_checks(temp_service);
1355
 
                                        break;
1356
 
 
1357
 
                                case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
 
1232
                                else
1358
1233
                                        disable_service_checks(temp_service);
1359
 
                                        break;
1360
 
 
1361
 
                                case CMD_ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS:
1362
 
                                        enable_passive_service_checks(temp_service);
1363
 
                                        break;
1364
 
 
1365
 
                                case CMD_DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS:
1366
 
                                        disable_passive_service_checks(temp_service);
1367
 
                                        break;
1368
 
 
1369
 
                                default:
1370
 
                                        break;
1371
 
                                        }
1372
 
                                }
1373
 
                        
1374
 
                        break;
1375
 
                        }
1376
 
 
1377
 
                }
1378
 
 
1379
 
        return OK;
1380
 
        }
1381
 
 
1382
 
 
1383
 
 
1384
 
/* processes an external service command */
1385
 
int process_service_command(int cmd, time_t entry_time, char *args){
1386
 
        char *host_name=NULL;
1387
 
        char *svc_description=NULL;
1388
 
        service *temp_service=NULL;
1389
 
        char *str=NULL;
1390
 
        char *buf[2]={NULL,NULL};
1391
 
        int intval=0;
1392
 
 
1393
 
        /* get the host name */
1394
 
        if((host_name=my_strtok(args,";"))==NULL)
1395
 
                return ERROR;
1396
 
 
1397
 
        /* get the service description */
1398
 
        if((svc_description=my_strtok(NULL,";"))==NULL)
1399
 
                return ERROR;
1400
 
 
1401
 
        /* find the service */
1402
 
        if((temp_service=find_service(host_name,svc_description))==NULL)
1403
 
                return ERROR;
1404
 
 
1405
 
        switch(cmd){
1406
 
 
1407
 
        case CMD_ENABLE_SVC_NOTIFICATIONS:
1408
 
                enable_service_notifications(temp_service);
1409
 
                break;
1410
 
 
1411
 
        case CMD_DISABLE_SVC_NOTIFICATIONS:
1412
 
                disable_service_notifications(temp_service);
1413
 
                break;
1414
 
 
1415
 
        case CMD_ENABLE_SVC_CHECK:
1416
 
                enable_service_checks(temp_service);
1417
 
                break;
1418
 
 
1419
 
        case CMD_DISABLE_SVC_CHECK:
1420
 
                disable_service_checks(temp_service);
1421
 
                break;
1422
 
 
1423
 
        case CMD_ENABLE_SVC_EVENT_HANDLER:
1424
 
                enable_service_event_handler(temp_service);
1425
 
                break;
1426
 
 
1427
 
        case CMD_DISABLE_SVC_EVENT_HANDLER:
1428
 
                disable_service_event_handler(temp_service);
1429
 
                break;
1430
 
 
1431
 
        case CMD_ENABLE_SVC_FLAP_DETECTION:
1432
 
                enable_service_flap_detection(temp_service);
1433
 
                break;
1434
 
 
1435
 
        case CMD_DISABLE_SVC_FLAP_DETECTION:
1436
 
                disable_service_flap_detection(temp_service);
1437
 
                break;
1438
 
 
1439
 
        case CMD_ENABLE_PASSIVE_SVC_CHECKS:
1440
 
                enable_passive_service_checks(temp_service);
1441
 
                break;
1442
 
 
1443
 
        case CMD_DISABLE_PASSIVE_SVC_CHECKS:
1444
 
                disable_passive_service_checks(temp_service);
1445
 
                break;
1446
 
 
1447
 
        case CMD_START_OBSESSING_OVER_SVC:
1448
 
                start_obsessing_over_service(temp_service);
1449
 
                break;
1450
 
 
1451
 
        case CMD_STOP_OBSESSING_OVER_SVC:
1452
 
                stop_obsessing_over_service(temp_service);
1453
 
                break;
1454
 
 
1455
 
        case CMD_SET_SVC_NOTIFICATION_NUMBER:
1456
 
                if((str=my_strtok(NULL,";"))){
1457
 
                        intval=atoi(str);
1458
 
                        set_service_notification_number(temp_service,intval);
1459
 
                        }
1460
 
                break;
1461
 
 
1462
 
        case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
1463
 
                if((str=my_strtok(NULL,";")))
1464
 
                        intval=atoi(str);
1465
 
                str=my_strtok(NULL,";");
1466
 
                if(str)
1467
 
                        buf[0]=strdup(str);
1468
 
                str=my_strtok(NULL,";");
1469
 
                if(str)
1470
 
                        buf[1]=strdup(str);
1471
 
                if(buf[0] && buf[1])
1472
 
                        service_notification(temp_service,NOTIFICATION_CUSTOM,buf[0],buf[1],intval);
1473
 
                break;
1474
 
 
1475
 
        default:
1476
 
                break;
1477
 
                }
1478
 
 
1479
 
        return OK;
1480
 
        }
1481
 
 
1482
 
 
1483
 
/* processes an external servicegroup command */
1484
 
int process_servicegroup_command(int cmd, time_t entry_time, char *args){
1485
 
        char *servicegroup_name=NULL;
1486
 
        servicegroup *temp_servicegroup=NULL;
1487
 
        servicesmember *temp_member=NULL;
1488
 
        host *temp_host=NULL;
1489
 
        host *last_host=NULL;
1490
 
        service *temp_service=NULL;
1491
 
 
1492
 
        /* get the servicegroup name */
1493
 
        if((servicegroup_name=my_strtok(args,";"))==NULL)
1494
 
                return ERROR;
1495
 
 
1496
 
        /* find the servicegroup */
1497
 
        if((temp_servicegroup=find_servicegroup(servicegroup_name))==NULL)
1498
 
                return ERROR;
1499
 
 
1500
 
        switch(cmd){
1501
 
 
1502
 
        case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
1503
 
        case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
1504
 
        case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
1505
 
        case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
1506
 
        case CMD_ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
1507
 
        case CMD_DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
1508
 
 
1509
 
                /* loop through all servicegroup members */
1510
 
                for(temp_member=temp_servicegroup->members;temp_member!=NULL;temp_member=temp_member->next){
1511
 
 
1512
 
                        temp_service=find_service(temp_member->host_name,temp_member->service_description);
1513
 
                        if(temp_service==NULL)
1514
 
                                continue;
1515
 
 
1516
 
                        switch(cmd){
1517
 
 
1518
 
                        case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
1519
 
                                enable_service_notifications(temp_service);
1520
 
                                break;
1521
 
 
1522
 
                        case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
1523
 
                                disable_service_notifications(temp_service);
1524
 
                                break;
1525
 
 
1526
 
                        case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
1527
 
                                enable_service_checks(temp_service);
1528
 
                                break;
1529
 
 
1530
 
                        case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
1531
 
                                disable_service_checks(temp_service);
1532
 
                                break;
1533
 
 
1534
 
                        case CMD_ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
1535
 
                                enable_passive_service_checks(temp_service);
1536
 
                                break;
1537
 
 
1538
 
                        case CMD_DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
1539
 
                                disable_passive_service_checks(temp_service);
1540
 
                                break;
1541
 
 
1542
 
                        default:
1543
 
                                break;
1544
 
                                }
1545
 
                        }
1546
 
 
1547
 
                break;
1548
 
 
1549
 
        case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
1550
 
        case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
1551
 
        case CMD_ENABLE_SERVICEGROUP_HOST_CHECKS:
1552
 
        case CMD_DISABLE_SERVICEGROUP_HOST_CHECKS:
1553
 
        case CMD_ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS:
1554
 
        case CMD_DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS:
1555
 
 
1556
 
                /* loop through all hosts that have services belonging to the servicegroup */
1557
 
                last_host=NULL;
1558
 
                for(temp_member=temp_servicegroup->members;temp_member!=NULL;temp_member=temp_member->next){
1559
 
 
1560
 
                        if((temp_host=find_host(temp_member->host_name))==NULL)
1561
 
                                continue;
1562
 
 
1563
 
                        if(temp_host==last_host)
1564
 
                                continue;
1565
 
 
1566
 
                        switch(cmd){
1567
 
 
1568
 
                        case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
 
1234
                                }
 
1235
                        break;
 
1236
 
 
1237
                case CMD_ENABLE_HOST_CHECK:
 
1238
                        enable_host_checks(temp_host);
 
1239
                        break;
 
1240
 
 
1241
                case CMD_DISABLE_HOST_CHECK:
 
1242
                        disable_host_checks(temp_host);
 
1243
                        break;
 
1244
 
 
1245
                case CMD_ENABLE_HOST_EVENT_HANDLER:
 
1246
                        enable_host_event_handler(temp_host);
 
1247
                        break;
 
1248
 
 
1249
                case CMD_DISABLE_HOST_EVENT_HANDLER:
 
1250
                        disable_host_event_handler(temp_host);
 
1251
                        break;
 
1252
 
 
1253
                case CMD_ENABLE_HOST_FLAP_DETECTION:
 
1254
                        enable_host_flap_detection(temp_host);
 
1255
                        break;
 
1256
 
 
1257
                case CMD_DISABLE_HOST_FLAP_DETECTION:
 
1258
                        disable_host_flap_detection(temp_host);
 
1259
                        break;
 
1260
 
 
1261
                case CMD_ENABLE_PASSIVE_HOST_CHECKS:
 
1262
                        enable_passive_host_checks(temp_host);
 
1263
                        break;
 
1264
 
 
1265
                case CMD_DISABLE_PASSIVE_HOST_CHECKS:
 
1266
                        disable_passive_host_checks(temp_host);
 
1267
                        break;
 
1268
 
 
1269
                case CMD_START_OBSESSING_OVER_HOST:
 
1270
                        start_obsessing_over_host(temp_host);
 
1271
                        break;
 
1272
 
 
1273
                case CMD_STOP_OBSESSING_OVER_HOST:
 
1274
                        stop_obsessing_over_host(temp_host);
 
1275
                        break;
 
1276
 
 
1277
                case CMD_SET_HOST_NOTIFICATION_NUMBER:
 
1278
                        if((str = my_strtok(NULL, ";"))) {
 
1279
                                intval = atoi(str);
 
1280
                                set_host_notification_number(temp_host, intval);
 
1281
                                }
 
1282
                        break;
 
1283
 
 
1284
                case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
 
1285
                        if((str = my_strtok(NULL, ";")))
 
1286
                                intval = atoi(str);
 
1287
                        str = my_strtok(NULL, ";");
 
1288
                        if(str)
 
1289
                                buf[0] = strdup(str);
 
1290
                        str = my_strtok(NULL, ";");
 
1291
                        if(str)
 
1292
                                buf[1] = strdup(str);
 
1293
                        if(buf[0] && buf[1])
 
1294
                                host_notification(temp_host, NOTIFICATION_CUSTOM, buf[0], buf[1], intval);
 
1295
                        break;
 
1296
 
 
1297
                default:
 
1298
                        break;
 
1299
                }
 
1300
 
 
1301
        return OK;
 
1302
        }
 
1303
 
 
1304
 
 
1305
/* processes an external hostgroup command */
 
1306
int process_hostgroup_command(int cmd, time_t entry_time, char *args) {
 
1307
        char *hostgroup_name = NULL;
 
1308
        hostgroup *temp_hostgroup = NULL;
 
1309
        hostsmember *temp_member = NULL;
 
1310
        host *temp_host = NULL;
 
1311
        service *temp_service = NULL;
 
1312
        servicesmember *temp_servicesmember = NULL;
 
1313
 
 
1314
        /* get the hostgroup name */
 
1315
        if((hostgroup_name = my_strtok(args, ";")) == NULL)
 
1316
                return ERROR;
 
1317
 
 
1318
        /* find the hostgroup */
 
1319
        if((temp_hostgroup = find_hostgroup(hostgroup_name)) == NULL)
 
1320
                return ERROR;
 
1321
 
 
1322
        /* loop through all hosts in the hostgroup */
 
1323
        for(temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
 
1324
 
 
1325
                if((temp_host = (host *)temp_member->host_ptr) == NULL)
 
1326
                        continue;
 
1327
 
 
1328
                switch(cmd) {
 
1329
 
 
1330
                        case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
1569
1331
                                enable_host_notifications(temp_host);
1570
1332
                                break;
1571
1333
 
1572
 
                        case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
 
1334
                        case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
1573
1335
                                disable_host_notifications(temp_host);
1574
1336
                                break;
1575
1337
 
1576
 
                        case CMD_ENABLE_SERVICEGROUP_HOST_CHECKS:
 
1338
                        case CMD_ENABLE_HOSTGROUP_HOST_CHECKS:
1577
1339
                                enable_host_checks(temp_host);
1578
1340
                                break;
1579
1341
 
1580
 
                        case CMD_DISABLE_SERVICEGROUP_HOST_CHECKS:
 
1342
                        case CMD_DISABLE_HOSTGROUP_HOST_CHECKS:
1581
1343
                                disable_host_checks(temp_host);
1582
1344
                                break;
1583
1345
 
1584
 
                        case CMD_ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS:
 
1346
                        case CMD_ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS:
1585
1347
                                enable_passive_host_checks(temp_host);
1586
1348
                                break;
1587
1349
 
1588
 
                        case CMD_DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS:
 
1350
                        case CMD_DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS:
1589
1351
                                disable_passive_host_checks(temp_host);
1590
1352
                                break;
1591
1353
 
1592
1354
                        default:
 
1355
 
 
1356
                                /* loop through all services on the host */
 
1357
                                for(temp_servicesmember = temp_host->services; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {
 
1358
                                        if((temp_service = temp_servicesmember->service_ptr) == NULL)
 
1359
                                                continue;
 
1360
 
 
1361
                                        switch(cmd) {
 
1362
 
 
1363
                                                case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
 
1364
                                                        enable_service_notifications(temp_service);
 
1365
                                                        break;
 
1366
 
 
1367
                                                case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
 
1368
                                                        disable_service_notifications(temp_service);
 
1369
                                                        break;
 
1370
 
 
1371
                                                case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
 
1372
                                                        enable_service_checks(temp_service);
 
1373
                                                        break;
 
1374
 
 
1375
                                                case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
 
1376
                                                        disable_service_checks(temp_service);
 
1377
                                                        break;
 
1378
 
 
1379
                                                case CMD_ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS:
 
1380
                                                        enable_passive_service_checks(temp_service);
 
1381
                                                        break;
 
1382
 
 
1383
                                                case CMD_DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS:
 
1384
                                                        disable_passive_service_checks(temp_service);
 
1385
                                                        break;
 
1386
 
 
1387
                                                default:
 
1388
                                                        break;
 
1389
                                                }
 
1390
                                        }
 
1391
 
1593
1392
                                break;
1594
 
                                }
1595
 
 
1596
 
                        last_host=temp_host;
1597
 
                        }
1598
 
 
1599
 
                break;
1600
 
 
1601
 
        default:
1602
 
                break;
1603
 
                }
1604
 
 
1605
 
        return OK;
1606
 
        }
 
1393
                        }
 
1394
 
 
1395
                }
 
1396
 
 
1397
        return OK;
 
1398
        }
 
1399
 
 
1400
 
 
1401
 
 
1402
/* processes an external service command */
 
1403
int process_service_command(int cmd, time_t entry_time, char *args) {
 
1404
        char *host_name = NULL;
 
1405
        char *svc_description = NULL;
 
1406
        service *temp_service = NULL;
 
1407
        char *str = NULL;
 
1408
        char *buf[2] = {NULL, NULL};
 
1409
        int intval = 0;
 
1410
 
 
1411
        /* get the host name */
 
1412
        if((host_name = my_strtok(args, ";")) == NULL)
 
1413
                return ERROR;
 
1414
 
 
1415
        /* get the service description */
 
1416
        if((svc_description = my_strtok(NULL, ";")) == NULL)
 
1417
                return ERROR;
 
1418
 
 
1419
        /* find the service */
 
1420
        if((temp_service = find_service(host_name, svc_description)) == NULL)
 
1421
                return ERROR;
 
1422
 
 
1423
        switch(cmd) {
 
1424
 
 
1425
                case CMD_ENABLE_SVC_NOTIFICATIONS:
 
1426
                        enable_service_notifications(temp_service);
 
1427
                        break;
 
1428
 
 
1429
                case CMD_DISABLE_SVC_NOTIFICATIONS:
 
1430
                        disable_service_notifications(temp_service);
 
1431
                        break;
 
1432
 
 
1433
                case CMD_ENABLE_SVC_CHECK:
 
1434
                        enable_service_checks(temp_service);
 
1435
                        break;
 
1436
 
 
1437
                case CMD_DISABLE_SVC_CHECK:
 
1438
                        disable_service_checks(temp_service);
 
1439
                        break;
 
1440
 
 
1441
                case CMD_ENABLE_SVC_EVENT_HANDLER:
 
1442
                        enable_service_event_handler(temp_service);
 
1443
                        break;
 
1444
 
 
1445
                case CMD_DISABLE_SVC_EVENT_HANDLER:
 
1446
                        disable_service_event_handler(temp_service);
 
1447
                        break;
 
1448
 
 
1449
                case CMD_ENABLE_SVC_FLAP_DETECTION:
 
1450
                        enable_service_flap_detection(temp_service);
 
1451
                        break;
 
1452
 
 
1453
                case CMD_DISABLE_SVC_FLAP_DETECTION:
 
1454
                        disable_service_flap_detection(temp_service);
 
1455
                        break;
 
1456
 
 
1457
                case CMD_ENABLE_PASSIVE_SVC_CHECKS:
 
1458
                        enable_passive_service_checks(temp_service);
 
1459
                        break;
 
1460
 
 
1461
                case CMD_DISABLE_PASSIVE_SVC_CHECKS:
 
1462
                        disable_passive_service_checks(temp_service);
 
1463
                        break;
 
1464
 
 
1465
                case CMD_START_OBSESSING_OVER_SVC:
 
1466
                        start_obsessing_over_service(temp_service);
 
1467
                        break;
 
1468
 
 
1469
                case CMD_STOP_OBSESSING_OVER_SVC:
 
1470
                        stop_obsessing_over_service(temp_service);
 
1471
                        break;
 
1472
 
 
1473
                case CMD_SET_SVC_NOTIFICATION_NUMBER:
 
1474
                        if((str = my_strtok(NULL, ";"))) {
 
1475
                                intval = atoi(str);
 
1476
                                set_service_notification_number(temp_service, intval);
 
1477
                                }
 
1478
                        break;
 
1479
 
 
1480
                case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
 
1481
                        if((str = my_strtok(NULL, ";")))
 
1482
                                intval = atoi(str);
 
1483
                        str = my_strtok(NULL, ";");
 
1484
                        if(str)
 
1485
                                buf[0] = strdup(str);
 
1486
                        str = my_strtok(NULL, ";");
 
1487
                        if(str)
 
1488
                                buf[1] = strdup(str);
 
1489
                        if(buf[0] && buf[1])
 
1490
                                service_notification(temp_service, NOTIFICATION_CUSTOM, buf[0], buf[1], intval);
 
1491
                        break;
 
1492
 
 
1493
                default:
 
1494
                        break;
 
1495
                }
 
1496
 
 
1497
        return OK;
 
1498
        }
 
1499
 
 
1500
 
 
1501
/* processes an external servicegroup command */
 
1502
int process_servicegroup_command(int cmd, time_t entry_time, char *args) {
 
1503
        char *servicegroup_name = NULL;
 
1504
        servicegroup *temp_servicegroup = NULL;
 
1505
        servicesmember *temp_member = NULL;
 
1506
        host *temp_host = NULL;
 
1507
        host *last_host = NULL;
 
1508
        service *temp_service = NULL;
 
1509
 
 
1510
        /* get the servicegroup name */
 
1511
        if((servicegroup_name = my_strtok(args, ";")) == NULL)
 
1512
                return ERROR;
 
1513
 
 
1514
        /* find the servicegroup */
 
1515
        if((temp_servicegroup = find_servicegroup(servicegroup_name)) == NULL)
 
1516
                return ERROR;
 
1517
 
 
1518
        switch(cmd) {
 
1519
 
 
1520
                case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
 
1521
                case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
 
1522
                case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
 
1523
                case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
 
1524
                case CMD_ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
 
1525
                case CMD_DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
 
1526
 
 
1527
                        /* loop through all servicegroup members */
 
1528
                        for(temp_member = temp_servicegroup->members; temp_member != NULL; temp_member = temp_member->next) {
 
1529
 
 
1530
                                temp_service = find_service(temp_member->host_name, temp_member->service_description);
 
1531
                                if(temp_service == NULL)
 
1532
                                        continue;
 
1533
 
 
1534
                                switch(cmd) {
 
1535
 
 
1536
                                        case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
 
1537
                                                enable_service_notifications(temp_service);
 
1538
                                                break;
 
1539
 
 
1540
                                        case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
 
1541
                                                disable_service_notifications(temp_service);
 
1542
                                                break;
 
1543
 
 
1544
                                        case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
 
1545
                                                enable_service_checks(temp_service);
 
1546
                                                break;
 
1547
 
 
1548
                                        case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
 
1549
                                                disable_service_checks(temp_service);
 
1550
                                                break;
 
1551
 
 
1552
                                        case CMD_ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
 
1553
                                                enable_passive_service_checks(temp_service);
 
1554
                                                break;
 
1555
 
 
1556
                                        case CMD_DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
 
1557
                                                disable_passive_service_checks(temp_service);
 
1558
                                                break;
 
1559
 
 
1560
                                        default:
 
1561
                                                break;
 
1562
                                        }
 
1563
                                }
 
1564
 
 
1565
                        break;
 
1566
 
 
1567
                case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
 
1568
                case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
 
1569
                case CMD_ENABLE_SERVICEGROUP_HOST_CHECKS:
 
1570
                case CMD_DISABLE_SERVICEGROUP_HOST_CHECKS:
 
1571
                case CMD_ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS:
 
1572
                case CMD_DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS:
 
1573
 
 
1574
                        /* loop through all hosts that have services belonging to the servicegroup */
 
1575
                        last_host = NULL;
 
1576
                        for(temp_member = temp_servicegroup->members; temp_member != NULL; temp_member = temp_member->next) {
 
1577
 
 
1578
                                if((temp_host = find_host(temp_member->host_name)) == NULL)
 
1579
                                        continue;
 
1580
 
 
1581
                                if(temp_host == last_host)
 
1582
                                        continue;
 
1583
 
 
1584
                                switch(cmd) {
 
1585
 
 
1586
                                        case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
 
1587
                                                enable_host_notifications(temp_host);
 
1588
                                                break;
 
1589
 
 
1590
                                        case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
 
1591
                                                disable_host_notifications(temp_host);
 
1592
                                                break;
 
1593
 
 
1594
                                        case CMD_ENABLE_SERVICEGROUP_HOST_CHECKS:
 
1595
                                                enable_host_checks(temp_host);
 
1596
                                                break;
 
1597
 
 
1598
                                        case CMD_DISABLE_SERVICEGROUP_HOST_CHECKS:
 
1599
                                                disable_host_checks(temp_host);
 
1600
                                                break;
 
1601
 
 
1602
                                        case CMD_ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS:
 
1603
                                                enable_passive_host_checks(temp_host);
 
1604
                                                break;
 
1605
 
 
1606
                                        case CMD_DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS:
 
1607
                                                disable_passive_host_checks(temp_host);
 
1608
                                                break;
 
1609
 
 
1610
                                        default:
 
1611
                                                break;
 
1612
                                        }
 
1613
 
 
1614
                                last_host = temp_host;
 
1615
                                }
 
1616
 
 
1617
                        break;
 
1618
 
 
1619
                default:
 
1620
                        break;
 
1621
                }
 
1622
 
 
1623
        return OK;
 
1624
        }
1607
1625
 
1608
1626
 
1609
1627
 
1610
1628
/* processes an external contact command */
1611
 
int process_contact_command(int cmd, time_t entry_time, char *args){
1612
 
        char *contact_name=NULL;
1613
 
        contact *temp_contact=NULL;
 
1629
int process_contact_command(int cmd, time_t entry_time, char *args) {
 
1630
        char *contact_name = NULL;
 
1631
        contact *temp_contact = NULL;
1614
1632
 
1615
1633
        /* get the contact name */
1616
 
        if((contact_name=my_strtok(args,";"))==NULL)
 
1634
        if((contact_name = my_strtok(args, ";")) == NULL)
1617
1635
                return ERROR;
1618
1636
 
1619
1637
        /* find the contact */
1620
 
        if((temp_contact=find_contact(contact_name))==NULL)
 
1638
        if((temp_contact = find_contact(contact_name)) == NULL)
1621
1639
                return ERROR;
1622
1640
 
1623
 
        switch(cmd){
1624
 
 
1625
 
        case CMD_ENABLE_CONTACT_HOST_NOTIFICATIONS:
1626
 
                enable_contact_host_notifications(temp_contact);
1627
 
                break;
1628
 
 
1629
 
        case CMD_DISABLE_CONTACT_HOST_NOTIFICATIONS:
1630
 
                disable_contact_host_notifications(temp_contact);
1631
 
                break;
1632
 
 
1633
 
        case CMD_ENABLE_CONTACT_SVC_NOTIFICATIONS:
1634
 
                enable_contact_service_notifications(temp_contact);
1635
 
                break;
1636
 
 
1637
 
        case CMD_DISABLE_CONTACT_SVC_NOTIFICATIONS:
1638
 
                disable_contact_service_notifications(temp_contact);
1639
 
                break;
1640
 
 
1641
 
        default:
1642
 
                break;
1643
 
                }
 
1641
        switch(cmd) {
 
1642
 
 
1643
                case CMD_ENABLE_CONTACT_HOST_NOTIFICATIONS:
 
1644
                        enable_contact_host_notifications(temp_contact);
 
1645
                        break;
 
1646
 
 
1647
                case CMD_DISABLE_CONTACT_HOST_NOTIFICATIONS:
 
1648
                        disable_contact_host_notifications(temp_contact);
 
1649
                        break;
 
1650
 
 
1651
                case CMD_ENABLE_CONTACT_SVC_NOTIFICATIONS:
 
1652
                        enable_contact_service_notifications(temp_contact);
 
1653
                        break;
 
1654
 
 
1655
                case CMD_DISABLE_CONTACT_SVC_NOTIFICATIONS:
 
1656
                        disable_contact_service_notifications(temp_contact);
 
1657
                        break;
 
1658
 
 
1659
                default:
 
1660
                        break;
 
1661
                }
1644
1662
 
1645
1663
        return OK;
1646
 
        }
 
1664
        }
1647
1665
 
1648
1666
 
1649
1667
/* processes an external contactgroup command */
1650
 
int process_contactgroup_command(int cmd, time_t entry_time, char *args){
1651
 
        char *contactgroup_name=NULL;
1652
 
        contactgroup *temp_contactgroup=NULL;
1653
 
        contactsmember *temp_member=NULL;
1654
 
        contact *temp_contact=NULL;
 
1668
int process_contactgroup_command(int cmd, time_t entry_time, char *args) {
 
1669
        char *contactgroup_name = NULL;
 
1670
        contactgroup *temp_contactgroup = NULL;
 
1671
        contactsmember *temp_member = NULL;
 
1672
        contact *temp_contact = NULL;
1655
1673
 
1656
1674
        /* get the contactgroup name */
1657
 
        if((contactgroup_name=my_strtok(args,";"))==NULL)
 
1675
        if((contactgroup_name = my_strtok(args, ";")) == NULL)
1658
1676
                return ERROR;
1659
1677
 
1660
1678
        /* find the contactgroup */
1661
 
        if((temp_contactgroup=find_contactgroup(contactgroup_name))==NULL)
 
1679
        if((temp_contactgroup = find_contactgroup(contactgroup_name)) == NULL)
1662
1680
                return ERROR;
1663
1681
 
1664
 
        switch(cmd){
1665
 
 
1666
 
        case CMD_ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS:
1667
 
        case CMD_DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS:
1668
 
        case CMD_ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
1669
 
        case CMD_DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
1670
 
 
1671
 
                /* loop through all contactgroup members */
1672
 
                for(temp_member=temp_contactgroup->members;temp_member!=NULL;temp_member=temp_member->next){
1673
 
 
1674
 
                        if((temp_contact=temp_member->contact_ptr)==NULL)
1675
 
                                continue;
1676
 
 
1677
 
                        switch(cmd){
1678
 
 
1679
 
                        case CMD_ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS:
1680
 
                                enable_contact_host_notifications(temp_contact);
1681
 
                                break;
1682
 
 
1683
 
                        case CMD_DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS:
1684
 
                                disable_contact_host_notifications(temp_contact);
1685
 
                                break;
1686
 
 
1687
 
                        case CMD_ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
1688
 
                                enable_contact_service_notifications(temp_contact);
1689
 
                                break;
1690
 
 
1691
 
                        case CMD_DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
1692
 
                                disable_contact_service_notifications(temp_contact);
1693
 
                                break;
1694
 
 
1695
 
                        default:
1696
 
                                break;
1697
 
                                }
1698
 
                        }
1699
 
 
1700
 
                break;
1701
 
 
1702
 
        default:
1703
 
                break;
1704
 
                }
 
1682
        switch(cmd) {
 
1683
 
 
1684
                case CMD_ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS:
 
1685
                case CMD_DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS:
 
1686
                case CMD_ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
 
1687
                case CMD_DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
 
1688
 
 
1689
                        /* loop through all contactgroup members */
 
1690
                        for(temp_member = temp_contactgroup->members; temp_member != NULL; temp_member = temp_member->next) {
 
1691
 
 
1692
                                if((temp_contact = temp_member->contact_ptr) == NULL)
 
1693
                                        continue;
 
1694
 
 
1695
                                switch(cmd) {
 
1696
 
 
1697
                                        case CMD_ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS:
 
1698
                                                enable_contact_host_notifications(temp_contact);
 
1699
                                                break;
 
1700
 
 
1701
                                        case CMD_DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS:
 
1702
                                                disable_contact_host_notifications(temp_contact);
 
1703
                                                break;
 
1704
 
 
1705
                                        case CMD_ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
 
1706
                                                enable_contact_service_notifications(temp_contact);
 
1707
                                                break;
 
1708
 
 
1709
                                        case CMD_DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
 
1710
                                                disable_contact_service_notifications(temp_contact);
 
1711
                                                break;
 
1712
 
 
1713
                                        default:
 
1714
                                                break;
 
1715
                                        }
 
1716
                                }
 
1717
 
 
1718
                        break;
 
1719
 
 
1720
                default:
 
1721
                        break;
 
1722
                }
1705
1723
 
1706
1724
        return OK;
1707
 
        }
 
1725
        }
1708
1726
 
1709
1727
 
1710
1728
 
1713
1731
/******************************************************************/
1714
1732
 
1715
1733
/* adds a host or service comment to the status log */
1716
 
int cmd_add_comment(int cmd,time_t entry_time,char *args){
1717
 
        char *temp_ptr=NULL;
1718
 
        host *temp_host=NULL;
1719
 
        service *temp_service=NULL;
1720
 
        char *host_name=NULL;
1721
 
        char *svc_description=NULL;
1722
 
        char *user=NULL;
1723
 
        char *comment_data=NULL;
1724
 
        int persistent=0;
1725
 
        int result=0;
 
1734
int cmd_add_comment(int cmd, time_t entry_time, char *args) {
 
1735
        char *temp_ptr = NULL;
 
1736
        host *temp_host = NULL;
 
1737
        service *temp_service = NULL;
 
1738
        char *host_name = NULL;
 
1739
        char *svc_description = NULL;
 
1740
        char *user = NULL;
 
1741
        char *comment_data = NULL;
 
1742
        int persistent = 0;
 
1743
        int result = 0;
1726
1744
 
1727
1745
        /* get the host name */
1728
 
        if((host_name=my_strtok(args,";"))==NULL)
 
1746
        if((host_name = my_strtok(args, ";")) == NULL)
1729
1747
                return ERROR;
1730
1748
 
1731
1749
        /* if we're adding a service comment...  */
1732
 
        if(cmd==CMD_ADD_SVC_COMMENT){
 
1750
        if(cmd == CMD_ADD_SVC_COMMENT) {
1733
1751
 
1734
1752
                /* get the service description */
1735
 
                if((svc_description=my_strtok(NULL,";"))==NULL)
 
1753
                if((svc_description = my_strtok(NULL, ";")) == NULL)
1736
1754
                        return ERROR;
1737
1755
 
1738
1756
                /* verify that the service is valid */
1739
 
                if((temp_service=find_service(host_name,svc_description))==NULL)
 
1757
                if((temp_service = find_service(host_name, svc_description)) == NULL)
1740
1758
                        return ERROR;
1741
 
                }
 
1759
                }
1742
1760
 
1743
1761
        /* else verify that the host is valid */
1744
 
        if((temp_host=find_host(host_name))==NULL)
 
1762
        if((temp_host = find_host(host_name)) == NULL)
1745
1763
                return ERROR;
1746
1764
 
1747
1765
        /* get the persistent flag */
1748
 
        if((temp_ptr=my_strtok(NULL,";"))==NULL)
 
1766
        if((temp_ptr = my_strtok(NULL, ";")) == NULL)
1749
1767
                return ERROR;
1750
 
        persistent=atoi(temp_ptr);
1751
 
        if(persistent>1)
1752
 
                persistent=1;
1753
 
        else if(persistent<0)
1754
 
                persistent=0;
 
1768
        persistent = atoi(temp_ptr);
 
1769
        if(persistent > 1)
 
1770
                persistent = 1;
 
1771
        else if(persistent < 0)
 
1772
                persistent = 0;
1755
1773
 
1756
1774
        /* get the name of the user who entered the comment */
1757
 
        if((user=my_strtok(NULL,";"))==NULL)
 
1775
        if((user = my_strtok(NULL, ";")) == NULL)
1758
1776
                return ERROR;
1759
1777
 
1760
1778
        /* get the comment */
1761
 
        if((comment_data=my_strtok(NULL,"\n"))==NULL)
 
1779
        if((comment_data = my_strtok(NULL, "\n")) == NULL)
1762
1780
                return ERROR;
1763
1781
 
1764
1782
        /* add the comment */
1765
 
        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);
 
1783
        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);
1766
1784
 
1767
 
        if(result<0)
 
1785
        if(result < 0)
1768
1786
                return ERROR;
1769
1787
 
1770
1788
        return OK;
1771
 
        }
 
1789
        }
1772
1790
 
1773
1791
 
1774
1792
 
1775
1793
/* removes a host or service comment from the status log */
1776
 
int cmd_delete_comment(int cmd,char *args){
1777
 
        unsigned long comment_id=0L;
 
1794
int cmd_delete_comment(int cmd, char *args) {
 
1795
        unsigned long comment_id = 0L;
1778
1796
 
1779
1797
        /* get the comment id we should delete */
1780
 
        if((comment_id=strtoul(args,NULL,10))==0)
 
1798
        if((comment_id = strtoul(args, NULL, 10)) == 0)
1781
1799
                return ERROR;
1782
1800
 
1783
1801
        /* delete the specified comment */
1784
 
        if(cmd==CMD_DEL_HOST_COMMENT)
 
1802
        if(cmd == CMD_DEL_HOST_COMMENT)
1785
1803
                delete_host_comment(comment_id);
1786
1804
        else
1787
1805
                delete_service_comment(comment_id);
1788
1806
 
1789
1807
        return OK;
1790
 
        }
 
1808
        }
1791
1809
 
1792
1810
 
1793
1811
 
1794
1812
/* removes all comments associated with a host or service from the status log */
1795
 
int cmd_delete_all_comments(int cmd,char *args){
1796
 
        service *temp_service=NULL;
1797
 
        host *temp_host=NULL;
1798
 
        char *host_name=NULL;
1799
 
        char *svc_description=NULL;
 
1813
int cmd_delete_all_comments(int cmd, char *args) {
 
1814
        service *temp_service = NULL;
 
1815
        host *temp_host = NULL;
 
1816
        char *host_name = NULL;
 
1817
        char *svc_description = NULL;
1800
1818
 
1801
1819
        /* get the host name */
1802
 
        if((host_name=my_strtok(args,";"))==NULL)
 
1820
        if((host_name = my_strtok(args, ";")) == NULL)
1803
1821
                return ERROR;
1804
1822
 
1805
1823
        /* if we're deleting service comments...  */
1806
 
        if(cmd==CMD_DEL_ALL_SVC_COMMENTS){
 
1824
        if(cmd == CMD_DEL_ALL_SVC_COMMENTS) {
1807
1825
 
1808
1826
                /* get the service description */
1809
 
                if((svc_description=my_strtok(NULL,";"))==NULL)
 
1827
                if((svc_description = my_strtok(NULL, ";")) == NULL)
1810
1828
                        return ERROR;
1811
1829
 
1812
1830
                /* verify that the service is valid */
1813
 
                if((temp_service=find_service(host_name,svc_description))==NULL)
 
1831
                if((temp_service = find_service(host_name, svc_description)) == NULL)
1814
1832
                        return ERROR;
1815
 
                }
 
1833
                }
1816
1834
 
1817
1835
        /* else verify that the host is valid */
1818
 
        if((temp_host=find_host(host_name))==NULL)
 
1836
        if((temp_host = find_host(host_name)) == NULL)
1819
1837
                return ERROR;
1820
1838
 
1821
1839
        /* delete comments */
1822
 
        delete_all_comments((cmd==CMD_DEL_ALL_HOST_COMMENTS)?HOST_COMMENT:SERVICE_COMMENT,host_name,svc_description);
 
1840
        delete_all_comments((cmd == CMD_DEL_ALL_HOST_COMMENTS) ? HOST_COMMENT : SERVICE_COMMENT, host_name, svc_description);
1823
1841
 
1824
1842
        return OK;
1825
 
        }
 
1843
        }
1826
1844
 
1827
1845
 
1828
1846
 
1829
1847
/* delays a host or service notification for given number of minutes */
1830
 
int cmd_delay_notification(int cmd,char *args){
1831
 
        char *temp_ptr=NULL;
1832
 
        host *temp_host=NULL;
1833
 
        service *temp_service=NULL;
1834
 
        char *host_name=NULL;
1835
 
        char *svc_description=NULL;
1836
 
        time_t delay_time=0L;
 
1848
int cmd_delay_notification(int cmd, char *args) {
 
1849
        char *temp_ptr = NULL;
 
1850
        host *temp_host = NULL;
 
1851
        service *temp_service = NULL;
 
1852
        char *host_name = NULL;
 
1853
        char *svc_description = NULL;
 
1854
        time_t delay_time = 0L;
1837
1855
 
1838
1856
        /* get the host name */
1839
 
        if((host_name=my_strtok(args,";"))==NULL)
 
1857
        if((host_name = my_strtok(args, ";")) == NULL)
1840
1858
                return ERROR;
1841
1859
 
1842
1860
        /* if this is a service notification delay...  */
1843
 
        if(cmd==CMD_DELAY_SVC_NOTIFICATION){
 
1861
        if(cmd == CMD_DELAY_SVC_NOTIFICATION) {
1844
1862
 
1845
1863
                /* get the service description */
1846
 
                if((svc_description=my_strtok(NULL,";"))==NULL)
 
1864
                if((svc_description = my_strtok(NULL, ";")) == NULL)
1847
1865
                        return ERROR;
1848
1866
 
1849
1867
                /* verify that the service is valid */
1850
 
                if((temp_service=find_service(host_name,svc_description))==NULL)
 
1868
                if((temp_service = find_service(host_name, svc_description)) == NULL)
1851
1869
                        return ERROR;
1852
 
                }
 
1870
                }
1853
1871
 
1854
1872
        /* else verify that the host is valid */
1855
 
        else{
 
1873
        else {
1856
1874
 
1857
 
                if((temp_host=find_host(host_name))==NULL)
 
1875
                if((temp_host = find_host(host_name)) == NULL)
1858
1876
                        return ERROR;
1859
 
                }
 
1877
                }
1860
1878
 
1861
1879
        /* get the time that we should delay until... */
1862
 
        if((temp_ptr=my_strtok(NULL,"\n"))==NULL)
 
1880
        if((temp_ptr = my_strtok(NULL, "\n")) == NULL)
1863
1881
                return ERROR;
1864
 
        delay_time=strtoul(temp_ptr,NULL,10);
 
1882
        delay_time = strtoul(temp_ptr, NULL, 10);
1865
1883
 
1866
1884
        /* delay the next notification... */
1867
 
        if(cmd==CMD_DELAY_HOST_NOTIFICATION)
1868
 
                temp_host->next_host_notification=delay_time;
 
1885
        if(cmd == CMD_DELAY_HOST_NOTIFICATION)
 
1886
                temp_host->next_host_notification = delay_time;
1869
1887
        else
1870
 
                temp_service->next_notification=delay_time;
1871
 
        
 
1888
                temp_service->next_notification = delay_time;
 
1889
 
1872
1890
        return OK;
1873
 
        }
 
1891
        }
1874
1892
 
1875
1893
 
1876
1894
 
1877
1895
/* schedules a host check at a particular time */
1878
 
int cmd_schedule_check(int cmd,char *args){
1879
 
        char *temp_ptr=NULL;
1880
 
        host *temp_host=NULL;
1881
 
        service *temp_service=NULL;
1882
 
        servicesmember *temp_servicesmember=NULL;
1883
 
        char *host_name=NULL;
1884
 
        char *svc_description=NULL;
1885
 
        time_t delay_time=0L;
 
1896
int cmd_schedule_check(int cmd, char *args) {
 
1897
        char *temp_ptr = NULL;
 
1898
        host *temp_host = NULL;
 
1899
        service *temp_service = NULL;
 
1900
        servicesmember *temp_servicesmember = NULL;
 
1901
        char *host_name = NULL;
 
1902
        char *svc_description = NULL;
 
1903
        time_t delay_time = 0L;
1886
1904
 
1887
1905
        /* get the host name */
1888
 
        if((host_name=my_strtok(args,";"))==NULL)
 
1906
        if((host_name = my_strtok(args, ";")) == NULL)
1889
1907
                return ERROR;
1890
1908
 
1891
 
        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){
 
1909
        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) {
1892
1910
 
1893
1911
                /* verify that the host is valid */
1894
 
                if((temp_host=find_host(host_name))==NULL)
 
1912
                if((temp_host = find_host(host_name)) == NULL)
1895
1913
                        return ERROR;
1896
 
                }
1897
 
        
1898
 
        else{
 
1914
                }
 
1915
 
 
1916
        else {
1899
1917
 
1900
1918
                /* get the service description */
1901
 
                if((svc_description=my_strtok(NULL,";"))==NULL)
 
1919
                if((svc_description = my_strtok(NULL, ";")) == NULL)
1902
1920
                        return ERROR;
1903
1921
 
1904
1922
                /* verify that the service is valid */
1905
 
                if((temp_service=find_service(host_name,svc_description))==NULL)
 
1923
                if((temp_service = find_service(host_name, svc_description)) == NULL)
1906
1924
                        return ERROR;
1907
 
                }
 
1925
                }
1908
1926
 
1909
1927
        /* get the next check time */
1910
 
        if((temp_ptr=my_strtok(NULL,"\n"))==NULL)
 
1928
        if((temp_ptr = my_strtok(NULL, "\n")) == NULL)
1911
1929
                return ERROR;
1912
 
        delay_time=strtoul(temp_ptr,NULL,10);
 
1930
        delay_time = strtoul(temp_ptr, NULL, 10);
1913
1931
 
1914
1932
        /* schedule the host check */
1915
 
        if(cmd==CMD_SCHEDULE_HOST_CHECK || cmd==CMD_SCHEDULE_FORCED_HOST_CHECK)
1916
 
                schedule_host_check(temp_host,delay_time,(cmd==CMD_SCHEDULE_FORCED_HOST_CHECK)?CHECK_OPTION_FORCE_EXECUTION:CHECK_OPTION_NONE);
 
1933
        if(cmd == CMD_SCHEDULE_HOST_CHECK || cmd == CMD_SCHEDULE_FORCED_HOST_CHECK)
 
1934
                schedule_host_check(temp_host, delay_time, (cmd == CMD_SCHEDULE_FORCED_HOST_CHECK) ? CHECK_OPTION_FORCE_EXECUTION : CHECK_OPTION_NONE);
1917
1935
 
1918
1936
        /* schedule service checks */
1919
 
        else if(cmd==CMD_SCHEDULE_HOST_SVC_CHECKS || cmd==CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS){
1920
 
                for(temp_servicesmember=temp_host->services;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
1921
 
                        if((temp_service=temp_servicesmember->service_ptr)==NULL)
 
1937
        else if(cmd == CMD_SCHEDULE_HOST_SVC_CHECKS || cmd == CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS) {
 
1938
                for(temp_servicesmember = temp_host->services; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {
 
1939
                        if((temp_service = temp_servicesmember->service_ptr) == NULL)
1922
1940
                                continue;
1923
 
                        schedule_service_check(temp_service,delay_time,(cmd==CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS)?CHECK_OPTION_FORCE_EXECUTION:CHECK_OPTION_NONE);
1924
 
                        }
1925
 
                }
 
1941
                        schedule_service_check(temp_service, delay_time, (cmd == CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS) ? CHECK_OPTION_FORCE_EXECUTION : CHECK_OPTION_NONE);
 
1942
                        }
 
1943
                }
1926
1944
        else
1927
 
                schedule_service_check(temp_service,delay_time,(cmd==CMD_SCHEDULE_FORCED_SVC_CHECK)?CHECK_OPTION_FORCE_EXECUTION:CHECK_OPTION_NONE);
 
1945
                schedule_service_check(temp_service, delay_time, (cmd == CMD_SCHEDULE_FORCED_SVC_CHECK) ? CHECK_OPTION_FORCE_EXECUTION : CHECK_OPTION_NONE);
1928
1946
 
1929
1947
        return OK;
1930
 
        }
 
1948
        }
1931
1949
 
1932
1950
 
1933
1951
 
1934
1952
/* schedules all service checks on a host for a particular time */
1935
 
int cmd_schedule_host_service_checks(int cmd,char *args, int force){
1936
 
        char *temp_ptr=NULL;
1937
 
        service *temp_service=NULL;
1938
 
        servicesmember *temp_servicesmember=NULL;
1939
 
        host *temp_host=NULL;
1940
 
        char *host_name=NULL;
1941
 
        time_t delay_time=0L;
 
1953
int cmd_schedule_host_service_checks(int cmd, char *args, int force) {
 
1954
        char *temp_ptr = NULL;
 
1955
        service *temp_service = NULL;
 
1956
        servicesmember *temp_servicesmember = NULL;
 
1957
        host *temp_host = NULL;
 
1958
        char *host_name = NULL;
 
1959
        time_t delay_time = 0L;
1942
1960
 
1943
1961
        /* get the host name */
1944
 
        if((host_name=my_strtok(args,";"))==NULL)
 
1962
        if((host_name = my_strtok(args, ";")) == NULL)
1945
1963
                return ERROR;
1946
1964
 
1947
1965
        /* verify that the host is valid */
1948
 
        if((temp_host=find_host(host_name))==NULL)
 
1966
        if((temp_host = find_host(host_name)) == NULL)
1949
1967
                return ERROR;
1950
1968
 
1951
1969
        /* get the next check time */
1952
 
        if((temp_ptr=my_strtok(NULL,"\n"))==NULL)
 
1970
        if((temp_ptr = my_strtok(NULL, "\n")) == NULL)
1953
1971
                return ERROR;
1954
 
        delay_time=strtoul(temp_ptr,NULL,10);
 
1972
        delay_time = strtoul(temp_ptr, NULL, 10);
1955
1973
 
1956
1974
        /* reschedule all services on the specified host */
1957
 
        for(temp_servicesmember=temp_host->services;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
1958
 
                if((temp_service=temp_servicesmember->service_ptr)==NULL)
 
1975
        for(temp_servicesmember = temp_host->services; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {
 
1976
                if((temp_service = temp_servicesmember->service_ptr) == NULL)
1959
1977
                        continue;
1960
 
                schedule_service_check(temp_service,delay_time,(force==TRUE)?CHECK_OPTION_FORCE_EXECUTION:CHECK_OPTION_NONE);
1961
 
                }
 
1978
                schedule_service_check(temp_service, delay_time, (force == TRUE) ? CHECK_OPTION_FORCE_EXECUTION : CHECK_OPTION_NONE);
 
1979
                }
1962
1980
 
1963
1981
        return OK;
1964
 
        }
 
1982
        }
1965
1983
 
1966
1984
 
1967
1985
 
1968
1986
 
1969
1987
/* schedules a program shutdown or restart */
1970
 
int cmd_signal_process(int cmd, char *args){
1971
 
        time_t scheduled_time=0L;
1972
 
        char *temp_ptr=NULL;
1973
 
        int result=OK;
 
1988
int cmd_signal_process(int cmd, char *args) {
 
1989
        time_t scheduled_time = 0L;
 
1990
        char *temp_ptr = NULL;
 
1991
        int result = OK;
1974
1992
 
1975
1993
        /* get the time to schedule the event */
1976
 
        if((temp_ptr=my_strtok(args,"\n"))==NULL)
1977
 
                scheduled_time=0L;
 
1994
        if((temp_ptr = my_strtok(args, "\n")) == NULL)
 
1995
                scheduled_time = 0L;
1978
1996
        else
1979
 
                scheduled_time=strtoul(temp_ptr,NULL,10);
 
1997
                scheduled_time = strtoul(temp_ptr, NULL, 10);
1980
1998
 
1981
1999
        /* add a scheduled program shutdown or restart to the event list */
1982
 
        result=schedule_new_event((cmd==CMD_SHUTDOWN_PROCESS)?EVENT_PROGRAM_SHUTDOWN:EVENT_PROGRAM_RESTART,TRUE,scheduled_time,FALSE,0,NULL,FALSE,NULL,NULL,0);
 
2000
        result = schedule_new_event((cmd == CMD_SHUTDOWN_PROCESS) ? EVENT_PROGRAM_SHUTDOWN : EVENT_PROGRAM_RESTART, TRUE, scheduled_time, FALSE, 0, NULL, FALSE, NULL, NULL, 0);
1983
2001
 
1984
2002
        return result;
1985
 
        }
 
2003
        }
1986
2004
 
1987
2005
 
1988
2006
 
1989
2007
/* processes results of an external service check */
1990
 
int cmd_process_service_check_result(int cmd,time_t check_time,char *args){
1991
 
        char *temp_ptr=NULL;
1992
 
        char *host_name=NULL;
1993
 
        char *svc_description=NULL;
1994
 
        int return_code=0;
1995
 
        char *output=NULL;
1996
 
        int result=0;
 
2008
int cmd_process_service_check_result(int cmd, time_t check_time, char *args) {
 
2009
        char *temp_ptr = NULL;
 
2010
        char *host_name = NULL;
 
2011
        char *svc_description = NULL;
 
2012
        int return_code = 0;
 
2013
        char *output = NULL;
 
2014
        int result = 0;
1997
2015
 
1998
2016
        /* get the host name */
1999
 
        if((temp_ptr=my_strtok(args,";"))==NULL)
 
2017
        if((temp_ptr = my_strtok(args, ";")) == NULL)
2000
2018
                return ERROR;
2001
 
        host_name=(char *)strdup(temp_ptr);
 
2019
        host_name = (char *)strdup(temp_ptr);
2002
2020
 
2003
2021
        /* get the service description */
2004
 
        if((temp_ptr=my_strtok(NULL,";"))==NULL){
 
2022
        if((temp_ptr = my_strtok(NULL, ";")) == NULL) {
2005
2023
                my_free(host_name);
2006
2024
                return ERROR;
2007
 
                }
2008
 
        svc_description=(char *)strdup(temp_ptr);
 
2025
                }
 
2026
        svc_description = (char *)strdup(temp_ptr);
2009
2027
 
2010
2028
        /* get the service check return code */
2011
 
        if((temp_ptr=my_strtok(NULL,";"))==NULL){
 
2029
        if((temp_ptr = my_strtok(NULL, ";")) == NULL) {
2012
2030
                my_free(host_name);
2013
2031
                my_free(svc_description);
2014
2032
                return ERROR;
2015
 
                }
2016
 
        return_code=atoi(temp_ptr);
 
2033
                }
 
2034
        return_code = atoi(temp_ptr);
2017
2035
 
2018
2036
        /* get the plugin output (may be empty) */
2019
 
        if((temp_ptr=my_strtok(NULL,"\n"))==NULL)
2020
 
                output=(char *)strdup("");
 
2037
        if((temp_ptr = my_strtok(NULL, "\n")) == NULL)
 
2038
                output = (char *)strdup("");
2021
2039
        else
2022
 
                output=(char *)strdup(temp_ptr);
 
2040
                output = (char *)strdup(temp_ptr);
2023
2041
 
2024
2042
        /* submit the passive check result */
2025
 
        result=process_passive_service_check(check_time,host_name,svc_description,return_code,output);
 
2043
        result = process_passive_service_check(check_time, host_name, svc_description, return_code, output);
2026
2044
 
2027
2045
        /* free memory */
2028
2046
        my_free(host_name);
2030
2048
        my_free(output);
2031
2049
 
2032
2050
        return result;
2033
 
        }
 
2051
        }
2034
2052
 
2035
2053
 
2036
2054
 
2037
2055
/* submits a passive service check result for later processing */
2038
 
int process_passive_service_check(time_t check_time, char *host_name, char *svc_description, int return_code, char *output){
2039
 
        passive_check_result *new_pcr=NULL;
2040
 
        host *temp_host=NULL;
2041
 
        service *temp_service=NULL;
2042
 
        char *real_host_name=NULL;
 
2056
int process_passive_service_check(time_t check_time, char *host_name, char *svc_description, int return_code, char *output) {
 
2057
        passive_check_result *new_pcr = NULL;
 
2058
        host *temp_host = NULL;
 
2059
        service *temp_service = NULL;
 
2060
        char *real_host_name = NULL;
2043
2061
        struct timeval tv;
2044
 
        int result=OK;
 
2062
        int result = OK;
2045
2063
 
2046
2064
        /* skip this service check result if we aren't accepting passive service checks */
2047
 
        if(accept_passive_service_checks==FALSE)
 
2065
        if(accept_passive_service_checks == FALSE)
2048
2066
                return ERROR;
2049
2067
 
2050
2068
        /* make sure we have all required data */
2051
 
        if(host_name==NULL || svc_description==NULL || output==NULL)
 
2069
        if(host_name == NULL || svc_description == NULL || output == NULL)
2052
2070
                return ERROR;
2053
2071
 
2054
2072
        /* find the host by its name or address */
2055
 
        if(find_host(host_name)!=NULL)
2056
 
                real_host_name=host_name;
2057
 
        else{
2058
 
                for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
2059
 
                        if(!strcmp(host_name,temp_host->address)){
2060
 
                                real_host_name=temp_host->name;
 
2073
        if(find_host(host_name) != NULL)
 
2074
                real_host_name = host_name;
 
2075
        else {
 
2076
                for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
 
2077
                        if(!strcmp(host_name, temp_host->address)) {
 
2078
                                real_host_name = temp_host->name;
2061
2079
                                break;
2062
 
                                }
2063
 
                        }
2064
 
                }
 
2080
                                }
 
2081
                        }
 
2082
                }
2065
2083
 
2066
2084
        /* we couldn't find the host */
2067
 
        if(real_host_name==NULL){
2068
 
                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);
 
2085
        if(real_host_name == NULL) {
 
2086
                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);
2069
2087
                return ERROR;
2070
2088
                }
2071
2089
 
2072
2090
        /* make sure the service exists */
2073
 
        if((temp_service=find_service(real_host_name,svc_description))==NULL){
2074
 
                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);
 
2091
        if((temp_service = find_service(real_host_name, svc_description)) == NULL) {
 
2092
                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);
2075
2093
                return ERROR;
2076
2094
                }
2077
2095
 
2078
2096
        /* skip this is we aren't accepting passive checks for this service */
2079
 
        if(temp_service->accept_passive_service_checks==FALSE)
 
2097
        if(temp_service->accept_passive_service_checks == FALSE)
2080
2098
                return ERROR;
2081
2099
 
2082
2100
        /* allocate memory for the passive check result */
2083
 
        new_pcr=(passive_check_result *)malloc(sizeof(passive_check_result));
2084
 
        if(new_pcr==NULL)
 
2101
        new_pcr = (passive_check_result *)malloc(sizeof(passive_check_result));
 
2102
        if(new_pcr == NULL)
2085
2103
                return ERROR;
2086
2104
 
2087
2105
        /* initialize vars */
2088
 
        new_pcr->object_check_type=SERVICE_CHECK;
2089
 
        new_pcr->host_name=NULL;
2090
 
        new_pcr->service_description=NULL;
2091
 
        new_pcr->output=NULL;
2092
 
        new_pcr->next=NULL;
 
2106
        new_pcr->object_check_type = SERVICE_CHECK;
 
2107
        new_pcr->host_name = NULL;
 
2108
        new_pcr->service_description = NULL;
 
2109
        new_pcr->output = NULL;
 
2110
        new_pcr->next = NULL;
2093
2111
 
2094
2112
        /* save string vars */
2095
 
        if((new_pcr->host_name=(char *)strdup(real_host_name))==NULL)
2096
 
                result=ERROR;
2097
 
        if((new_pcr->service_description=(char *)strdup(svc_description))==NULL)
2098
 
                result=ERROR;
2099
 
        if((new_pcr->output=(char *)strdup(output))==NULL)
2100
 
                result=ERROR;
 
2113
        if((new_pcr->host_name = (char *)strdup(real_host_name)) == NULL)
 
2114
                result = ERROR;
 
2115
        if((new_pcr->service_description = (char *)strdup(svc_description)) == NULL)
 
2116
                result = ERROR;
 
2117
        if((new_pcr->output = (char *)strdup(output)) == NULL)
 
2118
                result = ERROR;
2101
2119
 
2102
2120
        /* handle errors */
2103
 
        if(result==ERROR){
 
2121
        if(result == ERROR) {
2104
2122
                my_free(new_pcr->output);
2105
2123
                my_free(new_pcr->service_description);
2106
2124
                my_free(new_pcr->host_name);
2107
2125
                my_free(new_pcr);
2108
2126
                return ERROR;
2109
 
                }
 
2127
                }
2110
2128
 
2111
2129
        /* save the return code */
2112
 
        new_pcr->return_code=return_code;
 
2130
        new_pcr->return_code = return_code;
2113
2131
 
2114
2132
        /* make sure the return code is within bounds */
2115
 
        if(new_pcr->return_code<0 || new_pcr->return_code>3)
2116
 
                new_pcr->return_code=STATE_UNKNOWN;
 
2133
        if(new_pcr->return_code < 0 || new_pcr->return_code > 3)
 
2134
                new_pcr->return_code = STATE_UNKNOWN;
2117
2135
 
2118
 
        new_pcr->check_time=check_time;
 
2136
        new_pcr->check_time = check_time;
2119
2137
 
2120
2138
        /* calculate latency */
2121
 
        gettimeofday(&tv,NULL);
2122
 
        new_pcr->latency=(double)((double)(tv.tv_sec-check_time)+(double)(tv.tv_usec/1000.0)/1000.0);
2123
 
        if(new_pcr->latency<0.0)
2124
 
                new_pcr->latency=0.0;
 
2139
        gettimeofday(&tv, NULL);
 
2140
        new_pcr->latency = (double)((double)(tv.tv_sec - check_time) + (double)(tv.tv_usec / 1000.0) / 1000.0);
 
2141
        if(new_pcr->latency < 0.0)
 
2142
                new_pcr->latency = 0.0;
2125
2143
 
2126
2144
        /* add the passive check result to the end of the list in memory */
2127
 
        if(passive_check_result_list==NULL)
2128
 
                passive_check_result_list=new_pcr;
 
2145
        if(passive_check_result_list == NULL)
 
2146
                passive_check_result_list = new_pcr;
2129
2147
        else
2130
 
                passive_check_result_list_tail->next=new_pcr;
2131
 
        passive_check_result_list_tail=new_pcr;
 
2148
                passive_check_result_list_tail->next = new_pcr;
 
2149
        passive_check_result_list_tail = new_pcr;
2132
2150
 
2133
2151
        return OK;
2134
 
        }
 
2152
        }
2135
2153
 
2136
2154
 
2137
2155
 
2138
2156
/* process passive host check result */
2139
 
int cmd_process_host_check_result(int cmd,time_t check_time,char *args){
2140
 
        char *temp_ptr=NULL;
2141
 
        char *host_name=NULL;
2142
 
        int return_code=0;
2143
 
        char *output=NULL;
2144
 
        int result=0;
 
2157
int cmd_process_host_check_result(int cmd, time_t check_time, char *args) {
 
2158
        char *temp_ptr = NULL;
 
2159
        char *host_name = NULL;
 
2160
        int return_code = 0;
 
2161
        char *output = NULL;
 
2162
        int result = 0;
2145
2163
 
2146
2164
        /* get the host name */
2147
 
        if((temp_ptr=my_strtok(args,";"))==NULL)
 
2165
        if((temp_ptr = my_strtok(args, ";")) == NULL)
2148
2166
                return ERROR;
2149
 
        host_name=(char *)strdup(temp_ptr);
 
2167
        host_name = (char *)strdup(temp_ptr);
2150
2168
 
2151
2169
        /* get the host check return code */
2152
 
        if((temp_ptr=my_strtok(NULL,";"))==NULL){
 
2170
        if((temp_ptr = my_strtok(NULL, ";")) == NULL) {
2153
2171
                my_free(host_name);
2154
2172
                return ERROR;
2155
 
                }
2156
 
        return_code=atoi(temp_ptr);
 
2173
                }
 
2174
        return_code = atoi(temp_ptr);
2157
2175
 
2158
2176
        /* get the plugin output (may be empty) */
2159
 
        if((temp_ptr=my_strtok(NULL,"\n"))==NULL)
2160
 
                output=(char *)strdup("");
 
2177
        if((temp_ptr = my_strtok(NULL, "\n")) == NULL)
 
2178
                output = (char *)strdup("");
2161
2179
        else
2162
 
                output=(char *)strdup(temp_ptr);
 
2180
                output = (char *)strdup(temp_ptr);
2163
2181
 
2164
2182
        /* submit the check result */
2165
 
        result=process_passive_host_check(check_time,host_name,return_code,output);
 
2183
        result = process_passive_host_check(check_time, host_name, return_code, output);
2166
2184
 
2167
2185
        /* free memory */
2168
2186
        my_free(host_name);
2169
2187
        my_free(output);
2170
2188
 
2171
2189
        return result;
2172
 
        }
 
2190
        }
2173
2191
 
2174
2192
 
2175
2193
/* process passive host check result */
2176
 
int process_passive_host_check(time_t check_time, char *host_name, int return_code, char *output){
2177
 
        passive_check_result *new_pcr=NULL;
2178
 
        host *temp_host=NULL;
2179
 
        char *real_host_name=NULL;
 
2194
int process_passive_host_check(time_t check_time, char *host_name, int return_code, char *output) {
 
2195
        passive_check_result *new_pcr = NULL;
 
2196
        host *temp_host = NULL;
 
2197
        char *real_host_name = NULL;
2180
2198
        struct timeval tv;
2181
 
        int result=OK;
 
2199
        int result = OK;
2182
2200
 
2183
2201
        /* skip this host check result if we aren't accepting passive host checks */
2184
 
        if(accept_passive_service_checks==FALSE)
 
2202
        if(accept_passive_service_checks == FALSE)
2185
2203
                return ERROR;
2186
2204
 
2187
2205
        /* make sure we have all required data */
2188
 
        if(host_name==NULL || output==NULL)
 
2206
        if(host_name == NULL || output == NULL)
2189
2207
                return ERROR;
2190
2208
 
2191
2209
        /* make sure we have a reasonable return code */
2192
 
        if(return_code<0 || return_code>2)
 
2210
        if(return_code < 0 || return_code > 2)
2193
2211
                return ERROR;
2194
2212
 
2195
2213
        /* find the host by its name or address */
2196
 
        if((temp_host=find_host(host_name))!=NULL)
2197
 
                real_host_name=host_name;
2198
 
        else{
2199
 
                for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
2200
 
                        if(!strcmp(host_name,temp_host->address)){
2201
 
                                real_host_name=temp_host->name;
 
2214
        if((temp_host = find_host(host_name)) != NULL)
 
2215
                real_host_name = host_name;
 
2216
        else {
 
2217
                for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
 
2218
                        if(!strcmp(host_name, temp_host->address)) {
 
2219
                                real_host_name = temp_host->name;
2202
2220
                                break;
2203
 
                                }
2204
 
                        }
2205
 
                }
 
2221
                                }
 
2222
                        }
 
2223
                }
2206
2224
 
2207
2225
        /* we couldn't find the host */
2208
 
        if(temp_host==NULL){
2209
 
                logit(NSLOG_RUNTIME_WARNING,TRUE,"Warning:  Passive check result was received for host '%s', but the host could not be found!\n",host_name);
 
2226
        if(temp_host == NULL) {
 
2227
                logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning:  Passive check result was received for host '%s', but the host could not be found!\n", host_name);
2210
2228
                return ERROR;
2211
2229
                }
2212
2230
 
2213
2231
        /* skip this is we aren't accepting passive checks for this host */
2214
 
        if(temp_host->accept_passive_host_checks==FALSE)
 
2232
        if(temp_host->accept_passive_host_checks == FALSE)
2215
2233
                return ERROR;
2216
2234
 
2217
2235
        /* allocate memory for the passive check result */
2218
 
        new_pcr=(passive_check_result *)malloc(sizeof(passive_check_result));
2219
 
        if(new_pcr==NULL)
 
2236
        new_pcr = (passive_check_result *)malloc(sizeof(passive_check_result));
 
2237
        if(new_pcr == NULL)
2220
2238
                return ERROR;
2221
2239
 
2222
2240
        /* initialize vars */
2223
 
        new_pcr->object_check_type=HOST_CHECK;
2224
 
        new_pcr->host_name=NULL;
2225
 
        new_pcr->service_description=NULL;
2226
 
        new_pcr->output=NULL;
2227
 
        new_pcr->next=NULL;
 
2241
        new_pcr->object_check_type = HOST_CHECK;
 
2242
        new_pcr->host_name = NULL;
 
2243
        new_pcr->service_description = NULL;
 
2244
        new_pcr->output = NULL;
 
2245
        new_pcr->next = NULL;
2228
2246
 
2229
2247
        /* save string vars */
2230
 
        if((new_pcr->host_name=(char *)strdup(real_host_name))==NULL)
2231
 
                result=ERROR;
2232
 
        if((new_pcr->output=(char *)strdup(output))==NULL)
2233
 
                result=ERROR;
 
2248
        if((new_pcr->host_name = (char *)strdup(real_host_name)) == NULL)
 
2249
                result = ERROR;
 
2250
        if((new_pcr->output = (char *)strdup(output)) == NULL)
 
2251
                result = ERROR;
2234
2252
 
2235
2253
        /* handle errors */
2236
 
        if(result==ERROR){
 
2254
        if(result == ERROR) {
2237
2255
                my_free(new_pcr->output);
2238
2256
                my_free(new_pcr->service_description);
2239
2257
                my_free(new_pcr->host_name);
2240
2258
                my_free(new_pcr);
2241
2259
                return ERROR;
2242
 
                }
 
2260
                }
2243
2261
 
2244
2262
        /* save the return code */
2245
 
        new_pcr->return_code=return_code;
 
2263
        new_pcr->return_code = return_code;
2246
2264
 
2247
2265
        /* make sure the return code is within bounds */
2248
 
        if(new_pcr->return_code<0 || new_pcr->return_code>3)
2249
 
                new_pcr->return_code=STATE_UNKNOWN;
 
2266
        if(new_pcr->return_code < 0 || new_pcr->return_code > 3)
 
2267
                new_pcr->return_code = STATE_UNKNOWN;
2250
2268
 
2251
 
        new_pcr->check_time=check_time;
 
2269
        new_pcr->check_time = check_time;
2252
2270
 
2253
2271
        /* calculate latency */
2254
 
        gettimeofday(&tv,NULL);
2255
 
        new_pcr->latency=(double)((double)(tv.tv_sec-check_time)+(double)(tv.tv_usec/1000.0)/1000.0);
2256
 
        if(new_pcr->latency<0.0)
2257
 
                new_pcr->latency=0.0;
 
2272
        gettimeofday(&tv, NULL);
 
2273
        new_pcr->latency = (double)((double)(tv.tv_sec - check_time) + (double)(tv.tv_usec / 1000.0) / 1000.0);
 
2274
        if(new_pcr->latency < 0.0)
 
2275
                new_pcr->latency = 0.0;
2258
2276
 
2259
2277
        /* add the passive check result to the end of the list in memory */
2260
 
        if(passive_check_result_list==NULL)
2261
 
                passive_check_result_list=new_pcr;
 
2278
        if(passive_check_result_list == NULL)
 
2279
                passive_check_result_list = new_pcr;
2262
2280
        else
2263
 
                passive_check_result_list_tail->next=new_pcr;
2264
 
        passive_check_result_list_tail=new_pcr;
 
2281
                passive_check_result_list_tail->next = new_pcr;
 
2282
        passive_check_result_list_tail = new_pcr;
2265
2283
 
2266
2284
        return OK;
2267
 
        }
 
2285
        }
2268
2286
 
2269
2287
 
2270
2288
 
2271
2289
/* acknowledges a host or service problem */
2272
 
int cmd_acknowledge_problem(int cmd,char *args){
2273
 
        service *temp_service=NULL;
2274
 
        host *temp_host=NULL;
2275
 
        char *host_name=NULL;
2276
 
        char *svc_description=NULL;
2277
 
        char *ack_author=NULL;
2278
 
        char *ack_data=NULL;
2279
 
        char *temp_ptr=NULL;
2280
 
        int type=ACKNOWLEDGEMENT_NORMAL;
2281
 
        int notify=TRUE;
2282
 
        int persistent=TRUE;
 
2290
int cmd_acknowledge_problem(int cmd, char *args) {
 
2291
        service *temp_service = NULL;
 
2292
        host *temp_host = NULL;
 
2293
        char *host_name = NULL;
 
2294
        char *svc_description = NULL;
 
2295
        char *ack_author = NULL;
 
2296
        char *ack_data = NULL;
 
2297
        char *temp_ptr = NULL;
 
2298
        int type = ACKNOWLEDGEMENT_NORMAL;
 
2299
        int notify = TRUE;
 
2300
        int persistent = TRUE;
2283
2301
 
2284
2302
        /* get the host name */
2285
 
        if((host_name=my_strtok(args,";"))==NULL)
 
2303
        if((host_name = my_strtok(args, ";")) == NULL)
2286
2304
                return ERROR;
2287
2305
 
2288
2306
        /* verify that the host is valid */
2289
 
        if((temp_host=find_host(host_name))==NULL)
 
2307
        if((temp_host = find_host(host_name)) == NULL)
2290
2308
                return ERROR;
2291
2309
 
2292
2310
        /* this is a service acknowledgement */
2293
 
        if(cmd==CMD_ACKNOWLEDGE_SVC_PROBLEM){
 
2311
        if(cmd == CMD_ACKNOWLEDGE_SVC_PROBLEM) {
2294
2312
 
2295
2313
                /* get the service name */
2296
 
                if((svc_description=my_strtok(NULL,";"))==NULL)
 
2314
                if((svc_description = my_strtok(NULL, ";")) == NULL)
2297
2315
                        return ERROR;
2298
2316
 
2299
2317
                /* verify that the service is valid */
2300
 
                if((temp_service=find_service(temp_host->name,svc_description))==NULL)
 
2318
                if((temp_service = find_service(temp_host->name, svc_description)) == NULL)
2301
2319
                        return ERROR;
2302
 
                }
 
2320
                }
2303
2321
 
2304
2322
        /* get the type */
2305
 
        if((temp_ptr=my_strtok(NULL,";"))==NULL)
 
2323
        if((temp_ptr = my_strtok(NULL, ";")) == NULL)
2306
2324
                return ERROR;
2307
 
        type=atoi(temp_ptr);
 
2325
        type = atoi(temp_ptr);
2308
2326
 
2309
2327
        /* get the notification option */
2310
 
        if((temp_ptr=my_strtok(NULL,";"))==NULL)
 
2328
        if((temp_ptr = my_strtok(NULL, ";")) == NULL)
2311
2329
                return ERROR;
2312
 
        notify=(atoi(temp_ptr)>0)?TRUE:FALSE;
 
2330
        notify = (atoi(temp_ptr) > 0) ? TRUE : FALSE;
2313
2331
 
2314
2332
        /* get the persistent option */
2315
 
        if((temp_ptr=my_strtok(NULL,";"))==NULL)
 
2333
        if((temp_ptr = my_strtok(NULL, ";")) == NULL)
2316
2334
                return ERROR;
2317
 
        persistent=(atoi(temp_ptr)>0)?TRUE:FALSE;
 
2335
        persistent = (atoi(temp_ptr) > 0) ? TRUE : FALSE;
2318
2336
 
2319
2337
        /* get the acknowledgement author */
2320
 
        if((temp_ptr=my_strtok(NULL,";"))==NULL)
 
2338
        if((temp_ptr = my_strtok(NULL, ";")) == NULL)
2321
2339
                return ERROR;
2322
 
        ack_author=(char *)strdup(temp_ptr);
2323
 
        
 
2340
        ack_author = (char *)strdup(temp_ptr);
 
2341
 
2324
2342
        /* get the acknowledgement data */
2325
 
        if((temp_ptr=my_strtok(NULL,"\n"))==NULL){
 
2343
        if((temp_ptr = my_strtok(NULL, "\n")) == NULL) {
2326
2344
                my_free(ack_author);
2327
2345
                return ERROR;
2328
 
                }
2329
 
        ack_data=(char *)strdup(temp_ptr);
2330
 
        
 
2346
                }
 
2347
        ack_data = (char *)strdup(temp_ptr);
 
2348
 
2331
2349
        /* acknowledge the host problem */
2332
 
        if(cmd==CMD_ACKNOWLEDGE_HOST_PROBLEM)
2333
 
                acknowledge_host_problem(temp_host,ack_author,ack_data,type,notify,persistent);
 
2350
        if(cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM)
 
2351
                acknowledge_host_problem(temp_host, ack_author, ack_data, type, notify, persistent);
2334
2352
 
2335
2353
        /* acknowledge the service problem */
2336
2354
        else
2337
 
                acknowledge_service_problem(temp_service,ack_author,ack_data,type,notify,persistent);
 
2355
                acknowledge_service_problem(temp_service, ack_author, ack_data, type, notify, persistent);
2338
2356
 
2339
2357
        /* free memory */
2340
2358
        my_free(ack_author);
2341
2359
        my_free(ack_data);
2342
2360
 
2343
2361
        return OK;
2344
 
        }
 
2362
        }
2345
2363
 
2346
2364
 
2347
2365
 
2348
2366
/* removes a host or service acknowledgement */
2349
 
int cmd_remove_acknowledgement(int cmd,char *args){
2350
 
        service *temp_service=NULL;
2351
 
        host *temp_host=NULL;
2352
 
        char *host_name=NULL;
2353
 
        char *svc_description=NULL;
 
2367
int cmd_remove_acknowledgement(int cmd, char *args) {
 
2368
        service *temp_service = NULL;
 
2369
        host *temp_host = NULL;
 
2370
        char *host_name = NULL;
 
2371
        char *svc_description = NULL;
2354
2372
 
2355
2373
        /* get the host name */
2356
 
        if((host_name=my_strtok(args,";"))==NULL)
 
2374
        if((host_name = my_strtok(args, ";")) == NULL)
2357
2375
                return ERROR;
2358
2376
 
2359
2377
        /* verify that the host is valid */
2360
 
        if((temp_host=find_host(host_name))==NULL)
 
2378
        if((temp_host = find_host(host_name)) == NULL)
2361
2379
                return ERROR;
2362
2380
 
2363
2381
        /* we are removing a service acknowledgement */
2364
 
        if(cmd==CMD_REMOVE_SVC_ACKNOWLEDGEMENT){
 
2382
        if(cmd == CMD_REMOVE_SVC_ACKNOWLEDGEMENT) {
2365
2383
 
2366
2384
                /* get the service name */
2367
 
                if((svc_description=my_strtok(NULL,";"))==NULL)
 
2385
                if((svc_description = my_strtok(NULL, ";")) == NULL)
2368
2386
                        return ERROR;
2369
2387
 
2370
2388
                /* verify that the service is valid */
2371
 
                if((temp_service=find_service(temp_host->name,svc_description))==NULL)
 
2389
                if((temp_service = find_service(temp_host->name, svc_description)) == NULL)
2372
2390
                        return ERROR;
2373
 
                }
 
2391
                }
2374
2392
 
2375
2393
        /* acknowledge the host problem */
2376
 
        if(cmd==CMD_REMOVE_HOST_ACKNOWLEDGEMENT)
 
2394
        if(cmd == CMD_REMOVE_HOST_ACKNOWLEDGEMENT)
2377
2395
                remove_host_acknowledgement(temp_host);
2378
2396
 
2379
2397
        /* acknowledge the service problem */
2381
2399
                remove_service_acknowledgement(temp_service);
2382
2400
 
2383
2401
        return OK;
2384
 
        }
 
2402
        }
2385
2403
 
2386
2404
 
2387
2405
 
2388
2406
/* schedules downtime for a specific host or service */
2389
 
int cmd_schedule_downtime(int cmd, time_t entry_time, char *args){
2390
 
        servicesmember *temp_servicesmember=NULL;
2391
 
        service *temp_service=NULL;
2392
 
        host *temp_host=NULL;
2393
 
        host *last_host=NULL;
2394
 
        hostgroup *temp_hostgroup=NULL;
2395
 
        hostsmember *temp_hgmember=NULL;
2396
 
        servicegroup *temp_servicegroup=NULL;
2397
 
        servicesmember *temp_sgmember=NULL;
2398
 
        char *host_name=NULL;
2399
 
        char *hostgroup_name=NULL;
2400
 
        char *servicegroup_name=NULL;
2401
 
        char *svc_description=NULL;
2402
 
        char *temp_ptr=NULL;
2403
 
        time_t start_time=0L;
2404
 
        time_t end_time=0L;
2405
 
        int fixed=0;
2406
 
        unsigned long triggered_by=0L;
2407
 
        unsigned long duration=0L;
2408
 
        char *author=NULL;
2409
 
        char *comment_data=NULL;
2410
 
        unsigned long downtime_id=0L;
2411
 
 
2412
 
        if(cmd==CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME || cmd==CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME){
2413
 
                
 
2407
int cmd_schedule_downtime(int cmd, time_t entry_time, char *args) {
 
2408
        servicesmember *temp_servicesmember = NULL;
 
2409
        service *temp_service = NULL;
 
2410
        host *temp_host = NULL;
 
2411
        host *last_host = NULL;
 
2412
        hostgroup *temp_hostgroup = NULL;
 
2413
        hostsmember *temp_hgmember = NULL;
 
2414
        servicegroup *temp_servicegroup = NULL;
 
2415
        servicesmember *temp_sgmember = NULL;
 
2416
        char *host_name = NULL;
 
2417
        char *hostgroup_name = NULL;
 
2418
        char *servicegroup_name = NULL;
 
2419
        char *svc_description = NULL;
 
2420
        char *temp_ptr = NULL;
 
2421
        time_t start_time = 0L;
 
2422
        time_t end_time = 0L;
 
2423
        int fixed = 0;
 
2424
        unsigned long triggered_by = 0L;
 
2425
        unsigned long duration = 0L;
 
2426
        char *author = NULL;
 
2427
        char *comment_data = NULL;
 
2428
        unsigned long downtime_id = 0L;
 
2429
 
 
2430
        if(cmd == CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME) {
 
2431
 
2414
2432
                /* get the hostgroup name */
2415
 
                if((hostgroup_name=my_strtok(args,";"))==NULL)
 
2433
                if((hostgroup_name = my_strtok(args, ";")) == NULL)
2416
2434
                        return ERROR;
2417
2435
 
2418
2436
                /* verify that the hostgroup is valid */
2419
 
                if((temp_hostgroup=find_hostgroup(hostgroup_name))==NULL)
 
2437
                if((temp_hostgroup = find_hostgroup(hostgroup_name)) == NULL)
2420
2438
                        return ERROR;
2421
 
                }
 
2439
                }
2422
2440
 
2423
 
        else if(cmd==CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME || cmd==CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME){
 
2441
        else if(cmd == CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME || cmd == CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME) {
2424
2442
 
2425
2443
                /* get the servicegroup name */
2426
 
                if((servicegroup_name=my_strtok(args,";"))==NULL)
 
2444
                if((servicegroup_name = my_strtok(args, ";")) == NULL)
2427
2445
                        return ERROR;
2428
2446
 
2429
2447
                /* verify that the servicegroup is valid */
2430
 
                if((temp_servicegroup=find_servicegroup(servicegroup_name))==NULL)
 
2448
                if((temp_servicegroup = find_servicegroup(servicegroup_name)) == NULL)
2431
2449
                        return ERROR;
2432
 
                }
 
2450
                }
2433
2451
 
2434
 
        else{
 
2452
        else {
2435
2453
 
2436
2454
                /* get the host name */
2437
 
                if((host_name=my_strtok(args,";"))==NULL)
 
2455
                if((host_name = my_strtok(args, ";")) == NULL)
2438
2456
                        return ERROR;
2439
2457
 
2440
2458
                /* verify that the host is valid */
2441
 
                if((temp_host=find_host(host_name))==NULL)
 
2459
                if((temp_host = find_host(host_name)) == NULL)
2442
2460
                        return ERROR;
2443
2461
 
2444
2462
                /* this is a service downtime */
2445
 
                if(cmd==CMD_SCHEDULE_SVC_DOWNTIME){
 
2463
                if(cmd == CMD_SCHEDULE_SVC_DOWNTIME) {
2446
2464
 
2447
2465
                        /* get the service name */
2448
 
                        if((svc_description=my_strtok(NULL,";"))==NULL)
 
2466
                        if((svc_description = my_strtok(NULL, ";")) == NULL)
2449
2467
                                return ERROR;
2450
2468
 
2451
2469
                        /* verify that the service is valid */
2452
 
                        if((temp_service=find_service(temp_host->name,svc_description))==NULL)
 
2470
                        if((temp_service = find_service(temp_host->name, svc_description)) == NULL)
2453
2471
                                return ERROR;
2454
 
                        }
2455
 
                }
 
2472
                        }
 
2473
                }
2456
2474
 
2457
2475
        /* get the start time */
2458
 
        if((temp_ptr=my_strtok(NULL,";"))==NULL)
 
2476
        if((temp_ptr = my_strtok(NULL, ";")) == NULL)
2459
2477
                return ERROR;
2460
 
        start_time=(time_t)strtoul(temp_ptr,NULL,10);
 
2478
        start_time = (time_t)strtoul(temp_ptr, NULL, 10);
2461
2479
 
2462
2480
        /* get the end time */
2463
 
        if((temp_ptr=my_strtok(NULL,";"))==NULL)
 
2481
        if((temp_ptr = my_strtok(NULL, ";")) == NULL)
2464
2482
                return ERROR;
2465
 
        end_time=(time_t)strtoul(temp_ptr,NULL,10);
 
2483
        end_time = (time_t)strtoul(temp_ptr, NULL, 10);
2466
2484
 
2467
2485
        /* get the fixed flag */
2468
 
        if((temp_ptr=my_strtok(NULL,";"))==NULL)
 
2486
        if((temp_ptr = my_strtok(NULL, ";")) == NULL)
2469
2487
                return ERROR;
2470
 
        fixed=atoi(temp_ptr);
 
2488
        fixed = atoi(temp_ptr);
2471
2489
 
2472
2490
        /* get the trigger id */
2473
 
        if((temp_ptr=my_strtok(NULL,";"))==NULL)
 
2491
        if((temp_ptr = my_strtok(NULL, ";")) == NULL)
2474
2492
                return ERROR;
2475
 
        triggered_by=strtoul(temp_ptr,NULL,10);
 
2493
        triggered_by = strtoul(temp_ptr, NULL, 10);
2476
2494
 
2477
2495
        /* get the duration */
2478
 
        if((temp_ptr=my_strtok(NULL,";"))==NULL)
 
2496
        if((temp_ptr = my_strtok(NULL, ";")) == NULL)
2479
2497
                return ERROR;
2480
 
        duration=strtoul(temp_ptr,NULL,10);
 
2498
        duration = strtoul(temp_ptr, NULL, 10);
2481
2499
 
2482
2500
        /* get the author */
2483
 
        if((author=my_strtok(NULL,";"))==NULL)
 
2501
        if((author = my_strtok(NULL, ";")) == NULL)
2484
2502
                return ERROR;
2485
2503
 
2486
2504
        /* get the comment */
2487
 
        if((comment_data=my_strtok(NULL,";"))==NULL)
2488
 
                return ERROR;
 
2505
        if((comment_data = my_strtok(NULL, ";")) == NULL)
 
2506
                return ERROR;
 
2507
 
 
2508
        /* check if flexible downtime demanded and duration set
 
2509
           to non-zero.
 
2510
           according to the documentation, a flexible downtime is
 
2511
           started between start and end time and will last for
 
2512
           "duration" seconds. strtoul converts a NULL value to 0
 
2513
           so if set to 0, bail out as a duration>0 is needed.     */
 
2514
 
 
2515
        if(fixed == 0 && duration == 0)
 
2516
                return ERROR;
 
2517
 
2489
2518
 
2490
2519
        /* duration should be auto-calculated, not user-specified */
2491
 
        if(fixed>0)
2492
 
                duration=(unsigned long)(end_time-start_time);
 
2520
        if(fixed > 0)
 
2521
                duration = (unsigned long)(end_time - start_time);
2493
2522
 
2494
2523
        /* schedule downtime */
2495
 
        switch(cmd){
2496
 
 
2497
 
        case CMD_SCHEDULE_HOST_DOWNTIME:
2498
 
                schedule_downtime(HOST_DOWNTIME,host_name,NULL,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&downtime_id);
2499
 
                break;
2500
 
 
2501
 
        case CMD_SCHEDULE_SVC_DOWNTIME:
2502
 
                schedule_downtime(SERVICE_DOWNTIME,host_name,svc_description,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&downtime_id);
2503
 
                break;
2504
 
 
2505
 
        case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
2506
 
                for(temp_servicesmember=temp_host->services;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
2507
 
                        if((temp_service=temp_servicesmember->service_ptr)==NULL)
2508
 
                                continue;
2509
 
                        schedule_downtime(SERVICE_DOWNTIME,host_name,temp_service->description,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&downtime_id);
2510
 
                        }
2511
 
                break;
2512
 
 
2513
 
        case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
2514
 
                for(temp_hgmember=temp_hostgroup->members;temp_hgmember!=NULL;temp_hgmember=temp_hgmember->next)
2515
 
                        schedule_downtime(HOST_DOWNTIME,temp_hgmember->host_name,NULL,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&downtime_id);
2516
 
                break;
2517
 
 
2518
 
        case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
2519
 
                for(temp_hgmember=temp_hostgroup->members;temp_hgmember!=NULL;temp_hgmember=temp_hgmember->next){
2520
 
                        if((temp_host=temp_hgmember->host_ptr)==NULL)
2521
 
                                continue;
2522
 
                        for(temp_servicesmember=temp_host->services;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
2523
 
                                if((temp_service=temp_servicesmember->service_ptr)==NULL)
2524
 
                                        continue;
2525
 
                                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);
2526
 
                                }
2527
 
                        }
2528
 
                break;
2529
 
 
2530
 
        case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
2531
 
                last_host=NULL;
2532
 
                for(temp_sgmember=temp_servicegroup->members;temp_sgmember!=NULL;temp_sgmember=temp_sgmember->next){
2533
 
                        temp_host=find_host(temp_sgmember->host_name);
2534
 
                        if(temp_host==NULL)
2535
 
                                continue;
2536
 
                        if(last_host==temp_host)
2537
 
                                continue;
2538
 
                        schedule_downtime(HOST_DOWNTIME,temp_sgmember->host_name,NULL,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&downtime_id);
2539
 
                        last_host=temp_host;
2540
 
                        }
2541
 
                break;
2542
 
 
2543
 
        case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
2544
 
                for(temp_sgmember=temp_servicegroup->members;temp_sgmember!=NULL;temp_sgmember=temp_sgmember->next)
2545
 
                        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);
2546
 
                break;
2547
 
 
2548
 
        case CMD_SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME:
2549
 
 
2550
 
                /* schedule downtime for "parent" host */
2551
 
                schedule_downtime(HOST_DOWNTIME,host_name,NULL,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&downtime_id);
2552
 
 
2553
 
                /* schedule (non-triggered) downtime for all child hosts */
2554
 
                schedule_and_propagate_downtime(temp_host,entry_time,author,comment_data,start_time,end_time,fixed,0,duration);
2555
 
                break;
2556
 
 
2557
 
        case CMD_SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME:
2558
 
 
2559
 
                /* schedule downtime for "parent" host */
2560
 
                schedule_downtime(HOST_DOWNTIME,host_name,NULL,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,&downtime_id);
2561
 
 
2562
 
                /* schedule triggered downtime for all child hosts */
2563
 
                schedule_and_propagate_downtime(temp_host,entry_time,author,comment_data,start_time,end_time,fixed,downtime_id,duration);
2564
 
                break;
2565
 
 
2566
 
        default:
2567
 
                break;
2568
 
                }
 
2524
        switch(cmd) {
 
2525
 
 
2526
                case CMD_SCHEDULE_HOST_DOWNTIME:
 
2527
                        schedule_downtime(HOST_DOWNTIME, host_name, NULL, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, &downtime_id);
 
2528
                        break;
 
2529
 
 
2530
                case CMD_SCHEDULE_SVC_DOWNTIME:
 
2531
                        schedule_downtime(SERVICE_DOWNTIME, host_name, svc_description, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, &downtime_id);
 
2532
                        break;
 
2533
 
 
2534
                case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
 
2535
                        for(temp_servicesmember = temp_host->services; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {
 
2536
                                if((temp_service = temp_servicesmember->service_ptr) == NULL)
 
2537
                                        continue;
 
2538
                                schedule_downtime(SERVICE_DOWNTIME, host_name, temp_service->description, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, &downtime_id);
 
2539
                                }
 
2540
                        break;
 
2541
 
 
2542
                case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
 
2543
                        for(temp_hgmember = temp_hostgroup->members; temp_hgmember != NULL; temp_hgmember = temp_hgmember->next)
 
2544
                                schedule_downtime(HOST_DOWNTIME, temp_hgmember->host_name, NULL, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, &downtime_id);
 
2545
                        break;
 
2546
 
 
2547
                case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
 
2548
                        for(temp_hgmember = temp_hostgroup->members; temp_hgmember != NULL; temp_hgmember = temp_hgmember->next) {
 
2549
                                if((temp_host = temp_hgmember->host_ptr) == NULL)
 
2550
                                        continue;
 
2551
                                for(temp_servicesmember = temp_host->services; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {
 
2552
                                        if((temp_service = temp_servicesmember->service_ptr) == NULL)
 
2553
                                                continue;
 
2554
                                        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);
 
2555
                                        }
 
2556
                                }
 
2557
                        break;
 
2558
 
 
2559
                case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
 
2560
                        last_host = NULL;
 
2561
                        for(temp_sgmember = temp_servicegroup->members; temp_sgmember != NULL; temp_sgmember = temp_sgmember->next) {
 
2562
                                temp_host = find_host(temp_sgmember->host_name);
 
2563
                                if(temp_host == NULL)
 
2564
                                        continue;
 
2565
                                if(last_host == temp_host)
 
2566
                                        continue;
 
2567
                                schedule_downtime(HOST_DOWNTIME, temp_sgmember->host_name, NULL, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, &downtime_id);
 
2568
                                last_host = temp_host;
 
2569
                                }
 
2570
                        break;
 
2571
 
 
2572
                case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
 
2573
                        for(temp_sgmember = temp_servicegroup->members; temp_sgmember != NULL; temp_sgmember = temp_sgmember->next)
 
2574
                                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);
 
2575
                        break;
 
2576
 
 
2577
                case CMD_SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME:
 
2578
 
 
2579
                        /* schedule downtime for "parent" host */
 
2580
                        schedule_downtime(HOST_DOWNTIME, host_name, NULL, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, &downtime_id);
 
2581
 
 
2582
                        /* schedule (non-triggered) downtime for all child hosts */
 
2583
                        schedule_and_propagate_downtime(temp_host, entry_time, author, comment_data, start_time, end_time, fixed, 0, duration);
 
2584
                        break;
 
2585
 
 
2586
                case CMD_SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME:
 
2587
 
 
2588
                        /* schedule downtime for "parent" host */
 
2589
                        schedule_downtime(HOST_DOWNTIME, host_name, NULL, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, &downtime_id);
 
2590
 
 
2591
                        /* schedule triggered downtime for all child hosts */
 
2592
                        schedule_and_propagate_downtime(temp_host, entry_time, author, comment_data, start_time, end_time, fixed, downtime_id, duration);
 
2593
                        break;
 
2594
 
 
2595
                default:
 
2596
                        break;
 
2597
                }
2569
2598
 
2570
2599
        return OK;
2571
 
        }
 
2600
        }
2572
2601
 
2573
2602
 
2574
2603
 
2575
2604
/* deletes scheduled host or service downtime */
2576
 
int cmd_delete_downtime(int cmd, char *args){
2577
 
        unsigned long downtime_id=0L;
2578
 
        char *temp_ptr=NULL;
 
2605
int cmd_delete_downtime(int cmd, char *args) {
 
2606
        unsigned long downtime_id = 0L;
 
2607
        char *temp_ptr = NULL;
2579
2608
 
2580
2609
        /* get the id of the downtime to delete */
2581
 
        if((temp_ptr=my_strtok(args,"\n"))==NULL)
 
2610
        if((temp_ptr = my_strtok(args, "\n")) == NULL)
2582
2611
                return ERROR;
2583
 
        downtime_id=strtoul(temp_ptr,NULL,10);
 
2612
        downtime_id = strtoul(temp_ptr, NULL, 10);
2584
2613
 
2585
 
        if(cmd==CMD_DEL_HOST_DOWNTIME)
2586
 
                unschedule_downtime(HOST_DOWNTIME,downtime_id);
 
2614
        if(cmd == CMD_DEL_HOST_DOWNTIME)
 
2615
                unschedule_downtime(HOST_DOWNTIME, downtime_id);
2587
2616
        else
2588
 
                unschedule_downtime(SERVICE_DOWNTIME,downtime_id);
2589
 
 
2590
 
        return OK;
2591
 
        }
2592
 
 
2593
 
 
2594
 
        
 
2617
                unschedule_downtime(SERVICE_DOWNTIME, downtime_id);
 
2618
 
 
2619
        return OK;
 
2620
        }
 
2621
 
 
2622
 
 
2623
/* Opsview enhancements: some of these commands are now "distributable" as no downtime ids are used */
 
2624
/* Deletes scheduled host and service downtime based on hostname and optionally other filter arguments */
 
2625
int cmd_delete_downtime_by_host_name(int cmd, char *args) {
 
2626
        char *temp_ptr = NULL;
 
2627
        char *end_ptr = NULL;
 
2628
        char *hostname = NULL;
 
2629
        char *service_description = NULL;
 
2630
        char *downtime_comment = NULL;
 
2631
        time_t downtime_start_time = 0L;
 
2632
        int deleted = 0;
 
2633
 
 
2634
        /* get the host name of the downtime to delete */
 
2635
        temp_ptr = my_strtok(args, ";");
 
2636
        if(temp_ptr == NULL)
 
2637
                return ERROR;
 
2638
        hostname = temp_ptr;
 
2639
 
 
2640
        /* get the optional service name */
 
2641
        temp_ptr = my_strtok(NULL, ";");
 
2642
        if(temp_ptr != NULL) {
 
2643
                if(*temp_ptr != '\0')
 
2644
                        service_description = temp_ptr;
 
2645
 
 
2646
                /* get the optional start time */
 
2647
                temp_ptr = my_strtok(NULL, ";");
 
2648
                if(temp_ptr != NULL) {
 
2649
                        downtime_start_time = strtoul(temp_ptr, &end_ptr, 10);
 
2650
 
 
2651
                        /* get the optional comment */
 
2652
                        temp_ptr = my_strtok(NULL, ";");
 
2653
                        if(temp_ptr != NULL) {
 
2654
                                if(*temp_ptr != '\0')
 
2655
                                        downtime_comment = temp_ptr;
 
2656
 
 
2657
                                }
 
2658
                        }
 
2659
                }
 
2660
 
 
2661
        deleted = delete_downtime_by_hostname_service_description_start_time_comment(hostname, service_description, downtime_start_time, downtime_comment);
 
2662
 
 
2663
        if(deleted == 0)
 
2664
                return ERROR;
 
2665
 
 
2666
        return OK;
 
2667
        }
 
2668
 
 
2669
/* Opsview enhancement: Deletes scheduled host and service downtime based on hostgroup and optionally other filter arguments */
 
2670
int cmd_delete_downtime_by_hostgroup_name(int cmd, char *args) {
 
2671
        char *temp_ptr = NULL;
 
2672
        char *end_ptr = NULL;
 
2673
        host *temp_host = NULL;
 
2674
        hostgroup *temp_hostgroup = NULL;
 
2675
        hostsmember *temp_member = NULL;
 
2676
        char *service_description = NULL;
 
2677
        char *downtime_comment = NULL;
 
2678
        char *host_name = NULL;
 
2679
        time_t downtime_start_time = 0L;
 
2680
        int deleted = 0;
 
2681
 
 
2682
        /* get the host group name of the downtime to delete */
 
2683
        temp_ptr = my_strtok(args, ";");
 
2684
        if(temp_ptr == NULL)
 
2685
                return ERROR;
 
2686
 
 
2687
        temp_hostgroup = find_hostgroup(temp_ptr);
 
2688
        if(temp_hostgroup == NULL)
 
2689
                return ERROR;
 
2690
 
 
2691
        /* get the optional host name */
 
2692
        temp_ptr = my_strtok(NULL, ";");
 
2693
        if(temp_ptr != NULL) {
 
2694
                if(*temp_ptr != '\0')
 
2695
                        host_name = temp_ptr;
 
2696
 
 
2697
                /* get the optional service name */
 
2698
                temp_ptr = my_strtok(NULL, ";");
 
2699
                if(temp_ptr != NULL) {
 
2700
                        if(*temp_ptr != '\0')
 
2701
                                service_description = temp_ptr;
 
2702
 
 
2703
                        /* get the optional start time */
 
2704
                        temp_ptr = my_strtok(NULL, ";");
 
2705
                        if(temp_ptr != NULL) {
 
2706
                                downtime_start_time = strtoul(temp_ptr, &end_ptr, 10);
 
2707
 
 
2708
                                /* get the optional comment */
 
2709
                                temp_ptr = my_strtok(NULL, ";");
 
2710
                                if(temp_ptr != NULL) {
 
2711
                                        if(*temp_ptr != '\0')
 
2712
                                                downtime_comment = temp_ptr;
 
2713
 
 
2714
                                        }
 
2715
                                }
 
2716
                        }
 
2717
 
 
2718
                /* get the optional service name */
 
2719
                temp_ptr = my_strtok(NULL, ";");
 
2720
                if(temp_ptr != NULL) {
 
2721
                        if(*temp_ptr != '\0')
 
2722
                                service_description = temp_ptr;
 
2723
 
 
2724
                        /* get the optional start time */
 
2725
                        temp_ptr = my_strtok(NULL, ";");
 
2726
                        if(temp_ptr != NULL) {
 
2727
                                downtime_start_time = strtoul(temp_ptr, &end_ptr, 10);
 
2728
 
 
2729
                                /* get the optional comment */
 
2730
                                temp_ptr = my_strtok(NULL, ";");
 
2731
                                if(temp_ptr != NULL) {
 
2732
                                        if(*temp_ptr != '\0')
 
2733
                                                downtime_comment = temp_ptr;
 
2734
                                        }
 
2735
                                }
 
2736
                        }
 
2737
                }
 
2738
 
 
2739
        for(temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
 
2740
                if((temp_host = (host *)temp_member->host_ptr) == NULL)
 
2741
                        continue;
 
2742
                if(host_name != NULL && strcmp(temp_host->name, host_name) != 0)
 
2743
                        continue;
 
2744
                deleted = +delete_downtime_by_hostname_service_description_start_time_comment(temp_host->name, service_description, downtime_start_time, downtime_comment);
 
2745
                }
 
2746
 
 
2747
        if(deleted == 0)
 
2748
                return ERROR;
 
2749
 
 
2750
        return OK;
 
2751
        }
 
2752
 
 
2753
/* Opsview enhancement: Delete downtimes based on start time and/or comment */
 
2754
int cmd_delete_downtime_by_start_time_comment(int cmd, char *args) {
 
2755
        time_t downtime_start_time = 0L;
 
2756
        char *downtime_comment = NULL;
 
2757
        char *temp_ptr = NULL;
 
2758
        char *end_ptr = NULL;
 
2759
        int deleted = 0;
 
2760
 
 
2761
        /* Get start time if set */
 
2762
        temp_ptr = my_strtok(args, ";");
 
2763
        if(temp_ptr != NULL) {
 
2764
                /* This will be set to 0 if no start_time is entered or data is bad */
 
2765
                downtime_start_time = strtoul(temp_ptr, &end_ptr, 10);
 
2766
                }
 
2767
 
 
2768
        /* Get comment - not sure if this should be also tokenised by ; */
 
2769
        temp_ptr = my_strtok(NULL, "\n");
 
2770
        if(temp_ptr != NULL && *temp_ptr != '\0') {
 
2771
                downtime_comment = temp_ptr;
 
2772
                }
 
2773
 
 
2774
        /* No args should give an error */
 
2775
        if(downtime_start_time == 0 && downtime_comment == NULL)
 
2776
                return ERROR;
 
2777
 
 
2778
        deleted = delete_downtime_by_hostname_service_description_start_time_comment(NULL, NULL, downtime_start_time, downtime_comment);
 
2779
 
 
2780
        if(deleted == 0)
 
2781
                return ERROR;
 
2782
 
 
2783
        return OK;
 
2784
        }
 
2785
 
 
2786
 
2595
2787
/* changes a host or service (integer) variable */
2596
 
int cmd_change_object_int_var(int cmd,char *args){
2597
 
        service *temp_service=NULL;
2598
 
        host *temp_host=NULL;
2599
 
        contact *temp_contact=NULL;
2600
 
        char *host_name=NULL;
2601
 
        char *svc_description=NULL;
2602
 
        char *contact_name=NULL;
2603
 
        char *temp_ptr=NULL;
2604
 
        int intval=0;
2605
 
        double dval=0.0;
2606
 
        double old_dval=0.0;
2607
 
        time_t preferred_time=0L;
2608
 
        time_t next_valid_time=0L;
2609
 
        unsigned long attr=MODATTR_NONE;
2610
 
        unsigned long hattr=MODATTR_NONE;
2611
 
        unsigned long sattr=MODATTR_NONE;
2612
 
 
2613
 
        switch(cmd){
2614
 
 
2615
 
        case CMD_CHANGE_NORMAL_SVC_CHECK_INTERVAL:
2616
 
        case CMD_CHANGE_RETRY_SVC_CHECK_INTERVAL:
2617
 
        case CMD_CHANGE_MAX_SVC_CHECK_ATTEMPTS:
2618
 
        case CMD_CHANGE_SVC_MODATTR:
2619
 
                
2620
 
                /* get the host name */
2621
 
                if((host_name=my_strtok(args,";"))==NULL)
2622
 
                        return ERROR;
2623
 
 
2624
 
                /* get the service name */
2625
 
                if((svc_description=my_strtok(NULL,";"))==NULL)
2626
 
                        return ERROR;
2627
 
 
2628
 
                /* verify that the service is valid */
2629
 
                if((temp_service=find_service(host_name,svc_description))==NULL)
2630
 
                        return ERROR;
2631
 
 
2632
 
                break;
2633
 
 
2634
 
        case CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL:
2635
 
        case CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL:
2636
 
        case CMD_CHANGE_MAX_HOST_CHECK_ATTEMPTS:
2637
 
        case CMD_CHANGE_HOST_MODATTR:
2638
 
 
2639
 
                /* get the host name */
2640
 
                if((host_name=my_strtok(args,";"))==NULL)
2641
 
                        return ERROR;
2642
 
 
2643
 
                /* verify that the host is valid */
2644
 
                if((temp_host=find_host(host_name))==NULL)
2645
 
                        return ERROR;
2646
 
                break;
2647
 
 
2648
 
        case CMD_CHANGE_CONTACT_MODATTR:
2649
 
        case CMD_CHANGE_CONTACT_MODHATTR:
2650
 
        case CMD_CHANGE_CONTACT_MODSATTR:
2651
 
 
2652
 
                /* get the contact name */
2653
 
                if((contact_name=my_strtok(args,";"))==NULL)
2654
 
                        return ERROR;
2655
 
 
2656
 
                /* verify that the contact is valid */
2657
 
                if((temp_contact=find_contact(contact_name))==NULL)
2658
 
                        return ERROR;
2659
 
                break;
2660
 
 
2661
 
        default:
2662
 
                /* unknown command */
2663
 
                return ERROR;
2664
 
                break;
2665
 
                }
 
2788
int cmd_change_object_int_var(int cmd, char *args) {
 
2789
        service *temp_service = NULL;
 
2790
        host *temp_host = NULL;
 
2791
        contact *temp_contact = NULL;
 
2792
        char *host_name = NULL;
 
2793
        char *svc_description = NULL;
 
2794
        char *contact_name = NULL;
 
2795
        char *temp_ptr = NULL;
 
2796
        int intval = 0;
 
2797
        double dval = 0.0;
 
2798
        double old_dval = 0.0;
 
2799
        time_t preferred_time = 0L;
 
2800
        time_t next_valid_time = 0L;
 
2801
        unsigned long attr = MODATTR_NONE;
 
2802
        unsigned long hattr = MODATTR_NONE;
 
2803
        unsigned long sattr = MODATTR_NONE;
 
2804
 
 
2805
        switch(cmd) {
 
2806
 
 
2807
                case CMD_CHANGE_NORMAL_SVC_CHECK_INTERVAL:
 
2808
                case CMD_CHANGE_RETRY_SVC_CHECK_INTERVAL:
 
2809
                case CMD_CHANGE_MAX_SVC_CHECK_ATTEMPTS:
 
2810
                case CMD_CHANGE_SVC_MODATTR:
 
2811
 
 
2812
                        /* get the host name */
 
2813
                        if((host_name = my_strtok(args, ";")) == NULL)
 
2814
                                return ERROR;
 
2815
 
 
2816
                        /* get the service name */
 
2817
                        if((svc_description = my_strtok(NULL, ";")) == NULL)
 
2818
                                return ERROR;
 
2819
 
 
2820
                        /* verify that the service is valid */
 
2821
                        if((temp_service = find_service(host_name, svc_description)) == NULL)
 
2822
                                return ERROR;
 
2823
 
 
2824
                        break;
 
2825
 
 
2826
                case CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL:
 
2827
                case CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL:
 
2828
                case CMD_CHANGE_MAX_HOST_CHECK_ATTEMPTS:
 
2829
                case CMD_CHANGE_HOST_MODATTR:
 
2830
 
 
2831
                        /* get the host name */
 
2832
                        if((host_name = my_strtok(args, ";")) == NULL)
 
2833
                                return ERROR;
 
2834
 
 
2835
                        /* verify that the host is valid */
 
2836
                        if((temp_host = find_host(host_name)) == NULL)
 
2837
                                return ERROR;
 
2838
                        break;
 
2839
 
 
2840
                case CMD_CHANGE_CONTACT_MODATTR:
 
2841
                case CMD_CHANGE_CONTACT_MODHATTR:
 
2842
                case CMD_CHANGE_CONTACT_MODSATTR:
 
2843
 
 
2844
                        /* get the contact name */
 
2845
                        if((contact_name = my_strtok(args, ";")) == NULL)
 
2846
                                return ERROR;
 
2847
 
 
2848
                        /* verify that the contact is valid */
 
2849
                        if((temp_contact = find_contact(contact_name)) == NULL)
 
2850
                                return ERROR;
 
2851
                        break;
 
2852
 
 
2853
                default:
 
2854
                        /* unknown command */
 
2855
                        return ERROR;
 
2856
                        break;
 
2857
                }
2666
2858
 
2667
2859
        /* get the value */
2668
 
        if((temp_ptr=my_strtok(NULL,";"))==NULL)
2669
 
                return ERROR;
2670
 
        intval=(int)strtol(temp_ptr,NULL,0);
2671
 
        if(intval<0 || (intval==0 && errno==EINVAL))
2672
 
                return ERROR;
2673
 
        dval=(int)strtod(temp_ptr,NULL);
2674
 
 
2675
 
        switch(cmd){
2676
 
 
2677
 
        case CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL:
2678
 
 
2679
 
                /* save the old check interval */
2680
 
                old_dval=temp_host->check_interval;
2681
 
 
2682
 
                /* modify the check interval */
2683
 
                temp_host->check_interval=dval;
2684
 
                attr=MODATTR_NORMAL_CHECK_INTERVAL;
2685
 
 
2686
 
                /* schedule a host check if previous interval was 0 (checks were not regularly scheduled) */
2687
 
                if(old_dval==0 && temp_host->checks_enabled==TRUE){
2688
 
 
2689
 
                        /* set the host check flag */
2690
 
                        temp_host->should_be_scheduled=TRUE;
2691
 
 
2692
 
                        /* schedule a check for right now (or as soon as possible) */
2693
 
                        time(&preferred_time);
2694
 
                        if(check_time_against_period(preferred_time,temp_host->check_period_ptr)==ERROR){
2695
 
                                get_next_valid_time(preferred_time,&next_valid_time,temp_host->check_period_ptr);
2696
 
                                temp_host->next_check=next_valid_time;
2697
 
                                }
2698
 
                        else
2699
 
                                temp_host->next_check=preferred_time;
2700
 
 
2701
 
                        /* schedule a check if we should */
2702
 
                        if(temp_host->should_be_scheduled==TRUE)
2703
 
                                schedule_host_check(temp_host,temp_host->next_check,CHECK_OPTION_NONE);
2704
 
                        }
2705
 
 
2706
 
                break;
2707
 
 
2708
 
        case CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL:
2709
 
 
2710
 
                temp_host->retry_interval=dval;
2711
 
                attr=MODATTR_RETRY_CHECK_INTERVAL;
2712
 
 
2713
 
                break;
2714
 
 
2715
 
        case CMD_CHANGE_MAX_HOST_CHECK_ATTEMPTS:
2716
 
 
2717
 
                temp_host->max_attempts=intval;
2718
 
                attr=MODATTR_MAX_CHECK_ATTEMPTS;
2719
 
 
2720
 
                /* adjust current attempt number if in a hard state */
2721
 
                if(temp_host->state_type==HARD_STATE && temp_host->current_state!=HOST_UP && temp_host->current_attempt>1)
2722
 
                        temp_host->current_attempt=temp_host->max_attempts;
2723
 
 
2724
 
                break;
2725
 
 
2726
 
        case CMD_CHANGE_NORMAL_SVC_CHECK_INTERVAL:
2727
 
 
2728
 
                /* save the old check interval */
2729
 
                old_dval=temp_service->check_interval;
2730
 
 
2731
 
                /* modify the check interval */
2732
 
                temp_service->check_interval=dval;
2733
 
                attr=MODATTR_NORMAL_CHECK_INTERVAL;
2734
 
 
2735
 
                /* schedule a service check if previous interval was 0 (checks were not regularly scheduled) */
2736
 
                if(old_dval==0 && temp_service->checks_enabled==TRUE && temp_service->check_interval!=0){
2737
 
 
2738
 
                        /* set the service check flag */
2739
 
                        temp_service->should_be_scheduled=TRUE;
2740
 
 
2741
 
                        /* schedule a check for right now (or as soon as possible) */
2742
 
                        time(&preferred_time);
2743
 
                        if(check_time_against_period(preferred_time,temp_service->check_period_ptr)==ERROR){
2744
 
                                get_next_valid_time(preferred_time,&next_valid_time,temp_service->check_period_ptr);
2745
 
                                temp_service->next_check=next_valid_time;
2746
 
                                }
2747
 
                        else
2748
 
                                temp_service->next_check=preferred_time;
2749
 
 
2750
 
                        /* schedule a check if we should */
2751
 
                        if(temp_service->should_be_scheduled==TRUE)
2752
 
                                schedule_service_check(temp_service,temp_service->next_check,CHECK_OPTION_NONE);
2753
 
                        }
2754
 
 
2755
 
                break;
2756
 
 
2757
 
        case CMD_CHANGE_RETRY_SVC_CHECK_INTERVAL:
2758
 
 
2759
 
                temp_service->retry_interval=dval;
2760
 
                attr=MODATTR_RETRY_CHECK_INTERVAL;
2761
 
 
2762
 
                break;
2763
 
 
2764
 
        case CMD_CHANGE_MAX_SVC_CHECK_ATTEMPTS:
2765
 
 
2766
 
                temp_service->max_attempts=intval;
2767
 
                attr=MODATTR_MAX_CHECK_ATTEMPTS;
2768
 
 
2769
 
                /* adjust current attempt number if in a hard state */
2770
 
                if(temp_service->state_type==HARD_STATE && temp_service->current_state!=STATE_OK && temp_service->current_attempt>1)
2771
 
                        temp_service->current_attempt=temp_service->max_attempts;
2772
 
 
2773
 
                break;
2774
 
 
2775
 
        case CMD_CHANGE_HOST_MODATTR:
2776
 
        case CMD_CHANGE_SVC_MODATTR:
2777
 
        case CMD_CHANGE_CONTACT_MODATTR:
2778
 
 
2779
 
                attr=intval;
2780
 
                break;
2781
 
 
2782
 
        case CMD_CHANGE_CONTACT_MODHATTR:
2783
 
 
2784
 
                hattr=intval;
2785
 
                break;
2786
 
 
2787
 
        case CMD_CHANGE_CONTACT_MODSATTR:
2788
 
 
2789
 
                sattr=intval;
2790
 
                break;
2791
 
                
2792
 
 
2793
 
        default:
2794
 
                break;
2795
 
                }
 
2860
        if((temp_ptr = my_strtok(NULL, ";")) == NULL)
 
2861
                return ERROR;
 
2862
        intval = (int)strtol(temp_ptr, NULL, 0);
 
2863
        if(intval < 0 || (intval == 0 && errno == EINVAL))
 
2864
                return ERROR;
 
2865
        dval = (int)strtod(temp_ptr, NULL);
 
2866
 
 
2867
        switch(cmd) {
 
2868
 
 
2869
                case CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL:
 
2870
 
 
2871
                        /* save the old check interval */
 
2872
                        old_dval = temp_host->check_interval;
 
2873
 
 
2874
                        /* modify the check interval */
 
2875
                        temp_host->check_interval = dval;
 
2876
                        attr = MODATTR_NORMAL_CHECK_INTERVAL;
 
2877
 
 
2878
                        /* schedule a host check if previous interval was 0 (checks were not regularly scheduled) */
 
2879
                        if(old_dval == 0 && temp_host->checks_enabled == TRUE) {
 
2880
 
 
2881
                                /* set the host check flag */
 
2882
                                temp_host->should_be_scheduled = TRUE;
 
2883
 
 
2884
                                /* schedule a check for right now (or as soon as possible) */
 
2885
                                time(&preferred_time);
 
2886
                                if(check_time_against_period(preferred_time, temp_host->check_period_ptr) == ERROR) {
 
2887
                                        get_next_valid_time(preferred_time, &next_valid_time, temp_host->check_period_ptr);
 
2888
                                        temp_host->next_check = next_valid_time;
 
2889
                                        }
 
2890
                                else
 
2891
                                        temp_host->next_check = preferred_time;
 
2892
 
 
2893
                                /* schedule a check if we should */
 
2894
                                if(temp_host->should_be_scheduled == TRUE)
 
2895
                                        schedule_host_check(temp_host, temp_host->next_check, CHECK_OPTION_NONE);
 
2896
                                }
 
2897
 
 
2898
                        break;
 
2899
 
 
2900
                case CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL:
 
2901
 
 
2902
                        temp_host->retry_interval = dval;
 
2903
                        attr = MODATTR_RETRY_CHECK_INTERVAL;
 
2904
 
 
2905
                        break;
 
2906
 
 
2907
                case CMD_CHANGE_MAX_HOST_CHECK_ATTEMPTS:
 
2908
 
 
2909
                        temp_host->max_attempts = intval;
 
2910
                        attr = MODATTR_MAX_CHECK_ATTEMPTS;
 
2911
 
 
2912
                        /* adjust current attempt number if in a hard state */
 
2913
                        if(temp_host->state_type == HARD_STATE && temp_host->current_state != HOST_UP && temp_host->current_attempt > 1)
 
2914
                                temp_host->current_attempt = temp_host->max_attempts;
 
2915
 
 
2916
                        break;
 
2917
 
 
2918
                case CMD_CHANGE_NORMAL_SVC_CHECK_INTERVAL:
 
2919
 
 
2920
                        /* save the old check interval */
 
2921
                        old_dval = temp_service->check_interval;
 
2922
 
 
2923
                        /* modify the check interval */
 
2924
                        temp_service->check_interval = dval;
 
2925
                        attr = MODATTR_NORMAL_CHECK_INTERVAL;
 
2926
 
 
2927
                        /* schedule a service check if previous interval was 0 (checks were not regularly scheduled) */
 
2928
                        if(old_dval == 0 && temp_service->checks_enabled == TRUE && temp_service->check_interval != 0) {
 
2929
 
 
2930
                                /* set the service check flag */
 
2931
                                temp_service->should_be_scheduled = TRUE;
 
2932
 
 
2933
                                /* schedule a check for right now (or as soon as possible) */
 
2934
                                time(&preferred_time);
 
2935
                                if(check_time_against_period(preferred_time, temp_service->check_period_ptr) == ERROR) {
 
2936
                                        get_next_valid_time(preferred_time, &next_valid_time, temp_service->check_period_ptr);
 
2937
                                        temp_service->next_check = next_valid_time;
 
2938
                                        }
 
2939
                                else
 
2940
                                        temp_service->next_check = preferred_time;
 
2941
 
 
2942
                                /* schedule a check if we should */
 
2943
                                if(temp_service->should_be_scheduled == TRUE)
 
2944
                                        schedule_service_check(temp_service, temp_service->next_check, CHECK_OPTION_NONE);
 
2945
                                }
 
2946
 
 
2947
                        break;
 
2948
 
 
2949
                case CMD_CHANGE_RETRY_SVC_CHECK_INTERVAL:
 
2950
 
 
2951
                        temp_service->retry_interval = dval;
 
2952
                        attr = MODATTR_RETRY_CHECK_INTERVAL;
 
2953
 
 
2954
                        break;
 
2955
 
 
2956
                case CMD_CHANGE_MAX_SVC_CHECK_ATTEMPTS:
 
2957
 
 
2958
                        temp_service->max_attempts = intval;
 
2959
                        attr = MODATTR_MAX_CHECK_ATTEMPTS;
 
2960
 
 
2961
                        /* adjust current attempt number if in a hard state */
 
2962
                        if(temp_service->state_type == HARD_STATE && temp_service->current_state != STATE_OK && temp_service->current_attempt > 1)
 
2963
                                temp_service->current_attempt = temp_service->max_attempts;
 
2964
 
 
2965
                        break;
 
2966
 
 
2967
                case CMD_CHANGE_HOST_MODATTR:
 
2968
                case CMD_CHANGE_SVC_MODATTR:
 
2969
                case CMD_CHANGE_CONTACT_MODATTR:
 
2970
 
 
2971
                        attr = intval;
 
2972
                        break;
 
2973
 
 
2974
                case CMD_CHANGE_CONTACT_MODHATTR:
 
2975
 
 
2976
                        hattr = intval;
 
2977
                        break;
 
2978
 
 
2979
                case CMD_CHANGE_CONTACT_MODSATTR:
 
2980
 
 
2981
                        sattr = intval;
 
2982
                        break;
 
2983
 
 
2984
 
 
2985
                default:
 
2986
                        break;
 
2987
                }
2796
2988
 
2797
2989
 
2798
2990
        /* send data to event broker and update status file */
2799
 
        switch(cmd){
2800
 
 
2801
 
        case CMD_CHANGE_RETRY_SVC_CHECK_INTERVAL:
2802
 
        case CMD_CHANGE_NORMAL_SVC_CHECK_INTERVAL:
2803
 
        case CMD_CHANGE_MAX_SVC_CHECK_ATTEMPTS:
2804
 
        case CMD_CHANGE_SVC_MODATTR:
2805
 
 
2806
 
                /* set the modified service attribute */
2807
 
                if(cmd==CMD_CHANGE_SVC_MODATTR)
2808
 
                        temp_service->modified_attributes=attr;
2809
 
                else
2810
 
                        temp_service->modified_attributes|=attr;
2811
 
 
2812
 
#ifdef USE_EVENT_BROKER
2813
 
                /* send data to event broker */
2814
 
                broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,temp_service,cmd,attr,temp_service->modified_attributes,NULL);
2815
 
#endif
2816
 
 
2817
 
                /* update the status log with the service info */
2818
 
                update_service_status(temp_service,FALSE);
2819
 
 
2820
 
                break;
2821
 
 
2822
 
        case CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL:
2823
 
        case CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL:
2824
 
        case CMD_CHANGE_MAX_HOST_CHECK_ATTEMPTS:
2825
 
        case CMD_CHANGE_HOST_MODATTR:
2826
 
 
2827
 
                /* set the modified host attribute */
2828
 
                if(cmd==CMD_CHANGE_HOST_MODATTR)
2829
 
                        temp_host->modified_attributes=attr;
2830
 
                else
2831
 
                        temp_host->modified_attributes|=attr;
2832
 
 
2833
 
#ifdef USE_EVENT_BROKER
2834
 
                /* send data to event broker */
2835
 
                broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,temp_host,cmd,attr,temp_host->modified_attributes,NULL);
2836
 
#endif
2837
 
 
2838
 
                /* update the status log with the host info */
2839
 
                update_host_status(temp_host,FALSE);
2840
 
                break;
2841
 
 
2842
 
        case CMD_CHANGE_CONTACT_MODATTR:
2843
 
        case CMD_CHANGE_CONTACT_MODHATTR:
2844
 
        case CMD_CHANGE_CONTACT_MODSATTR:
2845
 
 
2846
 
                /* set the modified attribute */
2847
 
                switch(cmd){
 
2991
        switch(cmd) {
 
2992
 
 
2993
                case CMD_CHANGE_RETRY_SVC_CHECK_INTERVAL:
 
2994
                case CMD_CHANGE_NORMAL_SVC_CHECK_INTERVAL:
 
2995
                case CMD_CHANGE_MAX_SVC_CHECK_ATTEMPTS:
 
2996
                case CMD_CHANGE_SVC_MODATTR:
 
2997
 
 
2998
                        /* set the modified service attribute */
 
2999
                        if(cmd == CMD_CHANGE_SVC_MODATTR)
 
3000
                                temp_service->modified_attributes = attr;
 
3001
                        else
 
3002
                                temp_service->modified_attributes |= attr;
 
3003
 
 
3004
#ifdef USE_EVENT_BROKER
 
3005
                        /* send data to event broker */
 
3006
                        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, temp_service, cmd, attr, temp_service->modified_attributes, NULL);
 
3007
#endif
 
3008
 
 
3009
                        /* update the status log with the service info */
 
3010
                        update_service_status(temp_service, FALSE);
 
3011
 
 
3012
                        break;
 
3013
 
 
3014
                case CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL:
 
3015
                case CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL:
 
3016
                case CMD_CHANGE_MAX_HOST_CHECK_ATTEMPTS:
 
3017
                case CMD_CHANGE_HOST_MODATTR:
 
3018
 
 
3019
                        /* set the modified host attribute */
 
3020
                        if(cmd == CMD_CHANGE_HOST_MODATTR)
 
3021
                                temp_host->modified_attributes = attr;
 
3022
                        else
 
3023
                                temp_host->modified_attributes |= attr;
 
3024
 
 
3025
#ifdef USE_EVENT_BROKER
 
3026
                        /* send data to event broker */
 
3027
                        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, temp_host, cmd, attr, temp_host->modified_attributes, NULL);
 
3028
#endif
 
3029
 
 
3030
                        /* update the status log with the host info */
 
3031
                        update_host_status(temp_host, FALSE);
 
3032
                        break;
 
3033
 
2848
3034
                case CMD_CHANGE_CONTACT_MODATTR:
2849
 
                        temp_contact->modified_attributes=attr;
2850
 
                        break;
2851
3035
                case CMD_CHANGE_CONTACT_MODHATTR:
2852
 
                        temp_contact->modified_host_attributes=hattr;
2853
 
                        break;
2854
3036
                case CMD_CHANGE_CONTACT_MODSATTR:
2855
 
                        temp_contact->modified_service_attributes=sattr;
 
3037
 
 
3038
                        /* set the modified attribute */
 
3039
                        switch(cmd) {
 
3040
                                case CMD_CHANGE_CONTACT_MODATTR:
 
3041
                                        temp_contact->modified_attributes = attr;
 
3042
                                        break;
 
3043
                                case CMD_CHANGE_CONTACT_MODHATTR:
 
3044
                                        temp_contact->modified_host_attributes = hattr;
 
3045
                                        break;
 
3046
                                case CMD_CHANGE_CONTACT_MODSATTR:
 
3047
                                        temp_contact->modified_service_attributes = sattr;
 
3048
                                        break;
 
3049
                                default:
 
3050
                                        break;
 
3051
                                }
 
3052
 
 
3053
#ifdef USE_EVENT_BROKER
 
3054
                        /* send data to event broker */
 
3055
                        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);
 
3056
#endif
 
3057
 
 
3058
                        /* update the status log with the contact info */
 
3059
                        update_contact_status(temp_contact, FALSE);
2856
3060
                        break;
 
3061
 
2857
3062
                default:
2858
3063
                        break;
2859
 
                        }
2860
 
 
2861
 
#ifdef USE_EVENT_BROKER
2862
 
                /* send data to event broker */
2863
 
                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);
2864
 
#endif
2865
 
 
2866
 
                /* update the status log with the contact info */
2867
 
                update_contact_status(temp_contact,FALSE);
2868
 
                break;
2869
 
 
2870
 
        default:
2871
 
                break;
2872
 
                }
 
3064
                }
2873
3065
 
2874
3066
        return OK;
2875
 
        }
2876
 
 
2877
 
 
2878
 
      
 
3067
        }
 
3068
 
 
3069
 
 
3070
 
2879
3071
/* changes a host or service (char) variable */
2880
 
int cmd_change_object_char_var(int cmd,char *args){
2881
 
        service *temp_service=NULL;
2882
 
        host *temp_host=NULL;
2883
 
        contact *temp_contact=NULL;
2884
 
        timeperiod *temp_timeperiod=NULL;
2885
 
        command *temp_command=NULL;
2886
 
        char *host_name=NULL;
2887
 
        char *svc_description=NULL;
2888
 
        char *contact_name=NULL;
2889
 
        char *charval=NULL;
2890
 
        char *temp_ptr=NULL;
2891
 
        char *temp_ptr2=NULL;
2892
 
        unsigned long attr=MODATTR_NONE;
2893
 
        unsigned long hattr=MODATTR_NONE;
2894
 
        unsigned long sattr=MODATTR_NONE;
2895
 
 
2896
 
        
 
3072
int cmd_change_object_char_var(int cmd, char *args) {
 
3073
        service *temp_service = NULL;
 
3074
        host *temp_host = NULL;
 
3075
        contact *temp_contact = NULL;
 
3076
        timeperiod *temp_timeperiod = NULL;
 
3077
        command *temp_command = NULL;
 
3078
        char *host_name = NULL;
 
3079
        char *svc_description = NULL;
 
3080
        char *contact_name = NULL;
 
3081
        char *charval = NULL;
 
3082
        char *temp_ptr = NULL;
 
3083
        char *temp_ptr2 = NULL;
 
3084
        unsigned long attr = MODATTR_NONE;
 
3085
        unsigned long hattr = MODATTR_NONE;
 
3086
        unsigned long sattr = MODATTR_NONE;
 
3087
 
 
3088
 
2897
3089
        /* SECURITY PATCH - disable these for the time being */
2898
 
        switch(cmd){
2899
 
        case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
2900
 
        case CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER:
2901
 
        case CMD_CHANGE_HOST_EVENT_HANDLER:
2902
 
        case CMD_CHANGE_SVC_EVENT_HANDLER:
2903
 
        case CMD_CHANGE_HOST_CHECK_COMMAND:
2904
 
        case CMD_CHANGE_SVC_CHECK_COMMAND:
2905
 
                return ERROR;
 
3090
        switch(cmd) {
 
3091
                case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
 
3092
                case CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER:
 
3093
                case CMD_CHANGE_HOST_EVENT_HANDLER:
 
3094
                case CMD_CHANGE_SVC_EVENT_HANDLER:
 
3095
                case CMD_CHANGE_HOST_CHECK_COMMAND:
 
3096
                case CMD_CHANGE_SVC_CHECK_COMMAND:
 
3097
                        return ERROR;
2906
3098
                }
2907
3099
 
2908
3100
 
2909
3101
        /* get the command arguments */
2910
 
        switch(cmd){
2911
 
 
2912
 
        case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
2913
 
        case CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER:
2914
 
 
2915
 
                if((charval=my_strtok(args,"\n"))==NULL)
2916
 
                        return ERROR;
2917
 
                
2918
 
                break;
2919
 
 
2920
 
        case CMD_CHANGE_HOST_EVENT_HANDLER:
2921
 
        case CMD_CHANGE_HOST_CHECK_COMMAND:
2922
 
        case CMD_CHANGE_HOST_CHECK_TIMEPERIOD:
2923
 
        case CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD:
2924
 
 
2925
 
                /* get the host name */
2926
 
                if((host_name=my_strtok(args,";"))==NULL)
2927
 
                        return ERROR;
2928
 
 
2929
 
                /* verify that the host is valid */
2930
 
                if((temp_host=find_host(host_name))==NULL)
2931
 
                        return ERROR;
2932
 
 
2933
 
                if((charval=my_strtok(NULL,"\n"))==NULL)
2934
 
                        return ERROR;
2935
 
 
2936
 
                break;
2937
 
 
2938
 
        case CMD_CHANGE_SVC_EVENT_HANDLER:
2939
 
        case CMD_CHANGE_SVC_CHECK_COMMAND:
2940
 
        case CMD_CHANGE_SVC_CHECK_TIMEPERIOD:
2941
 
        case CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD:
2942
 
 
2943
 
                /* get the host name */
2944
 
                if((host_name=my_strtok(args,";"))==NULL)
2945
 
                        return ERROR;
2946
 
 
2947
 
                /* get the service name */
2948
 
                if((svc_description=my_strtok(NULL,";"))==NULL)
2949
 
                        return ERROR;
2950
 
 
2951
 
                /* verify that the service is valid */
2952
 
                if((temp_service=find_service(host_name,svc_description))==NULL)
2953
 
                        return ERROR;
2954
 
 
2955
 
                if((charval=my_strtok(NULL,"\n"))==NULL)
2956
 
                        return ERROR;
2957
 
 
2958
 
                break;
2959
 
 
2960
 
 
2961
 
        case CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD:
2962
 
        case CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD:
2963
 
 
2964
 
                /* get the contact name */
2965
 
                if((contact_name=my_strtok(args,";"))==NULL)
2966
 
                        return ERROR;
2967
 
 
2968
 
                /* verify that the contact is valid */
2969
 
                if((temp_contact=find_contact(contact_name))==NULL)
2970
 
                        return ERROR;
2971
 
 
2972
 
                if((charval=my_strtok(NULL,"\n"))==NULL)
2973
 
                        return ERROR;
2974
 
 
2975
 
                break;
2976
 
 
2977
 
        default:
2978
 
                /* invalid command */
2979
 
                return ERROR;
2980
 
                break;
2981
 
 
2982
 
                }
2983
 
 
2984
 
        if((temp_ptr=(char *)strdup(charval))==NULL)
 
3102
        switch(cmd) {
 
3103
 
 
3104
                case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
 
3105
                case CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER:
 
3106
 
 
3107
                        if((charval = my_strtok(args, "\n")) == NULL)
 
3108
                                return ERROR;
 
3109
 
 
3110
                        break;
 
3111
 
 
3112
                case CMD_CHANGE_HOST_EVENT_HANDLER:
 
3113
                case CMD_CHANGE_HOST_CHECK_COMMAND:
 
3114
                case CMD_CHANGE_HOST_CHECK_TIMEPERIOD:
 
3115
                case CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD:
 
3116
 
 
3117
                        /* get the host name */
 
3118
                        if((host_name = my_strtok(args, ";")) == NULL)
 
3119
                                return ERROR;
 
3120
 
 
3121
                        /* verify that the host is valid */
 
3122
                        if((temp_host = find_host(host_name)) == NULL)
 
3123
                                return ERROR;
 
3124
 
 
3125
                        if((charval = my_strtok(NULL, "\n")) == NULL)
 
3126
                                return ERROR;
 
3127
 
 
3128
                        break;
 
3129
 
 
3130
                case CMD_CHANGE_SVC_EVENT_HANDLER:
 
3131
                case CMD_CHANGE_SVC_CHECK_COMMAND:
 
3132
                case CMD_CHANGE_SVC_CHECK_TIMEPERIOD:
 
3133
                case CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD:
 
3134
 
 
3135
                        /* get the host name */
 
3136
                        if((host_name = my_strtok(args, ";")) == NULL)
 
3137
                                return ERROR;
 
3138
 
 
3139
                        /* get the service name */
 
3140
                        if((svc_description = my_strtok(NULL, ";")) == NULL)
 
3141
                                return ERROR;
 
3142
 
 
3143
                        /* verify that the service is valid */
 
3144
                        if((temp_service = find_service(host_name, svc_description)) == NULL)
 
3145
                                return ERROR;
 
3146
 
 
3147
                        if((charval = my_strtok(NULL, "\n")) == NULL)
 
3148
                                return ERROR;
 
3149
 
 
3150
                        break;
 
3151
 
 
3152
 
 
3153
                case CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD:
 
3154
                case CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD:
 
3155
 
 
3156
                        /* get the contact name */
 
3157
                        if((contact_name = my_strtok(args, ";")) == NULL)
 
3158
                                return ERROR;
 
3159
 
 
3160
                        /* verify that the contact is valid */
 
3161
                        if((temp_contact = find_contact(contact_name)) == NULL)
 
3162
                                return ERROR;
 
3163
 
 
3164
                        if((charval = my_strtok(NULL, "\n")) == NULL)
 
3165
                                return ERROR;
 
3166
 
 
3167
                        break;
 
3168
 
 
3169
                default:
 
3170
                        /* invalid command */
 
3171
                        return ERROR;
 
3172
                        break;
 
3173
 
 
3174
                }
 
3175
 
 
3176
        if((temp_ptr = (char *)strdup(charval)) == NULL)
2985
3177
                return ERROR;
2986
3178
 
2987
3179
 
2988
3180
        /* do some validation */
2989
 
        switch(cmd){
2990
 
 
2991
 
        case CMD_CHANGE_HOST_CHECK_TIMEPERIOD:
2992
 
        case CMD_CHANGE_SVC_CHECK_TIMEPERIOD:
2993
 
        case CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD:
2994
 
        case CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD:
2995
 
        case CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD:
2996
 
        case CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD:
2997
 
 
2998
 
                /* make sure the timeperiod is valid */
2999
 
                if((temp_timeperiod=find_timeperiod(temp_ptr))==NULL){
3000
 
                        my_free(temp_ptr);
3001
 
                        return ERROR;
3002
 
                        }
3003
 
 
3004
 
                break;
3005
 
 
3006
 
        case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
3007
 
        case CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER:
3008
 
        case CMD_CHANGE_HOST_EVENT_HANDLER:
3009
 
        case CMD_CHANGE_SVC_EVENT_HANDLER:
3010
 
        case CMD_CHANGE_HOST_CHECK_COMMAND:
3011
 
        case CMD_CHANGE_SVC_CHECK_COMMAND:
3012
 
 
3013
 
                /* make sure the command exists */
3014
 
                temp_ptr2=my_strtok(temp_ptr,"!");
3015
 
                if((temp_command=find_command(temp_ptr2))==NULL){
3016
 
                        my_free(temp_ptr);
3017
 
                        return ERROR;
3018
 
                        }
3019
 
 
3020
 
                my_free(temp_ptr);
3021
 
                if((temp_ptr=(char *)strdup(charval))==NULL)
3022
 
                        return ERROR;
3023
 
 
3024
 
                break;
3025
 
 
3026
 
        default:
3027
 
                break;
3028
 
                }
 
3181
        switch(cmd) {
 
3182
 
 
3183
                case CMD_CHANGE_HOST_CHECK_TIMEPERIOD:
 
3184
                case CMD_CHANGE_SVC_CHECK_TIMEPERIOD:
 
3185
                case CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD:
 
3186
                case CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD:
 
3187
                case CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD:
 
3188
                case CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD:
 
3189
 
 
3190
                        /* make sure the timeperiod is valid */
 
3191
                        if((temp_timeperiod = find_timeperiod(temp_ptr)) == NULL) {
 
3192
                                my_free(temp_ptr);
 
3193
                                return ERROR;
 
3194
                                }
 
3195
 
 
3196
                        break;
 
3197
 
 
3198
                case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
 
3199
                case CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER:
 
3200
                case CMD_CHANGE_HOST_EVENT_HANDLER:
 
3201
                case CMD_CHANGE_SVC_EVENT_HANDLER:
 
3202
                case CMD_CHANGE_HOST_CHECK_COMMAND:
 
3203
                case CMD_CHANGE_SVC_CHECK_COMMAND:
 
3204
 
 
3205
                        /* make sure the command exists */
 
3206
                        temp_ptr2 = my_strtok(temp_ptr, "!");
 
3207
                        if((temp_command = find_command(temp_ptr2)) == NULL) {
 
3208
                                my_free(temp_ptr);
 
3209
                                return ERROR;
 
3210
                                }
 
3211
 
 
3212
                        my_free(temp_ptr);
 
3213
                        if((temp_ptr = (char *)strdup(charval)) == NULL)
 
3214
                                return ERROR;
 
3215
 
 
3216
                        break;
 
3217
 
 
3218
                default:
 
3219
                        break;
 
3220
                }
3029
3221
 
3030
3222
 
3031
3223
        /* update the variable */
3032
 
        switch(cmd){
3033
 
 
3034
 
        case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
3035
 
 
3036
 
                my_free(global_host_event_handler);
3037
 
                global_host_event_handler=temp_ptr;
3038
 
                global_host_event_handler_ptr=temp_command;
3039
 
                attr=MODATTR_EVENT_HANDLER_COMMAND;
3040
 
                break;
3041
 
 
3042
 
        case CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER:
3043
 
 
3044
 
                my_free(global_service_event_handler);
3045
 
                global_service_event_handler=temp_ptr;
3046
 
                global_service_event_handler_ptr=temp_command;
3047
 
                attr=MODATTR_EVENT_HANDLER_COMMAND;
3048
 
                break;
3049
 
 
3050
 
        case CMD_CHANGE_HOST_EVENT_HANDLER:
3051
 
 
3052
 
                my_free(temp_host->event_handler);
3053
 
                temp_host->event_handler=temp_ptr;
3054
 
                temp_host->event_handler_ptr=temp_command;
3055
 
                attr=MODATTR_EVENT_HANDLER_COMMAND;
3056
 
                break;
3057
 
 
3058
 
        case CMD_CHANGE_HOST_CHECK_COMMAND:
3059
 
 
3060
 
                my_free(temp_host->host_check_command);
3061
 
                temp_host->host_check_command=temp_ptr;
3062
 
                temp_host->check_command_ptr=temp_command;
3063
 
                attr=MODATTR_CHECK_COMMAND;
3064
 
                break;
3065
 
 
3066
 
        case CMD_CHANGE_HOST_CHECK_TIMEPERIOD:
3067
 
 
3068
 
                my_free(temp_host->check_period);
3069
 
                temp_host->check_period=temp_ptr;
3070
 
                temp_host->check_period_ptr=temp_timeperiod;
3071
 
                attr=MODATTR_CHECK_TIMEPERIOD;
3072
 
                break;
3073
 
 
3074
 
        case CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD:
3075
 
 
3076
 
                my_free(temp_host->notification_period);
3077
 
                temp_host->notification_period=temp_ptr;
3078
 
                temp_host->notification_period_ptr=temp_timeperiod;
3079
 
                attr=MODATTR_NOTIFICATION_TIMEPERIOD;
3080
 
                break;
3081
 
 
3082
 
        case CMD_CHANGE_SVC_EVENT_HANDLER:
3083
 
 
3084
 
                my_free(temp_service->event_handler);
3085
 
                temp_service->event_handler=temp_ptr;
3086
 
                temp_service->event_handler_ptr=temp_command;
3087
 
                attr=MODATTR_EVENT_HANDLER_COMMAND;
3088
 
                break;
3089
 
 
3090
 
        case CMD_CHANGE_SVC_CHECK_COMMAND:
3091
 
 
3092
 
                my_free(temp_service->service_check_command);
3093
 
                temp_service->service_check_command=temp_ptr;
3094
 
                temp_service->check_command_ptr=temp_command;
3095
 
                attr=MODATTR_CHECK_COMMAND;
3096
 
                break;
3097
 
 
3098
 
        case CMD_CHANGE_SVC_CHECK_TIMEPERIOD:
3099
 
 
3100
 
                my_free(temp_service->check_period);
3101
 
                temp_service->check_period=temp_ptr;
3102
 
                temp_service->check_period_ptr=temp_timeperiod;
3103
 
                attr=MODATTR_CHECK_TIMEPERIOD;
3104
 
                break;
3105
 
 
3106
 
        case CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD:
3107
 
 
3108
 
                my_free(temp_service->notification_period);
3109
 
                temp_service->notification_period=temp_ptr;
3110
 
                temp_service->notification_period_ptr=temp_timeperiod;
3111
 
                attr=MODATTR_NOTIFICATION_TIMEPERIOD;
3112
 
                break;
3113
 
 
3114
 
        case CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD:
3115
 
 
3116
 
                my_free(temp_contact->host_notification_period);
3117
 
                temp_contact->host_notification_period=temp_ptr;
3118
 
                temp_contact->host_notification_period_ptr=temp_timeperiod;
3119
 
                hattr=MODATTR_NOTIFICATION_TIMEPERIOD;
3120
 
                break;
3121
 
 
3122
 
        case CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD:
3123
 
 
3124
 
                my_free(temp_contact->service_notification_period);
3125
 
                temp_contact->service_notification_period=temp_ptr;
3126
 
                temp_contact->service_notification_period_ptr=temp_timeperiod;
3127
 
                sattr=MODATTR_NOTIFICATION_TIMEPERIOD;
3128
 
                break;
3129
 
 
3130
 
        default:
3131
 
                break;
3132
 
                }
 
3224
        switch(cmd) {
 
3225
 
 
3226
                case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
 
3227
 
 
3228
                        my_free(global_host_event_handler);
 
3229
                        global_host_event_handler = temp_ptr;
 
3230
                        global_host_event_handler_ptr = temp_command;
 
3231
                        attr = MODATTR_EVENT_HANDLER_COMMAND;
 
3232
                        break;
 
3233
 
 
3234
                case CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER:
 
3235
 
 
3236
                        my_free(global_service_event_handler);
 
3237
                        global_service_event_handler = temp_ptr;
 
3238
                        global_service_event_handler_ptr = temp_command;
 
3239
                        attr = MODATTR_EVENT_HANDLER_COMMAND;
 
3240
                        break;
 
3241
 
 
3242
                case CMD_CHANGE_HOST_EVENT_HANDLER:
 
3243
 
 
3244
                        my_free(temp_host->event_handler);
 
3245
                        temp_host->event_handler = temp_ptr;
 
3246
                        temp_host->event_handler_ptr = temp_command;
 
3247
                        attr = MODATTR_EVENT_HANDLER_COMMAND;
 
3248
                        break;
 
3249
 
 
3250
                case CMD_CHANGE_HOST_CHECK_COMMAND:
 
3251
 
 
3252
                        my_free(temp_host->host_check_command);
 
3253
                        temp_host->host_check_command = temp_ptr;
 
3254
                        temp_host->check_command_ptr = temp_command;
 
3255
                        attr = MODATTR_CHECK_COMMAND;
 
3256
                        break;
 
3257
 
 
3258
                case CMD_CHANGE_HOST_CHECK_TIMEPERIOD:
 
3259
 
 
3260
                        my_free(temp_host->check_period);
 
3261
                        temp_host->check_period = temp_ptr;
 
3262
                        temp_host->check_period_ptr = temp_timeperiod;
 
3263
                        attr = MODATTR_CHECK_TIMEPERIOD;
 
3264
                        break;
 
3265
 
 
3266
                case CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD:
 
3267
 
 
3268
                        my_free(temp_host->notification_period);
 
3269
                        temp_host->notification_period = temp_ptr;
 
3270
                        temp_host->notification_period_ptr = temp_timeperiod;
 
3271
                        attr = MODATTR_NOTIFICATION_TIMEPERIOD;
 
3272
                        break;
 
3273
 
 
3274
                case CMD_CHANGE_SVC_EVENT_HANDLER:
 
3275
 
 
3276
                        my_free(temp_service->event_handler);
 
3277
                        temp_service->event_handler = temp_ptr;
 
3278
                        temp_service->event_handler_ptr = temp_command;
 
3279
                        attr = MODATTR_EVENT_HANDLER_COMMAND;
 
3280
                        break;
 
3281
 
 
3282
                case CMD_CHANGE_SVC_CHECK_COMMAND:
 
3283
 
 
3284
                        my_free(temp_service->service_check_command);
 
3285
                        temp_service->service_check_command = temp_ptr;
 
3286
                        temp_service->check_command_ptr = temp_command;
 
3287
                        attr = MODATTR_CHECK_COMMAND;
 
3288
                        break;
 
3289
 
 
3290
                case CMD_CHANGE_SVC_CHECK_TIMEPERIOD:
 
3291
 
 
3292
                        my_free(temp_service->check_period);
 
3293
                        temp_service->check_period = temp_ptr;
 
3294
                        temp_service->check_period_ptr = temp_timeperiod;
 
3295
                        attr = MODATTR_CHECK_TIMEPERIOD;
 
3296
                        break;
 
3297
 
 
3298
                case CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD:
 
3299
 
 
3300
                        my_free(temp_service->notification_period);
 
3301
                        temp_service->notification_period = temp_ptr;
 
3302
                        temp_service->notification_period_ptr = temp_timeperiod;
 
3303
                        attr = MODATTR_NOTIFICATION_TIMEPERIOD;
 
3304
                        break;
 
3305
 
 
3306
                case CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD:
 
3307
 
 
3308
                        my_free(temp_contact->host_notification_period);
 
3309
                        temp_contact->host_notification_period = temp_ptr;
 
3310
                        temp_contact->host_notification_period_ptr = temp_timeperiod;
 
3311
                        hattr = MODATTR_NOTIFICATION_TIMEPERIOD;
 
3312
                        break;
 
3313
 
 
3314
                case CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD:
 
3315
 
 
3316
                        my_free(temp_contact->service_notification_period);
 
3317
                        temp_contact->service_notification_period = temp_ptr;
 
3318
                        temp_contact->service_notification_period_ptr = temp_timeperiod;
 
3319
                        sattr = MODATTR_NOTIFICATION_TIMEPERIOD;
 
3320
                        break;
 
3321
 
 
3322
                default:
 
3323
                        break;
 
3324
                }
3133
3325
 
3134
3326
 
3135
3327
        /* send data to event broker and update status file */
3136
 
        switch(cmd){
3137
 
 
3138
 
        case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
3139
 
 
3140
 
                /* set the modified host attribute */
3141
 
                modified_host_process_attributes|=attr;
3142
 
 
3143
 
#ifdef USE_EVENT_BROKER
3144
 
                /* send data to event broker */
3145
 
                broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,cmd,attr,modified_host_process_attributes,MODATTR_NONE,modified_service_process_attributes,NULL);
3146
 
#endif
3147
 
 
3148
 
                /* update program status */
3149
 
                update_program_status(FALSE);
3150
 
 
3151
 
                break;
3152
 
 
3153
 
        case CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER:
3154
 
 
3155
 
                /* set the modified service attribute */
3156
 
                modified_service_process_attributes|=attr;
3157
 
 
3158
 
#ifdef USE_EVENT_BROKER
3159
 
                /* send data to event broker */
3160
 
                broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,cmd,MODATTR_NONE,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
3161
 
#endif
3162
 
 
3163
 
                /* update program status */
3164
 
                update_program_status(FALSE);
3165
 
 
3166
 
                break;
3167
 
 
3168
 
        case CMD_CHANGE_SVC_EVENT_HANDLER:
3169
 
        case CMD_CHANGE_SVC_CHECK_COMMAND:
3170
 
        case CMD_CHANGE_SVC_CHECK_TIMEPERIOD:
3171
 
        case CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD:
3172
 
 
3173
 
                /* set the modified service attribute */
3174
 
                temp_service->modified_attributes|=attr;
3175
 
 
3176
 
#ifdef USE_EVENT_BROKER
3177
 
                /* send data to event broker */
3178
 
                broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,temp_service,cmd,attr,temp_service->modified_attributes,NULL);
3179
 
#endif
3180
 
 
3181
 
                /* update the status log with the service info */
3182
 
                update_service_status(temp_service,FALSE);
3183
 
 
3184
 
                break;
3185
 
 
3186
 
        case CMD_CHANGE_HOST_EVENT_HANDLER:
3187
 
        case CMD_CHANGE_HOST_CHECK_COMMAND:
3188
 
        case CMD_CHANGE_HOST_CHECK_TIMEPERIOD:
3189
 
        case CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD:
3190
 
 
3191
 
                /* set the modified host attribute */
3192
 
                temp_host->modified_attributes|=attr;
3193
 
 
3194
 
#ifdef USE_EVENT_BROKER
3195
 
                /* send data to event broker */
3196
 
                broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,temp_host,cmd,attr,temp_host->modified_attributes,NULL);
3197
 
#endif
3198
 
 
3199
 
                /* update the status log with the host info */
3200
 
                update_host_status(temp_host,FALSE);
3201
 
                break;
3202
 
 
3203
 
        case CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD:
3204
 
        case CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD:
3205
 
 
3206
 
                /* set the modified attributes */
3207
 
                temp_contact->modified_host_attributes|=hattr;
3208
 
                temp_contact->modified_service_attributes|=sattr;
3209
 
 
3210
 
#ifdef USE_EVENT_BROKER
3211
 
                /* send data to event broker */
3212
 
                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);
3213
 
#endif
3214
 
 
3215
 
                /* update the status log with the contact info */
3216
 
                update_contact_status(temp_contact,FALSE);
3217
 
                break;
3218
 
 
3219
 
        default:
3220
 
                break;
3221
 
                }
 
3328
        switch(cmd) {
 
3329
 
 
3330
                case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
 
3331
 
 
3332
                        /* set the modified host attribute */
 
3333
                        modified_host_process_attributes |= attr;
 
3334
 
 
3335
#ifdef USE_EVENT_BROKER
 
3336
                        /* send data to event broker */
 
3337
                        broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, cmd, attr, modified_host_process_attributes, MODATTR_NONE, modified_service_process_attributes, NULL);
 
3338
#endif
 
3339
 
 
3340
                        /* update program status */
 
3341
                        update_program_status(FALSE);
 
3342
 
 
3343
                        break;
 
3344
 
 
3345
                case CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER:
 
3346
 
 
3347
                        /* set the modified service attribute */
 
3348
                        modified_service_process_attributes |= attr;
 
3349
 
 
3350
#ifdef USE_EVENT_BROKER
 
3351
                        /* send data to event broker */
 
3352
                        broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, cmd, MODATTR_NONE, modified_host_process_attributes, attr, modified_service_process_attributes, NULL);
 
3353
#endif
 
3354
 
 
3355
                        /* update program status */
 
3356
                        update_program_status(FALSE);
 
3357
 
 
3358
                        break;
 
3359
 
 
3360
                case CMD_CHANGE_SVC_EVENT_HANDLER:
 
3361
                case CMD_CHANGE_SVC_CHECK_COMMAND:
 
3362
                case CMD_CHANGE_SVC_CHECK_TIMEPERIOD:
 
3363
                case CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD:
 
3364
 
 
3365
                        /* set the modified service attribute */
 
3366
                        temp_service->modified_attributes |= attr;
 
3367
 
 
3368
#ifdef USE_EVENT_BROKER
 
3369
                        /* send data to event broker */
 
3370
                        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, temp_service, cmd, attr, temp_service->modified_attributes, NULL);
 
3371
#endif
 
3372
 
 
3373
                        /* update the status log with the service info */
 
3374
                        update_service_status(temp_service, FALSE);
 
3375
 
 
3376
                        break;
 
3377
 
 
3378
                case CMD_CHANGE_HOST_EVENT_HANDLER:
 
3379
                case CMD_CHANGE_HOST_CHECK_COMMAND:
 
3380
                case CMD_CHANGE_HOST_CHECK_TIMEPERIOD:
 
3381
                case CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD:
 
3382
 
 
3383
                        /* set the modified host attribute */
 
3384
                        temp_host->modified_attributes |= attr;
 
3385
 
 
3386
#ifdef USE_EVENT_BROKER
 
3387
                        /* send data to event broker */
 
3388
                        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, temp_host, cmd, attr, temp_host->modified_attributes, NULL);
 
3389
#endif
 
3390
 
 
3391
                        /* update the status log with the host info */
 
3392
                        update_host_status(temp_host, FALSE);
 
3393
                        break;
 
3394
 
 
3395
                case CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD:
 
3396
                case CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD:
 
3397
 
 
3398
                        /* set the modified attributes */
 
3399
                        temp_contact->modified_host_attributes |= hattr;
 
3400
                        temp_contact->modified_service_attributes |= sattr;
 
3401
 
 
3402
#ifdef USE_EVENT_BROKER
 
3403
                        /* send data to event broker */
 
3404
                        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);
 
3405
#endif
 
3406
 
 
3407
                        /* update the status log with the contact info */
 
3408
                        update_contact_status(temp_contact, FALSE);
 
3409
                        break;
 
3410
 
 
3411
                default:
 
3412
                        break;
 
3413
                }
3222
3414
 
3223
3415
        return OK;
3224
 
        }
 
3416
        }
3225
3417
 
3226
3418
 
3227
3419
 
3228
3420
/* changes a custom host or service variable */
3229
 
int cmd_change_object_custom_var(int cmd, char *args){
3230
 
        host *temp_host=NULL;
3231
 
        service *temp_service=NULL;
3232
 
        contact *temp_contact=NULL;
3233
 
        customvariablesmember *temp_customvariablesmember=NULL;
3234
 
        char *temp_ptr=NULL;
3235
 
        char *name1=NULL;
3236
 
        char *name2=NULL;
3237
 
        char *varname=NULL;
3238
 
        char *varvalue=NULL;
3239
 
        register int x=0;
 
3421
int cmd_change_object_custom_var(int cmd, char *args) {
 
3422
        host *temp_host = NULL;
 
3423
        service *temp_service = NULL;
 
3424
        contact *temp_contact = NULL;
 
3425
        customvariablesmember *temp_customvariablesmember = NULL;
 
3426
        char *temp_ptr = NULL;
 
3427
        char *name1 = NULL;
 
3428
        char *name2 = NULL;
 
3429
        char *varname = NULL;
 
3430
        char *varvalue = NULL;
 
3431
        register int x = 0;
3240
3432
 
3241
3433
        /* get the host or contact name */
3242
 
        if((temp_ptr=my_strtok(args,";"))==NULL)
 
3434
        if((temp_ptr = my_strtok(args, ";")) == NULL)
3243
3435
                return ERROR;
3244
 
        if((name1=(char *)strdup(temp_ptr))==NULL)
 
3436
        if((name1 = (char *)strdup(temp_ptr)) == NULL)
3245
3437
                return ERROR;
3246
3438
 
3247
3439
        /* get the service description if necessary */
3248
 
        if(cmd==CMD_CHANGE_CUSTOM_SVC_VAR){
3249
 
                if((temp_ptr=my_strtok(NULL,";"))==NULL){
3250
 
                        my_free(name1);
3251
 
                        return ERROR;
3252
 
                        }
3253
 
                if((name2=(char *)strdup(temp_ptr))==NULL){
3254
 
                        my_free(name1);
3255
 
                        return ERROR;
3256
 
                        }
3257
 
                }
 
3440
        if(cmd == CMD_CHANGE_CUSTOM_SVC_VAR) {
 
3441
                if((temp_ptr = my_strtok(NULL, ";")) == NULL) {
 
3442
                        my_free(name1);
 
3443
                        return ERROR;
 
3444
                        }
 
3445
                if((name2 = (char *)strdup(temp_ptr)) == NULL) {
 
3446
                        my_free(name1);
 
3447
                        return ERROR;
 
3448
                        }
 
3449
                }
3258
3450
 
3259
3451
        /* get the custom variable name */
3260
 
        if((temp_ptr=my_strtok(NULL,";"))==NULL){
3261
 
                my_free(name1);
3262
 
                my_free(name2);
3263
 
                return ERROR;
3264
 
                }
3265
 
        if((varname=(char *)strdup(temp_ptr))==NULL){
3266
 
                my_free(name1);
3267
 
                my_free(name2);
3268
 
                return ERROR;
3269
 
                }
 
3452
        if((temp_ptr = my_strtok(NULL, ";")) == NULL) {
 
3453
                my_free(name1);
 
3454
                my_free(name2);
 
3455
                return ERROR;
 
3456
                }
 
3457
        if((varname = (char *)strdup(temp_ptr)) == NULL) {
 
3458
                my_free(name1);
 
3459
                my_free(name2);
 
3460
                return ERROR;
 
3461
                }
3270
3462
 
3271
3463
        /* get the custom variable value */
3272
 
        if((temp_ptr=my_strtok(NULL,";"))==NULL){
3273
 
                my_free(name1);
3274
 
                my_free(name2);
3275
 
                my_free(varname);
3276
 
                return ERROR;
3277
 
                }
3278
 
        if((varvalue=(char *)strdup(temp_ptr))==NULL){
3279
 
                my_free(name1);
3280
 
                my_free(name2);
3281
 
                my_free(varname);
3282
 
                return ERROR;
3283
 
                }
 
3464
        if((temp_ptr = my_strtok(NULL, ";")) == NULL) {
 
3465
                my_free(name1);
 
3466
                my_free(name2);
 
3467
                my_free(varname);
 
3468
                return ERROR;
 
3469
                }
 
3470
        if((varvalue = (char *)strdup(temp_ptr)) == NULL) {
 
3471
                my_free(name1);
 
3472
                my_free(name2);
 
3473
                my_free(varname);
 
3474
                return ERROR;
 
3475
                }
3284
3476
 
3285
3477
        /* find the object */
3286
 
        switch(cmd){
3287
 
        case CMD_CHANGE_CUSTOM_HOST_VAR:
3288
 
                temp_host=find_host(name1);
3289
 
                temp_customvariablesmember=temp_host->custom_variables;
3290
 
                break;
3291
 
        case CMD_CHANGE_CUSTOM_SVC_VAR:
3292
 
                temp_service=find_service(name1,name2);
3293
 
                temp_customvariablesmember=temp_service->custom_variables;
3294
 
                break;
3295
 
        case CMD_CHANGE_CUSTOM_CONTACT_VAR:
3296
 
                temp_contact=find_contact(name1);
3297
 
                temp_customvariablesmember=temp_contact->custom_variables;
3298
 
                break;
3299
 
        default:
3300
 
                break;
3301
 
                }
 
3478
        switch(cmd) {
 
3479
                case CMD_CHANGE_CUSTOM_HOST_VAR:
 
3480
                        if((temp_host = find_host(name1)) == NULL)
 
3481
                                return ERROR;
 
3482
                        temp_customvariablesmember = temp_host->custom_variables;
 
3483
                        break;
 
3484
                case CMD_CHANGE_CUSTOM_SVC_VAR:
 
3485
                        if((temp_service = find_service(name1, name2)) == NULL)
 
3486
                                return ERROR;
 
3487
                        temp_customvariablesmember = temp_service->custom_variables;
 
3488
                        break;
 
3489
                case CMD_CHANGE_CUSTOM_CONTACT_VAR:
 
3490
                        if((temp_contact = find_contact(name1)) == NULL)
 
3491
                                return ERROR;
 
3492
                        temp_customvariablesmember = temp_contact->custom_variables;
 
3493
                        break;
 
3494
                default:
 
3495
                        break;
 
3496
                }
3302
3497
 
3303
3498
        /* capitalize the custom variable name */
3304
 
        for(x=0;varname[x]!='\x0';x++)
3305
 
                varname[x]=toupper(varname[x]);
 
3499
        for(x = 0; varname[x] != '\x0'; x++)
 
3500
                varname[x] = toupper(varname[x]);
3306
3501
 
3307
3502
        /* find the proper variable */
3308
 
        for(;temp_customvariablesmember!=NULL;temp_customvariablesmember=temp_customvariablesmember->next){
3309
 
                
 
3503
        for(; temp_customvariablesmember != NULL; temp_customvariablesmember = temp_customvariablesmember->next) {
 
3504
 
3310
3505
                /* we found the variable, so update the value */
3311
 
                if(!strcmp(varname,temp_customvariablesmember->variable_name)){
 
3506
                if(!strcmp(varname, temp_customvariablesmember->variable_name)) {
3312
3507
 
3313
3508
                        /* update the value */
3314
3509
                        if(temp_customvariablesmember->variable_value)
3315
3510
                                my_free(temp_customvariablesmember->variable_value);
3316
 
                        temp_customvariablesmember->variable_value=(char *)strdup(varvalue);
 
3511
                        temp_customvariablesmember->variable_value = (char *)strdup(varvalue);
3317
3512
 
3318
3513
                        /* mark the variable value as having been changed */
3319
 
                        temp_customvariablesmember->has_been_modified=TRUE;
 
3514
                        temp_customvariablesmember->has_been_modified = TRUE;
3320
3515
 
3321
3516
                        break;
3322
 
                        }
3323
 
                }
 
3517
                        }
 
3518
                }
3324
3519
 
3325
3520
        /* free memory */
3326
3521
        my_free(name1);
3329
3524
        my_free(varvalue);
3330
3525
 
3331
3526
        /* set the modified attributes and update the status of the object */
3332
 
        switch(cmd){
3333
 
        case CMD_CHANGE_CUSTOM_HOST_VAR:
3334
 
                temp_host->modified_attributes|=MODATTR_CUSTOM_VARIABLE;
3335
 
                update_host_status(temp_host,FALSE);
3336
 
                break;
3337
 
        case CMD_CHANGE_CUSTOM_SVC_VAR:
3338
 
                temp_service->modified_attributes|=MODATTR_CUSTOM_VARIABLE;
3339
 
                update_service_status(temp_service,FALSE);
3340
 
                break;
3341
 
        case CMD_CHANGE_CUSTOM_CONTACT_VAR:
3342
 
                temp_contact->modified_attributes|=MODATTR_CUSTOM_VARIABLE;
3343
 
                update_contact_status(temp_contact,FALSE);
3344
 
                break;
3345
 
        default:
3346
 
                break;
3347
 
                }
 
3527
        switch(cmd) {
 
3528
                case CMD_CHANGE_CUSTOM_HOST_VAR:
 
3529
                        temp_host->modified_attributes |= MODATTR_CUSTOM_VARIABLE;
 
3530
                        update_host_status(temp_host, FALSE);
 
3531
                        break;
 
3532
                case CMD_CHANGE_CUSTOM_SVC_VAR:
 
3533
                        temp_service->modified_attributes |= MODATTR_CUSTOM_VARIABLE;
 
3534
                        update_service_status(temp_service, FALSE);
 
3535
                        break;
 
3536
                case CMD_CHANGE_CUSTOM_CONTACT_VAR:
 
3537
                        temp_contact->modified_attributes |= MODATTR_CUSTOM_VARIABLE;
 
3538
                        update_contact_status(temp_contact, FALSE);
 
3539
                        break;
 
3540
                default:
 
3541
                        break;
 
3542
                }
3348
3543
 
3349
3544
        return OK;
3350
 
        }
3351
 
        
 
3545
        }
 
3546
 
3352
3547
 
3353
3548
/* processes an external host command */
3354
 
int cmd_process_external_commands_from_file(int cmd, char *args){
3355
 
        char *fname=NULL;
3356
 
        char *temp_ptr=NULL;
3357
 
        int delete_file=FALSE;
 
3549
int cmd_process_external_commands_from_file(int cmd, char *args) {
 
3550
        char *fname = NULL;
 
3551
        char *temp_ptr = NULL;
 
3552
        int delete_file = FALSE;
3358
3553
 
3359
3554
        /* get the file name */
3360
 
        if((temp_ptr=my_strtok(args,";"))==NULL)
 
3555
        if((temp_ptr = my_strtok(args, ";")) == NULL)
3361
3556
                return ERROR;
3362
 
        if((fname=(char *)strdup(temp_ptr))==NULL)
 
3557
        if((fname = (char *)strdup(temp_ptr)) == NULL)
3363
3558
                return ERROR;
3364
3559
 
3365
3560
        /* find the deletion option */
3366
 
        if((temp_ptr=my_strtok(NULL,"\n"))==NULL){
 
3561
        if((temp_ptr = my_strtok(NULL, "\n")) == NULL) {
3367
3562
                my_free(fname);
3368
3563
                return ERROR;
3369
 
                }
3370
 
        if(atoi(temp_ptr)==0)
3371
 
                delete_file=FALSE;
 
3564
                }
 
3565
        if(atoi(temp_ptr) == 0)
 
3566
                delete_file = FALSE;
3372
3567
        else
3373
 
                delete_file=TRUE;
 
3568
                delete_file = TRUE;
3374
3569
 
3375
3570
        /* process the file */
3376
 
        process_external_commands_from_file(fname,delete_file);
 
3571
        process_external_commands_from_file(fname, delete_file);
3377
3572
 
3378
3573
        /* free memory */
3379
3574
        my_free(fname);
3380
3575
 
3381
3576
        return OK;
3382
 
        }
 
3577
        }
3383
3578
 
3384
3579
 
3385
3580
/******************************************************************/
3387
3582
/******************************************************************/
3388
3583
 
3389
3584
/* temporarily disables a service check */
3390
 
void disable_service_checks(service *svc){
3391
 
        unsigned long attr=MODATTR_ACTIVE_CHECKS_ENABLED;
 
3585
void disable_service_checks(service *svc) {
 
3586
        unsigned long attr = MODATTR_ACTIVE_CHECKS_ENABLED;
3392
3587
 
3393
3588
        /* checks are already disabled */
3394
 
        if(svc->checks_enabled==FALSE)
 
3589
        if(svc->checks_enabled == FALSE)
3395
3590
                return;
3396
3591
 
3397
3592
        /* set the attribute modified flag */
3398
 
        svc->modified_attributes|=attr;
 
3593
        svc->modified_attributes |= attr;
3399
3594
 
3400
3595
        /* disable the service check... */
3401
 
        svc->checks_enabled=FALSE;
3402
 
        svc->should_be_scheduled=FALSE;
 
3596
        svc->checks_enabled = FALSE;
 
3597
        svc->should_be_scheduled = FALSE;
3403
3598
 
3404
3599
#ifdef USE_EVENT_BROKER
3405
3600
        /* send data to event broker */
3406
 
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
 
3601
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
3407
3602
#endif
3408
3603
 
3409
3604
        /* update the status log to reflect the new service state */
3410
 
        update_service_status(svc,FALSE);
 
3605
        update_service_status(svc, FALSE);
3411
3606
 
3412
3607
        return;
3413
 
        }
 
3608
        }
3414
3609
 
3415
3610
 
3416
3611
 
3417
3612
/* enables a service check */
3418
 
void enable_service_checks(service *svc){
3419
 
        time_t preferred_time=0L;
3420
 
        time_t next_valid_time=0L;
3421
 
        unsigned long attr=MODATTR_ACTIVE_CHECKS_ENABLED;
 
3613
void enable_service_checks(service *svc) {
 
3614
        time_t preferred_time = 0L;
 
3615
        time_t next_valid_time = 0L;
 
3616
        unsigned long attr = MODATTR_ACTIVE_CHECKS_ENABLED;
3422
3617
 
3423
3618
        /* checks are already enabled */
3424
 
        if(svc->checks_enabled==TRUE)
 
3619
        if(svc->checks_enabled == TRUE)
3425
3620
                return;
3426
3621
 
3427
3622
        /* set the attribute modified flag */
3428
 
        svc->modified_attributes|=attr;
 
3623
        svc->modified_attributes |= attr;
3429
3624
 
3430
3625
        /* enable the service check... */
3431
 
        svc->checks_enabled=TRUE;
3432
 
        svc->should_be_scheduled=TRUE;
 
3626
        svc->checks_enabled = TRUE;
 
3627
        svc->should_be_scheduled = TRUE;
3433
3628
 
3434
3629
        /* services with no check intervals don't get checked */
3435
 
        if(svc->check_interval==0)
3436
 
                svc->should_be_scheduled=FALSE;
 
3630
        if(svc->check_interval == 0)
 
3631
                svc->should_be_scheduled = FALSE;
3437
3632
 
3438
3633
        /* schedule a check for right now (or as soon as possible) */
3439
3634
        time(&preferred_time);
3440
 
        if(check_time_against_period(preferred_time,svc->check_period_ptr)==ERROR){
3441
 
                get_next_valid_time(preferred_time,&next_valid_time,svc->check_period_ptr);
3442
 
                svc->next_check=next_valid_time;
3443
 
                }
 
3635
        if(check_time_against_period(preferred_time, svc->check_period_ptr) == ERROR) {
 
3636
                get_next_valid_time(preferred_time, &next_valid_time, svc->check_period_ptr);
 
3637
                svc->next_check = next_valid_time;
 
3638
                }
3444
3639
        else
3445
 
                svc->next_check=preferred_time;
 
3640
                svc->next_check = preferred_time;
3446
3641
 
3447
3642
        /* schedule a check if we should */
3448
 
        if(svc->should_be_scheduled==TRUE)
3449
 
                schedule_service_check(svc,svc->next_check,CHECK_OPTION_NONE);
 
3643
        if(svc->should_be_scheduled == TRUE)
 
3644
                schedule_service_check(svc, svc->next_check, CHECK_OPTION_NONE);
3450
3645
 
3451
3646
#ifdef USE_EVENT_BROKER
3452
3647
        /* send data to event broker */
3453
 
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
 
3648
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
3454
3649
#endif
3455
3650
 
3456
3651
        /* update the status log to reflect the new service state */
3457
 
        update_service_status(svc,FALSE);
 
3652
        update_service_status(svc, FALSE);
3458
3653
 
3459
3654
        return;
3460
 
        }
 
3655
        }
3461
3656
 
3462
3657
 
3463
3658
 
3464
3659
/* enable notifications on a program-wide basis */
3465
 
void enable_all_notifications(void){
3466
 
        unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
 
3660
void enable_all_notifications(void) {
 
3661
        unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3467
3662
 
3468
3663
        /* bail out if we're already set... */
3469
 
        if(enable_notifications==TRUE)
 
3664
        if(enable_notifications == TRUE)
3470
3665
                return;
3471
3666
 
3472
3667
        /* set the attribute modified flag */
3473
 
        modified_host_process_attributes|=attr;
3474
 
        modified_service_process_attributes|=attr;
 
3668
        modified_host_process_attributes |= attr;
 
3669
        modified_service_process_attributes |= attr;
3475
3670
 
3476
3671
        /* update notification status */
3477
 
        enable_notifications=TRUE;
 
3672
        enable_notifications = TRUE;
3478
3673
 
3479
3674
#ifdef USE_EVENT_BROKER
3480
3675
        /* send data to event broker */
3481
 
        broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
 
3676
        broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, CMD_NONE, attr, modified_host_process_attributes, attr, modified_service_process_attributes, NULL);
3482
3677
#endif
3483
3678
 
3484
3679
        /* update the status log */
3485
3680
        update_program_status(FALSE);
3486
3681
 
3487
3682
        return;
3488
 
        }
 
3683
        }
3489
3684
 
3490
3685
 
3491
3686
/* disable notifications on a program-wide basis */
3492
 
void disable_all_notifications(void){
3493
 
        unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
 
3687
void disable_all_notifications(void) {
 
3688
        unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3494
3689
 
3495
3690
        /* bail out if we're already set... */
3496
 
        if(enable_notifications==FALSE)
 
3691
        if(enable_notifications == FALSE)
3497
3692
                return;
3498
3693
 
3499
3694
        /* set the attribute modified flag */
3500
 
        modified_host_process_attributes|=attr;
3501
 
        modified_service_process_attributes|=attr;
 
3695
        modified_host_process_attributes |= attr;
 
3696
        modified_service_process_attributes |= attr;
3502
3697
 
3503
3698
        /* update notification status */
3504
 
        enable_notifications=FALSE;
 
3699
        enable_notifications = FALSE;
3505
3700
 
3506
3701
#ifdef USE_EVENT_BROKER
3507
3702
        /* send data to event broker */
3508
 
        broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
 
3703
        broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, CMD_NONE, attr, modified_host_process_attributes, attr, modified_service_process_attributes, NULL);
3509
3704
#endif
3510
3705
 
3511
3706
        /* update the status log */
3512
3707
        update_program_status(FALSE);
3513
3708
 
3514
3709
        return;
3515
 
        }
 
3710
        }
3516
3711
 
3517
3712
 
3518
3713
/* enables notifications for a service */
3519
 
void enable_service_notifications(service *svc){
3520
 
        unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
 
3714
void enable_service_notifications(service *svc) {
 
3715
        unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3521
3716
 
3522
3717
        /* no change */
3523
 
        if(svc->notifications_enabled==TRUE)
 
3718
        if(svc->notifications_enabled == TRUE)
3524
3719
                return;
3525
3720
 
3526
3721
        /* set the attribute modified flag */
3527
 
        svc->modified_attributes|=attr;
 
3722
        svc->modified_attributes |= attr;
3528
3723
 
3529
3724
        /* enable the service notifications... */
3530
 
        svc->notifications_enabled=TRUE;
 
3725
        svc->notifications_enabled = TRUE;
3531
3726
 
3532
3727
#ifdef USE_EVENT_BROKER
3533
3728
        /* send data to event broker */
3534
 
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
 
3729
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
3535
3730
#endif
3536
3731
 
3537
3732
        /* update the status log to reflect the new service state */
3538
 
        update_service_status(svc,FALSE);
 
3733
        update_service_status(svc, FALSE);
3539
3734
 
3540
3735
        return;
3541
 
        }
 
3736
        }
3542
3737
 
3543
3738
 
3544
3739
/* disables notifications for a service */
3545
 
void disable_service_notifications(service *svc){
3546
 
        unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
 
3740
void disable_service_notifications(service *svc) {
 
3741
        unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3547
3742
 
3548
3743
        /* no change */
3549
 
        if(svc->notifications_enabled==FALSE)
 
3744
        if(svc->notifications_enabled == FALSE)
3550
3745
                return;
3551
3746
 
3552
3747
        /* set the attribute modified flag */
3553
 
        svc->modified_attributes|=attr;
 
3748
        svc->modified_attributes |= attr;
3554
3749
 
3555
3750
        /* disable the service notifications... */
3556
 
        svc->notifications_enabled=FALSE;
 
3751
        svc->notifications_enabled = FALSE;
3557
3752
 
3558
3753
#ifdef USE_EVENT_BROKER
3559
3754
        /* send data to event broker */
3560
 
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
 
3755
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
3561
3756
#endif
3562
3757
 
3563
3758
        /* update the status log to reflect the new service state */
3564
 
        update_service_status(svc,FALSE);
 
3759
        update_service_status(svc, FALSE);
3565
3760
 
3566
3761
        return;
3567
 
        }
 
3762
        }
3568
3763
 
3569
3764
 
3570
3765
/* enables notifications for a host */
3571
 
void enable_host_notifications(host *hst){
3572
 
        unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
 
3766
void enable_host_notifications(host *hst) {
 
3767
        unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3573
3768
 
3574
3769
        /* no change */
3575
 
        if(hst->notifications_enabled==TRUE)
 
3770
        if(hst->notifications_enabled == TRUE)
3576
3771
                return;
3577
3772
 
3578
3773
        /* set the attribute modified flag */
3579
 
        hst->modified_attributes|=attr;
 
3774
        hst->modified_attributes |= attr;
3580
3775
 
3581
3776
        /* enable the host notifications... */
3582
 
        hst->notifications_enabled=TRUE;
 
3777
        hst->notifications_enabled = TRUE;
3583
3778
 
3584
3779
#ifdef USE_EVENT_BROKER
3585
3780
        /* send data to event broker */
3586
 
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
 
3781
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
3587
3782
#endif
3588
3783
 
3589
3784
        /* update the status log to reflect the new host state */
3590
 
        update_host_status(hst,FALSE);
 
3785
        update_host_status(hst, FALSE);
3591
3786
 
3592
3787
        return;
3593
 
        }
 
3788
        }
3594
3789
 
3595
3790
 
3596
3791
/* disables notifications for a host */
3597
 
void disable_host_notifications(host *hst){
3598
 
        unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
 
3792
void disable_host_notifications(host *hst) {
 
3793
        unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3599
3794
 
3600
3795
        /* no change */
3601
 
        if(hst->notifications_enabled==FALSE)
 
3796
        if(hst->notifications_enabled == FALSE)
3602
3797
                return;
3603
3798
 
3604
3799
        /* set the attribute modified flag */
3605
 
        hst->modified_attributes|=attr;
 
3800
        hst->modified_attributes |= attr;
3606
3801
 
3607
3802
        /* disable the host notifications... */
3608
 
        hst->notifications_enabled=FALSE;
 
3803
        hst->notifications_enabled = FALSE;
3609
3804
 
3610
3805
#ifdef USE_EVENT_BROKER
3611
3806
        /* send data to event broker */
3612
 
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
 
3807
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
3613
3808
#endif
3614
3809
 
3615
3810
        /* update the status log to reflect the new host state */
3616
 
        update_host_status(hst,FALSE);
 
3811
        update_host_status(hst, FALSE);
3617
3812
 
3618
3813
        return;
3619
 
        }
 
3814
        }
3620
3815
 
3621
3816
 
3622
3817
/* enables notifications for all hosts and services "beyond" a given host */
3623
 
void enable_and_propagate_notifications(host *hst, int level, int affect_top_host, int affect_hosts, int affect_services){
3624
 
        host *child_host=NULL;
3625
 
        service *temp_service=NULL;
3626
 
        servicesmember *temp_servicesmember=NULL;
3627
 
        hostsmember *temp_hostsmember=NULL;
 
3818
void enable_and_propagate_notifications(host *hst, int level, int affect_top_host, int affect_hosts, int affect_services) {
 
3819
        host *child_host = NULL;
 
3820
        service *temp_service = NULL;
 
3821
        servicesmember *temp_servicesmember = NULL;
 
3822
        hostsmember *temp_hostsmember = NULL;
3628
3823
 
3629
3824
        /* enable notification for top level host */
3630
 
        if(affect_top_host==TRUE && level==0)
 
3825
        if(affect_top_host == TRUE && level == 0)
3631
3826
                enable_host_notifications(hst);
3632
3827
 
3633
3828
        /* check all child hosts... */
3634
 
        for(temp_hostsmember=hst->child_hosts;temp_hostsmember!=NULL;temp_hostsmember=temp_hostsmember->next){
 
3829
        for(temp_hostsmember = hst->child_hosts; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
3635
3830
 
3636
 
                if((child_host=temp_hostsmember->host_ptr)==NULL)
 
3831
                if((child_host = temp_hostsmember->host_ptr) == NULL)
3637
3832
                        continue;
3638
3833
 
3639
3834
                /* recurse... */
3640
 
                enable_and_propagate_notifications(child_host,level+1,affect_top_host,affect_hosts,affect_services);
 
3835
                enable_and_propagate_notifications(child_host, level + 1, affect_top_host, affect_hosts, affect_services);
3641
3836
 
3642
3837
                /* enable notifications for this host */
3643
 
                if(affect_hosts==TRUE)
 
3838
                if(affect_hosts == TRUE)
3644
3839
                        enable_host_notifications(child_host);
3645
3840
 
3646
3841
                /* enable notifications for all services on this host... */
3647
 
                if(affect_services==TRUE){
3648
 
                        for(temp_servicesmember=child_host->services;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
3649
 
                                if((temp_service=temp_servicesmember->service_ptr)==NULL)
 
3842
                if(affect_services == TRUE) {
 
3843
                        for(temp_servicesmember = child_host->services; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {
 
3844
                                if((temp_service = temp_servicesmember->service_ptr) == NULL)
3650
3845
                                        continue;
3651
3846
                                enable_service_notifications(temp_service);
3652
 
                                }
3653
 
                        }
3654
 
                }
 
3847
                                }
 
3848
                        }
 
3849
                }
3655
3850
 
3656
3851
        return;
3657
 
        }
 
3852
        }
3658
3853
 
3659
3854
 
3660
3855
/* disables notifications for all hosts and services "beyond" a given host */
3661
 
void disable_and_propagate_notifications(host *hst, int level, int affect_top_host, int affect_hosts, int affect_services){
3662
 
        host *child_host=NULL;
3663
 
        service *temp_service=NULL;
3664
 
        servicesmember *temp_servicesmember=NULL;
3665
 
        hostsmember *temp_hostsmember=NULL;
 
3856
void disable_and_propagate_notifications(host *hst, int level, int affect_top_host, int affect_hosts, int affect_services) {
 
3857
        host *child_host = NULL;
 
3858
        service *temp_service = NULL;
 
3859
        servicesmember *temp_servicesmember = NULL;
 
3860
        hostsmember *temp_hostsmember = NULL;
3666
3861
 
3667
 
        if(hst==NULL)
 
3862
        if(hst == NULL)
3668
3863
                return;
3669
3864
 
3670
3865
        /* disable notifications for top host */
3671
 
        if(affect_top_host==TRUE && level==0)
 
3866
        if(affect_top_host == TRUE && level == 0)
3672
3867
                disable_host_notifications(hst);
3673
3868
 
3674
3869
        /* check all child hosts... */
3675
 
        for(temp_hostsmember=hst->child_hosts;temp_hostsmember!=NULL;temp_hostsmember=temp_hostsmember->next){
 
3870
        for(temp_hostsmember = hst->child_hosts; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
3676
3871
 
3677
 
                if((child_host=temp_hostsmember->host_ptr)==NULL)
 
3872
                if((child_host = temp_hostsmember->host_ptr) == NULL)
3678
3873
                        continue;
3679
3874
 
3680
3875
                /* recurse... */
3681
 
                disable_and_propagate_notifications(child_host,level+1,affect_top_host,affect_hosts,affect_services);
 
3876
                disable_and_propagate_notifications(child_host, level + 1, affect_top_host, affect_hosts, affect_services);
3682
3877
 
3683
3878
                /* disable notifications for this host */
3684
 
                if(affect_hosts==TRUE)
 
3879
                if(affect_hosts == TRUE)
3685
3880
                        disable_host_notifications(child_host);
3686
3881
 
3687
3882
                /* disable notifications for all services on this host... */
3688
 
                if(affect_services==TRUE){
3689
 
                        for(temp_servicesmember=child_host->services;temp_servicesmember!=NULL;temp_servicesmember=temp_servicesmember->next){
3690
 
                                if((temp_service=temp_servicesmember->service_ptr)==NULL)
 
3883
                if(affect_services == TRUE) {
 
3884
                        for(temp_servicesmember = child_host->services; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {
 
3885
                                if((temp_service = temp_servicesmember->service_ptr) == NULL)
3691
3886
                                        continue;
3692
3887
                                disable_service_notifications(temp_service);
3693
 
                                }
3694
 
                        }
3695
 
                }
 
3888
                                }
 
3889
                        }
 
3890
                }
3696
3891
 
3697
3892
        return;
3698
 
        }
 
3893
        }
3699
3894
 
3700
3895
 
3701
3896
 
3702
3897
/* enables host notifications for a contact */
3703
 
void enable_contact_host_notifications(contact *cntct){
3704
 
        unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
 
3898
void enable_contact_host_notifications(contact *cntct) {
 
3899
        unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3705
3900
 
3706
3901
        /* no change */
3707
 
        if(cntct->host_notifications_enabled==TRUE)
 
3902
        if(cntct->host_notifications_enabled == TRUE)
3708
3903
                return;
3709
3904
 
3710
3905
        /* set the attribute modified flag */
3711
 
        cntct->modified_host_attributes|=attr;
 
3906
        cntct->modified_host_attributes |= attr;
3712
3907
 
3713
3908
        /* enable the host notifications... */
3714
 
        cntct->host_notifications_enabled=TRUE;
 
3909
        cntct->host_notifications_enabled = TRUE;
3715
3910
 
3716
3911
#ifdef USE_EVENT_BROKER
3717
3912
        /* send data to event broker */
3718
 
        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);
 
3913
        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);
3719
3914
#endif
3720
3915
 
3721
3916
        /* update the status log to reflect the new contact state */
3722
 
        update_contact_status(cntct,FALSE);
 
3917
        update_contact_status(cntct, FALSE);
3723
3918
 
3724
3919
        return;
3725
 
        }
 
3920
        }
3726
3921
 
3727
3922
 
3728
3923
 
3729
3924
/* disables host notifications for a contact */
3730
 
void disable_contact_host_notifications(contact *cntct){
3731
 
        unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
 
3925
void disable_contact_host_notifications(contact *cntct) {
 
3926
        unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3732
3927
 
3733
3928
        /* no change */
3734
 
        if(cntct->host_notifications_enabled==FALSE)
 
3929
        if(cntct->host_notifications_enabled == FALSE)
3735
3930
                return;
3736
3931
 
3737
3932
        /* set the attribute modified flag */
3738
 
        cntct->modified_host_attributes|=attr;
 
3933
        cntct->modified_host_attributes |= attr;
3739
3934
 
3740
3935
        /* enable the host notifications... */
3741
 
        cntct->host_notifications_enabled=FALSE;
 
3936
        cntct->host_notifications_enabled = FALSE;
3742
3937
 
3743
3938
#ifdef USE_EVENT_BROKER
3744
3939
        /* send data to event broker */
3745
 
        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);
 
3940
        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);
3746
3941
#endif
3747
3942
 
3748
3943
        /* update the status log to reflect the new contact state */
3749
 
        update_contact_status(cntct,FALSE);
 
3944
        update_contact_status(cntct, FALSE);
3750
3945
 
3751
3946
        return;
3752
 
        }
 
3947
        }
3753
3948
 
3754
3949
 
3755
3950
 
3756
3951
/* enables service notifications for a contact */
3757
 
void enable_contact_service_notifications(contact *cntct){
3758
 
        unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
 
3952
void enable_contact_service_notifications(contact *cntct) {
 
3953
        unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3759
3954
 
3760
3955
        /* no change */
3761
 
        if(cntct->service_notifications_enabled==TRUE)
 
3956
        if(cntct->service_notifications_enabled == TRUE)
3762
3957
                return;
3763
3958
 
3764
3959
        /* set the attribute modified flag */
3765
 
        cntct->modified_service_attributes|=attr;
 
3960
        cntct->modified_service_attributes |= attr;
3766
3961
 
3767
3962
        /* enable the host notifications... */
3768
 
        cntct->service_notifications_enabled=TRUE;
 
3963
        cntct->service_notifications_enabled = TRUE;
3769
3964
 
3770
3965
#ifdef USE_EVENT_BROKER
3771
3966
        /* send data to event broker */
3772
 
        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);
 
3967
        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);
3773
3968
#endif
3774
3969
 
3775
3970
        /* update the status log to reflect the new contact state */
3776
 
        update_contact_status(cntct,FALSE);
 
3971
        update_contact_status(cntct, FALSE);
3777
3972
 
3778
3973
        return;
3779
 
        }
 
3974
        }
3780
3975
 
3781
3976
 
3782
3977
 
3783
3978
/* disables service notifications for a contact */
3784
 
void disable_contact_service_notifications(contact *cntct){
3785
 
        unsigned long attr=MODATTR_NOTIFICATIONS_ENABLED;
 
3979
void disable_contact_service_notifications(contact *cntct) {
 
3980
        unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3786
3981
 
3787
3982
        /* no change */
3788
 
        if(cntct->service_notifications_enabled==FALSE)
 
3983
        if(cntct->service_notifications_enabled == FALSE)
3789
3984
                return;
3790
3985
 
3791
3986
        /* set the attribute modified flag */
3792
 
        cntct->modified_service_attributes|=attr;
 
3987
        cntct->modified_service_attributes |= attr;
3793
3988
 
3794
3989
        /* enable the host notifications... */
3795
 
        cntct->service_notifications_enabled=FALSE;
 
3990
        cntct->service_notifications_enabled = FALSE;
3796
3991
 
3797
3992
#ifdef USE_EVENT_BROKER
3798
3993
        /* send data to event broker */
3799
 
        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);
 
3994
        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);
3800
3995
#endif
3801
3996
 
3802
3997
        /* update the status log to reflect the new contact state */
3803
 
        update_contact_status(cntct,FALSE);
 
3998
        update_contact_status(cntct, FALSE);
3804
3999
 
3805
4000
        return;
3806
 
        }
 
4001
        }
3807
4002
 
3808
4003
 
3809
4004
 
3810
4005
/* schedules downtime for all hosts "beyond" a given host */
3811
 
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){
3812
 
        host *child_host=NULL;
3813
 
        hostsmember *temp_hostsmember=NULL;
 
4006
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) {
 
4007
        host *child_host = NULL;
 
4008
        hostsmember *temp_hostsmember = NULL;
3814
4009
 
3815
4010
        /* check all child hosts... */
3816
 
        for(temp_hostsmember=temp_host->child_hosts;temp_hostsmember!=NULL;temp_hostsmember=temp_hostsmember->next){
 
4011
        for(temp_hostsmember = temp_host->child_hosts; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
3817
4012
 
3818
 
                if((child_host=temp_hostsmember->host_ptr)==NULL)
 
4013
                if((child_host = temp_hostsmember->host_ptr) == NULL)
3819
4014
                        continue;
3820
4015
 
3821
4016
                /* recurse... */
3822
 
                schedule_and_propagate_downtime(child_host,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration);
 
4017
                schedule_and_propagate_downtime(child_host, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration);
3823
4018
 
3824
4019
                /* schedule downtime for this host */
3825
 
                schedule_downtime(HOST_DOWNTIME,child_host->name,NULL,entry_time,author,comment_data,start_time,end_time,fixed,triggered_by,duration,NULL);
3826
 
                }
 
4020
                schedule_downtime(HOST_DOWNTIME, child_host->name, NULL, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, NULL);
 
4021
                }
3827
4022
 
3828
4023
        return;
3829
 
        }
 
4024
        }
3830
4025
 
3831
4026
 
3832
4027
/* acknowledges a host problem */
3833
 
void acknowledge_host_problem(host *hst, char *ack_author, char *ack_data, int type, int notify, int persistent){
3834
 
        time_t current_time=0L;
 
4028
void acknowledge_host_problem(host *hst, char *ack_author, char *ack_data, int type, int notify, int persistent) {
 
4029
        time_t current_time = 0L;
3835
4030
 
3836
4031
        /* cannot acknowledge a non-existent problem */
3837
 
        if(hst->current_state==HOST_UP)
 
4032
        if(hst->current_state == HOST_UP)
3838
4033
                return;
3839
4034
 
3840
4035
#ifdef USE_EVENT_BROKER
3841
4036
        /* send data to event broker */
3842
 
        broker_acknowledgement_data(NEBTYPE_ACKNOWLEDGEMENT_ADD,NEBFLAG_NONE,NEBATTR_NONE,HOST_ACKNOWLEDGEMENT,(void *)hst,ack_author,ack_data,type,notify,persistent,NULL);
 
4037
        broker_acknowledgement_data(NEBTYPE_ACKNOWLEDGEMENT_ADD, NEBFLAG_NONE, NEBATTR_NONE, HOST_ACKNOWLEDGEMENT, (void *)hst, ack_author, ack_data, type, notify, persistent, NULL);
3843
4038
#endif
3844
4039
 
3845
4040
        /* send out an acknowledgement notification */
3846
 
        if(notify==TRUE)
3847
 
                host_notification(hst,NOTIFICATION_ACKNOWLEDGEMENT,ack_author,ack_data,NOTIFICATION_OPTION_NONE);
 
4041
        if(notify == TRUE)
 
4042
                host_notification(hst, NOTIFICATION_ACKNOWLEDGEMENT, ack_author, ack_data, NOTIFICATION_OPTION_NONE);
3848
4043
 
3849
4044
        /* set the acknowledgement flag */
3850
 
        hst->problem_has_been_acknowledged=TRUE;
 
4045
        hst->problem_has_been_acknowledged = TRUE;
3851
4046
 
3852
4047
        /* set the acknowledgement type */
3853
 
        hst->acknowledgement_type=(type==ACKNOWLEDGEMENT_STICKY)?ACKNOWLEDGEMENT_STICKY:ACKNOWLEDGEMENT_NORMAL;
 
4048
        hst->acknowledgement_type = (type == ACKNOWLEDGEMENT_STICKY) ? ACKNOWLEDGEMENT_STICKY : ACKNOWLEDGEMENT_NORMAL;
3854
4049
 
3855
4050
        /* update the status log with the host info */
3856
 
        update_host_status(hst,FALSE);
 
4051
        update_host_status(hst, FALSE);
3857
4052
 
3858
4053
        /* add a comment for the acknowledgement */
3859
4054
        time(&current_time);
3860
 
        add_new_host_comment(ACKNOWLEDGEMENT_COMMENT,hst->name,current_time,ack_author,ack_data,persistent,COMMENTSOURCE_INTERNAL,FALSE,(time_t)0,NULL);
 
4055
        add_new_host_comment(ACKNOWLEDGEMENT_COMMENT, hst->name, current_time, ack_author, ack_data, persistent, COMMENTSOURCE_INTERNAL, FALSE, (time_t)0, NULL);
3861
4056
 
3862
4057
        return;
3863
 
        }
 
4058
        }
3864
4059
 
3865
4060
 
3866
4061
/* acknowledges a service problem */
3867
 
void acknowledge_service_problem(service *svc, char *ack_author, char *ack_data, int type, int notify, int persistent){
3868
 
        time_t current_time=0L;
 
4062
void acknowledge_service_problem(service *svc, char *ack_author, char *ack_data, int type, int notify, int persistent) {
 
4063
        time_t current_time = 0L;
3869
4064
 
3870
4065
        /* cannot acknowledge a non-existent problem */
3871
 
        if(svc->current_state==STATE_OK)
 
4066
        if(svc->current_state == STATE_OK)
3872
4067
                return;
3873
4068
 
3874
4069
#ifdef USE_EVENT_BROKER
3875
4070
        /* send data to event broker */
3876
 
        broker_acknowledgement_data(NEBTYPE_ACKNOWLEDGEMENT_ADD,NEBFLAG_NONE,NEBATTR_NONE,SERVICE_ACKNOWLEDGEMENT,(void *)svc,ack_author,ack_data,type,notify,persistent,NULL);
 
4071
        broker_acknowledgement_data(NEBTYPE_ACKNOWLEDGEMENT_ADD, NEBFLAG_NONE, NEBATTR_NONE, SERVICE_ACKNOWLEDGEMENT, (void *)svc, ack_author, ack_data, type, notify, persistent, NULL);
3877
4072
#endif
3878
4073
 
3879
4074
        /* send out an acknowledgement notification */
3880
 
        if(notify==TRUE)
3881
 
                service_notification(svc,NOTIFICATION_ACKNOWLEDGEMENT,ack_author,ack_data,NOTIFICATION_OPTION_NONE);
 
4075
        if(notify == TRUE)
 
4076
                service_notification(svc, NOTIFICATION_ACKNOWLEDGEMENT, ack_author, ack_data, NOTIFICATION_OPTION_NONE);
3882
4077
 
3883
4078
        /* set the acknowledgement flag */
3884
 
        svc->problem_has_been_acknowledged=TRUE;
 
4079
        svc->problem_has_been_acknowledged = TRUE;
3885
4080
 
3886
4081
        /* set the acknowledgement type */
3887
 
        svc->acknowledgement_type=(type==ACKNOWLEDGEMENT_STICKY)?ACKNOWLEDGEMENT_STICKY:ACKNOWLEDGEMENT_NORMAL;
 
4082
        svc->acknowledgement_type = (type == ACKNOWLEDGEMENT_STICKY) ? ACKNOWLEDGEMENT_STICKY : ACKNOWLEDGEMENT_NORMAL;
3888
4083
 
3889
4084
        /* update the status log with the service info */
3890
 
        update_service_status(svc,FALSE);
 
4085
        update_service_status(svc, FALSE);
3891
4086
 
3892
4087
        /* add a comment for the acknowledgement */
3893
4088
        time(&current_time);
3894
 
        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);
 
4089
        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);
3895
4090
 
3896
4091
        return;
3897
 
        }
 
4092
        }
3898
4093
 
3899
4094
 
3900
4095
/* removes a host acknowledgement */
3901
 
void remove_host_acknowledgement(host *hst){
 
4096
void remove_host_acknowledgement(host *hst) {
3902
4097
 
3903
4098
        /* set the acknowledgement flag */
3904
 
        hst->problem_has_been_acknowledged=FALSE;
 
4099
        hst->problem_has_been_acknowledged = FALSE;
3905
4100
 
3906
4101
        /* update the status log with the host info */
3907
 
        update_host_status(hst,FALSE);
 
4102
        update_host_status(hst, FALSE);
3908
4103
 
3909
4104
        /* remove any non-persistant comments associated with the ack */
3910
4105
        delete_host_acknowledgement_comments(hst);
3911
4106
 
3912
4107
        return;
3913
 
        }
 
4108
        }
3914
4109
 
3915
4110
 
3916
4111
/* removes a service acknowledgement */
3917
 
void remove_service_acknowledgement(service *svc){
 
4112
void remove_service_acknowledgement(service *svc) {
3918
4113
 
3919
4114
        /* set the acknowledgement flag */
3920
 
        svc->problem_has_been_acknowledged=FALSE;
 
4115
        svc->problem_has_been_acknowledged = FALSE;
3921
4116
 
3922
4117
        /* update the status log with the service info */
3923
 
        update_service_status(svc,FALSE);
 
4118
        update_service_status(svc, FALSE);
3924
4119
 
3925
4120
        /* remove any non-persistant comments associated with the ack */
3926
4121
        delete_service_acknowledgement_comments(svc);
3927
4122
 
3928
4123
        return;
3929
 
        }
 
4124
        }
3930
4125
 
3931
4126
 
3932
4127
/* starts executing service checks */
3933
 
void start_executing_service_checks(void){
3934
 
        unsigned long attr=MODATTR_ACTIVE_CHECKS_ENABLED;
 
4128
void start_executing_service_checks(void) {
 
4129
        unsigned long attr = MODATTR_ACTIVE_CHECKS_ENABLED;
3935
4130
 
3936
4131
        /* bail out if we're already executing services */
3937
 
        if(execute_service_checks==TRUE)
 
4132
        if(execute_service_checks == TRUE)
3938
4133
                return;
3939
4134
 
3940
4135
        /* set the attribute modified flag */
3941
 
        modified_service_process_attributes|=attr;
 
4136
        modified_service_process_attributes |= attr;
3942
4137
 
3943
4138
        /* set the service check execution flag */
3944
 
        execute_service_checks=TRUE;
 
4139
        execute_service_checks = TRUE;
3945
4140
 
3946
4141
#ifdef USE_EVENT_BROKER
3947
4142
        /* send data to event broker */
3948
 
        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);
 
4143
        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);
3949
4144
#endif
3950
4145
 
3951
4146
        /* update the status log with the program info */
3952
4147
        update_program_status(FALSE);
3953
4148
 
3954
4149
        return;
3955
 
        }
 
4150
        }
3956
4151
 
3957
4152
 
3958
4153
 
3959
4154
 
3960
4155
/* stops executing service checks */
3961
 
void stop_executing_service_checks(void){
3962
 
        unsigned long attr=MODATTR_ACTIVE_CHECKS_ENABLED;
 
4156
void stop_executing_service_checks(void) {
 
4157
        unsigned long attr = MODATTR_ACTIVE_CHECKS_ENABLED;
3963
4158
 
3964
4159
        /* bail out if we're already not executing services */
3965
 
        if(execute_service_checks==FALSE)
 
4160
        if(execute_service_checks == FALSE)
3966
4161
                return;
3967
4162
 
3968
4163
        /* set the attribute modified flag */
3969
 
        modified_service_process_attributes|=attr;
 
4164
        modified_service_process_attributes |= attr;
3970
4165
 
3971
4166
        /* set the service check execution flag */
3972
 
        execute_service_checks=FALSE;
 
4167
        execute_service_checks = FALSE;
3973
4168
 
3974
4169
#ifdef USE_EVENT_BROKER
3975
4170
        /* send data to event broker */
3976
 
        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);
 
4171
        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);
3977
4172
#endif
3978
4173
 
3979
4174
        /* update the status log with the program info */
3980
4175
        update_program_status(FALSE);
3981
4176
 
3982
4177
        return;
3983
 
        }
 
4178
        }
3984
4179
 
3985
4180
 
3986
4181
 
3987
4182
/* starts accepting passive service checks */
3988
 
void start_accepting_passive_service_checks(void){
3989
 
        unsigned long attr=MODATTR_PASSIVE_CHECKS_ENABLED;
 
4183
void start_accepting_passive_service_checks(void) {
 
4184
        unsigned long attr = MODATTR_PASSIVE_CHECKS_ENABLED;
3990
4185
 
3991
4186
        /* bail out if we're already accepting passive services */
3992
 
        if(accept_passive_service_checks==TRUE)
 
4187
        if(accept_passive_service_checks == TRUE)
3993
4188
                return;
3994
4189
 
3995
4190
        /* set the attribute modified flag */
3996
 
        modified_service_process_attributes|=attr;
 
4191
        modified_service_process_attributes |= attr;
3997
4192
 
3998
4193
        /* set the service check flag */
3999
 
        accept_passive_service_checks=TRUE;
 
4194
        accept_passive_service_checks = TRUE;
4000
4195
 
4001
4196
#ifdef USE_EVENT_BROKER
4002
4197
        /* send data to event broker */
4003
 
        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);
 
4198
        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);
4004
4199
#endif
4005
4200
 
4006
4201
        /* update the status log with the program info */
4007
4202
        update_program_status(FALSE);
4008
4203
 
4009
4204
        return;
4010
 
        }
 
4205
        }
4011
4206
 
4012
4207
 
4013
4208
 
4014
4209
/* stops accepting passive service checks */
4015
 
void stop_accepting_passive_service_checks(void){
4016
 
        unsigned long attr=MODATTR_PASSIVE_CHECKS_ENABLED;
 
4210
void stop_accepting_passive_service_checks(void) {
 
4211
        unsigned long attr = MODATTR_PASSIVE_CHECKS_ENABLED;
4017
4212
 
4018
4213
        /* bail out if we're already not accepting passive services */
4019
 
        if(accept_passive_service_checks==FALSE)
 
4214
        if(accept_passive_service_checks == FALSE)
4020
4215
                return;
4021
4216
 
4022
4217
        /* set the attribute modified flag */
4023
 
        modified_service_process_attributes|=attr;
 
4218
        modified_service_process_attributes |= attr;
4024
4219
 
4025
4220
        /* set the service check flag */
4026
 
        accept_passive_service_checks=FALSE;
 
4221
        accept_passive_service_checks = FALSE;
4027
4222
 
4028
4223
#ifdef USE_EVENT_BROKER
4029
4224
        /* send data to event broker */
4030
 
        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);
 
4225
        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);
4031
4226
#endif
4032
4227
 
4033
4228
        /* update the status log with the program info */
4034
4229
        update_program_status(FALSE);
4035
4230
 
4036
4231
        return;
4037
 
        }
 
4232
        }
4038
4233
 
4039
4234
 
4040
4235
 
4041
4236
/* enables passive service checks for a particular service */
4042
 
void enable_passive_service_checks(service *svc){
4043
 
        unsigned long attr=MODATTR_PASSIVE_CHECKS_ENABLED;
 
4237
void enable_passive_service_checks(service *svc) {
 
4238
        unsigned long attr = MODATTR_PASSIVE_CHECKS_ENABLED;
4044
4239
 
4045
4240
        /* no change */
4046
 
        if(svc->accept_passive_service_checks==TRUE)
 
4241
        if(svc->accept_passive_service_checks == TRUE)
4047
4242
                return;
4048
4243
 
4049
4244
        /* set the attribute modified flag */
4050
 
        svc->modified_attributes|=attr;
 
4245
        svc->modified_attributes |= attr;
4051
4246
 
4052
4247
        /* set the passive check flag */
4053
 
        svc->accept_passive_service_checks=TRUE;
 
4248
        svc->accept_passive_service_checks = TRUE;
4054
4249
 
4055
4250
#ifdef USE_EVENT_BROKER
4056
4251
        /* send data to event broker */
4057
 
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
 
4252
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
4058
4253
#endif
4059
4254
 
4060
4255
        /* update the status log with the service info */
4061
 
        update_service_status(svc,FALSE);
 
4256
        update_service_status(svc, FALSE);
4062
4257
 
4063
4258
        return;
4064
 
        }
 
4259
        }
4065
4260
 
4066
4261
 
4067
4262
 
4068
4263
/* disables passive service checks for a particular service */
4069
 
void disable_passive_service_checks(service *svc){
4070
 
        unsigned long attr=MODATTR_PASSIVE_CHECKS_ENABLED;
 
4264
void disable_passive_service_checks(service *svc) {
 
4265
        unsigned long attr = MODATTR_PASSIVE_CHECKS_ENABLED;
4071
4266
 
4072
4267
        /* no change */
4073
 
        if(svc->accept_passive_service_checks==FALSE)
 
4268
        if(svc->accept_passive_service_checks == FALSE)
4074
4269
                return;
4075
4270
 
4076
4271
        /* set the attribute modified flag */
4077
 
        svc->modified_attributes|=attr;
 
4272
        svc->modified_attributes |= attr;
4078
4273
 
4079
4274
        /* set the passive check flag */
4080
 
        svc->accept_passive_service_checks=FALSE;
 
4275
        svc->accept_passive_service_checks = FALSE;
4081
4276
 
4082
4277
#ifdef USE_EVENT_BROKER
4083
4278
        /* send data to event broker */
4084
 
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
 
4279
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
4085
4280
#endif
4086
4281
 
4087
4282
        /* update the status log with the service info */
4088
 
        update_service_status(svc,FALSE);
 
4283
        update_service_status(svc, FALSE);
4089
4284
 
4090
4285
        return;
4091
 
        }
 
4286
        }
4092
4287
 
4093
4288
 
4094
4289
 
4095
4290
/* starts executing host checks */
4096
 
void start_executing_host_checks(void){
4097
 
        unsigned long attr=MODATTR_ACTIVE_CHECKS_ENABLED;
 
4291
void start_executing_host_checks(void) {
 
4292
        unsigned long attr = MODATTR_ACTIVE_CHECKS_ENABLED;
4098
4293
 
4099
4294
        /* bail out if we're already executing hosts */
4100
 
        if(execute_host_checks==TRUE)
 
4295
        if(execute_host_checks == TRUE)
4101
4296
                return;
4102
4297
 
4103
4298
        /* set the attribute modified flag */
4104
 
        modified_host_process_attributes|=attr;
 
4299
        modified_host_process_attributes |= attr;
4105
4300
 
4106
4301
        /* set the host check execution flag */
4107
 
        execute_host_checks=TRUE;
 
4302
        execute_host_checks = TRUE;
4108
4303
 
4109
4304
#ifdef USE_EVENT_BROKER
4110
4305
        /* send data to event broker */
4111
 
        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);
 
4306
        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);
4112
4307
#endif
4113
4308
 
4114
4309
        /* update the status log with the program info */
4115
4310
        update_program_status(FALSE);
4116
4311
 
4117
4312
        return;
4118
 
        }
 
4313
        }
4119
4314
 
4120
4315
 
4121
4316
 
4122
4317
 
4123
4318
/* stops executing host checks */
4124
 
void stop_executing_host_checks(void){
4125
 
        unsigned long attr=MODATTR_ACTIVE_CHECKS_ENABLED;
 
4319
void stop_executing_host_checks(void) {
 
4320
        unsigned long attr = MODATTR_ACTIVE_CHECKS_ENABLED;
4126
4321
 
4127
4322
        /* bail out if we're already not executing hosts */
4128
 
        if(execute_host_checks==FALSE)
 
4323
        if(execute_host_checks == FALSE)
4129
4324
                return;
4130
4325
 
4131
4326
        /* set the attribute modified flag */
4132
 
        modified_host_process_attributes|=attr;
 
4327
        modified_host_process_attributes |= attr;
4133
4328
 
4134
4329
        /* set the host check execution flag */
4135
 
        execute_host_checks=FALSE;
 
4330
        execute_host_checks = FALSE;
4136
4331
 
4137
4332
#ifdef USE_EVENT_BROKER
4138
4333
        /* send data to event broker */
4139
 
        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);
 
4334
        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);
4140
4335
#endif
4141
4336
 
4142
4337
        /* update the status log with the program info */
4143
4338
        update_program_status(FALSE);
4144
4339
 
4145
4340
        return;
4146
 
        }
 
4341
        }
4147
4342
 
4148
4343
 
4149
4344
 
4150
4345
/* starts accepting passive host checks */
4151
 
void start_accepting_passive_host_checks(void){
4152
 
        unsigned long attr=MODATTR_PASSIVE_CHECKS_ENABLED;
 
4346
void start_accepting_passive_host_checks(void) {
 
4347
        unsigned long attr = MODATTR_PASSIVE_CHECKS_ENABLED;
4153
4348
 
4154
4349
        /* bail out if we're already accepting passive hosts */
4155
 
        if(accept_passive_host_checks==TRUE)
 
4350
        if(accept_passive_host_checks == TRUE)
4156
4351
                return;
4157
4352
 
4158
4353
        /* set the attribute modified flag */
4159
 
        modified_host_process_attributes|=attr;
 
4354
        modified_host_process_attributes |= attr;
4160
4355
 
4161
4356
        /* set the host check flag */
4162
 
        accept_passive_host_checks=TRUE;
 
4357
        accept_passive_host_checks = TRUE;
4163
4358
 
4164
4359
#ifdef USE_EVENT_BROKER
4165
4360
        /* send data to event broker */
4166
 
        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);
 
4361
        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);
4167
4362
#endif
4168
4363
 
4169
4364
        /* update the status log with the program info */
4170
4365
        update_program_status(FALSE);
4171
4366
 
4172
4367
        return;
4173
 
        }
 
4368
        }
4174
4369
 
4175
4370
 
4176
4371
 
4177
4372
/* stops accepting passive host checks */
4178
 
void stop_accepting_passive_host_checks(void){
4179
 
        unsigned long attr=MODATTR_PASSIVE_CHECKS_ENABLED;
 
4373
void stop_accepting_passive_host_checks(void) {
 
4374
        unsigned long attr = MODATTR_PASSIVE_CHECKS_ENABLED;
4180
4375
 
4181
4376
        /* bail out if we're already not accepting passive hosts */
4182
 
        if(accept_passive_host_checks==FALSE)
 
4377
        if(accept_passive_host_checks == FALSE)
4183
4378
                return;
4184
4379
 
4185
4380
        /* set the attribute modified flag */
4186
 
        modified_host_process_attributes|=attr;
 
4381
        modified_host_process_attributes |= attr;
4187
4382
 
4188
4383
        /* set the host check flag */
4189
 
        accept_passive_host_checks=FALSE;
 
4384
        accept_passive_host_checks = FALSE;
4190
4385
 
4191
4386
#ifdef USE_EVENT_BROKER
4192
4387
        /* send data to event broker */
4193
 
        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);
 
4388
        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);
4194
4389
#endif
4195
4390
 
4196
4391
        /* update the status log with the program info */
4197
4392
        update_program_status(FALSE);
4198
4393
 
4199
4394
        return;
4200
 
        }
 
4395
        }
4201
4396
 
4202
4397
 
4203
4398
 
4204
4399
/* enables passive host checks for a particular host */
4205
 
void enable_passive_host_checks(host *hst){
4206
 
        unsigned long attr=MODATTR_PASSIVE_CHECKS_ENABLED;
 
4400
void enable_passive_host_checks(host *hst) {
 
4401
        unsigned long attr = MODATTR_PASSIVE_CHECKS_ENABLED;
4207
4402
 
4208
4403
        /* no change */
4209
 
        if(hst->accept_passive_host_checks==TRUE)
 
4404
        if(hst->accept_passive_host_checks == TRUE)
4210
4405
                return;
4211
4406
 
4212
4407
        /* set the attribute modified flag */
4213
 
        hst->modified_attributes|=attr;
 
4408
        hst->modified_attributes |= attr;
4214
4409
 
4215
4410
        /* set the passive check flag */
4216
 
        hst->accept_passive_host_checks=TRUE;
 
4411
        hst->accept_passive_host_checks = TRUE;
4217
4412
 
4218
4413
#ifdef USE_EVENT_BROKER
4219
4414
        /* send data to event broker */
4220
 
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
 
4415
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
4221
4416
#endif
4222
4417
 
4223
4418
        /* update the status log with the host info */
4224
 
        update_host_status(hst,FALSE);
 
4419
        update_host_status(hst, FALSE);
4225
4420
 
4226
4421
        return;
4227
 
        }
 
4422
        }
4228
4423
 
4229
4424
 
4230
4425
 
4231
4426
/* disables passive host checks for a particular host */
4232
 
void disable_passive_host_checks(host *hst){
4233
 
        unsigned long attr=MODATTR_PASSIVE_CHECKS_ENABLED;
 
4427
void disable_passive_host_checks(host *hst) {
 
4428
        unsigned long attr = MODATTR_PASSIVE_CHECKS_ENABLED;
4234
4429
 
4235
4430
        /* no change */
4236
 
        if(hst->accept_passive_host_checks==FALSE)
 
4431
        if(hst->accept_passive_host_checks == FALSE)
4237
4432
                return;
4238
4433
 
4239
4434
        /* set the attribute modified flag */
4240
 
        hst->modified_attributes|=attr;
 
4435
        hst->modified_attributes |= attr;
4241
4436
 
4242
4437
        /* set the passive check flag */
4243
 
        hst->accept_passive_host_checks=FALSE;
 
4438
        hst->accept_passive_host_checks = FALSE;
4244
4439
 
4245
4440
#ifdef USE_EVENT_BROKER
4246
4441
        /* send data to event broker */
4247
 
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
 
4442
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
4248
4443
#endif
4249
4444
 
4250
4445
        /* update the status log with the host info */
4251
 
        update_host_status(hst,FALSE);
 
4446
        update_host_status(hst, FALSE);
4252
4447
 
4253
4448
        return;
4254
 
        }
 
4449
        }
4255
4450
 
4256
4451
 
4257
4452
/* enables event handlers on a program-wide basis */
4258
 
void start_using_event_handlers(void){
4259
 
        unsigned long attr=MODATTR_EVENT_HANDLER_ENABLED;
 
4453
void start_using_event_handlers(void) {
 
4454
        unsigned long attr = MODATTR_EVENT_HANDLER_ENABLED;
4260
4455
 
4261
4456
        /* no change */
4262
 
        if(enable_event_handlers==TRUE)
 
4457
        if(enable_event_handlers == TRUE)
4263
4458
                return;
4264
4459
 
4265
4460
        /* set the attribute modified flag */
4266
 
        modified_host_process_attributes|=attr;
4267
 
        modified_service_process_attributes|=attr;
 
4461
        modified_host_process_attributes |= attr;
 
4462
        modified_service_process_attributes |= attr;
4268
4463
 
4269
4464
        /* set the event handler flag */
4270
 
        enable_event_handlers=TRUE;
 
4465
        enable_event_handlers = TRUE;
4271
4466
 
4272
4467
#ifdef USE_EVENT_BROKER
4273
4468
        /* send data to event broker */
4274
 
        broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
 
4469
        broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, CMD_NONE, attr, modified_host_process_attributes, attr, modified_service_process_attributes, NULL);
4275
4470
#endif
4276
4471
 
4277
4472
        /* update the status log with the program info */
4278
4473
        update_program_status(FALSE);
4279
4474
 
4280
4475
        return;
4281
 
        }
 
4476
        }
4282
4477
 
4283
4478
 
4284
4479
/* disables event handlers on a program-wide basis */
4285
 
void stop_using_event_handlers(void){
4286
 
        unsigned long attr=MODATTR_EVENT_HANDLER_ENABLED;
 
4480
void stop_using_event_handlers(void) {
 
4481
        unsigned long attr = MODATTR_EVENT_HANDLER_ENABLED;
4287
4482
 
4288
4483
        /* no change */
4289
 
        if(enable_event_handlers==FALSE)
 
4484
        if(enable_event_handlers == FALSE)
4290
4485
                return;
4291
4486
 
4292
4487
        /* set the attribute modified flag */
4293
 
        modified_host_process_attributes|=attr;
4294
 
        modified_service_process_attributes|=attr;
 
4488
        modified_host_process_attributes |= attr;
 
4489
        modified_service_process_attributes |= attr;
4295
4490
 
4296
4491
        /* set the event handler flag */
4297
 
        enable_event_handlers=FALSE;
 
4492
        enable_event_handlers = FALSE;
4298
4493
 
4299
4494
#ifdef USE_EVENT_BROKER
4300
4495
        /* send data to event broker */
4301
 
        broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
 
4496
        broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, CMD_NONE, attr, modified_host_process_attributes, attr, modified_service_process_attributes, NULL);
4302
4497
#endif
4303
4498
 
4304
4499
        /* update the status log with the program info */
4305
4500
        update_program_status(FALSE);
4306
4501
 
4307
4502
        return;
4308
 
        }
 
4503
        }
4309
4504
 
4310
4505
 
4311
4506
/* enables the event handler for a particular service */
4312
 
void enable_service_event_handler(service *svc){
4313
 
        unsigned long attr=MODATTR_EVENT_HANDLER_ENABLED;
 
4507
void enable_service_event_handler(service *svc) {
 
4508
        unsigned long attr = MODATTR_EVENT_HANDLER_ENABLED;
4314
4509
 
4315
4510
        /* no change */
4316
 
        if(svc->event_handler_enabled==TRUE)
 
4511
        if(svc->event_handler_enabled == TRUE)
4317
4512
                return;
4318
4513
 
4319
4514
        /* set the attribute modified flag */
4320
 
        svc->modified_attributes|=attr;
 
4515
        svc->modified_attributes |= attr;
4321
4516
 
4322
4517
        /* set the event handler flag */
4323
 
        svc->event_handler_enabled=TRUE;
 
4518
        svc->event_handler_enabled = TRUE;
4324
4519
 
4325
4520
#ifdef USE_EVENT_BROKER
4326
4521
        /* send data to event broker */
4327
 
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
 
4522
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
4328
4523
#endif
4329
4524
 
4330
4525
        /* update the status log with the service info */
4331
 
        update_service_status(svc,FALSE);
 
4526
        update_service_status(svc, FALSE);
4332
4527
 
4333
4528
        return;
4334
 
        }
 
4529
        }
4335
4530
 
4336
4531
 
4337
4532
 
4338
4533
/* disables the event handler for a particular service */
4339
 
void disable_service_event_handler(service *svc){
4340
 
        unsigned long attr=MODATTR_EVENT_HANDLER_ENABLED;
 
4534
void disable_service_event_handler(service *svc) {
 
4535
        unsigned long attr = MODATTR_EVENT_HANDLER_ENABLED;
4341
4536
 
4342
4537
        /* no change */
4343
 
        if(svc->event_handler_enabled==FALSE)
 
4538
        if(svc->event_handler_enabled == FALSE)
4344
4539
                return;
4345
4540
 
4346
4541
        /* set the attribute modified flag */
4347
 
        svc->modified_attributes|=attr;
 
4542
        svc->modified_attributes |= attr;
4348
4543
 
4349
4544
        /* set the event handler flag */
4350
 
        svc->event_handler_enabled=FALSE;
 
4545
        svc->event_handler_enabled = FALSE;
4351
4546
 
4352
4547
#ifdef USE_EVENT_BROKER
4353
4548
        /* send data to event broker */
4354
 
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
 
4549
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
4355
4550
#endif
4356
4551
 
4357
4552
        /* update the status log with the service info */
4358
 
        update_service_status(svc,FALSE);
 
4553
        update_service_status(svc, FALSE);
4359
4554
 
4360
4555
        return;
4361
 
        }
 
4556
        }
4362
4557
 
4363
4558
 
4364
4559
/* enables the event handler for a particular host */
4365
 
void enable_host_event_handler(host *hst){
4366
 
        unsigned long attr=MODATTR_EVENT_HANDLER_ENABLED;
 
4560
void enable_host_event_handler(host *hst) {
 
4561
        unsigned long attr = MODATTR_EVENT_HANDLER_ENABLED;
4367
4562
 
4368
4563
        /* no change */
4369
 
        if(hst->event_handler_enabled==TRUE)
 
4564
        if(hst->event_handler_enabled == TRUE)
4370
4565
                return;
4371
4566
 
4372
4567
        /* set the attribute modified flag */
4373
 
        hst->modified_attributes|=attr;
 
4568
        hst->modified_attributes |= attr;
4374
4569
 
4375
4570
        /* set the event handler flag */
4376
 
        hst->event_handler_enabled=TRUE;
 
4571
        hst->event_handler_enabled = TRUE;
4377
4572
 
4378
4573
#ifdef USE_EVENT_BROKER
4379
4574
        /* send data to event broker */
4380
 
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
 
4575
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
4381
4576
#endif
4382
4577
 
4383
4578
        /* update the status log with the host info */
4384
 
        update_host_status(hst,FALSE);
 
4579
        update_host_status(hst, FALSE);
4385
4580
 
4386
4581
        return;
4387
 
        }
 
4582
        }
4388
4583
 
4389
4584
 
4390
4585
/* disables the event handler for a particular host */
4391
 
void disable_host_event_handler(host *hst){
4392
 
        unsigned long attr=MODATTR_EVENT_HANDLER_ENABLED;
 
4586
void disable_host_event_handler(host *hst) {
 
4587
        unsigned long attr = MODATTR_EVENT_HANDLER_ENABLED;
4393
4588
 
4394
4589
        /* no change */
4395
 
        if(hst->event_handler_enabled==FALSE)
 
4590
        if(hst->event_handler_enabled == FALSE)
4396
4591
                return;
4397
4592
 
4398
4593
        /* set the attribute modified flag */
4399
 
        hst->modified_attributes|=attr;
 
4594
        hst->modified_attributes |= attr;
4400
4595
 
4401
4596
        /* set the event handler flag */
4402
 
        hst->event_handler_enabled=FALSE;
 
4597
        hst->event_handler_enabled = FALSE;
4403
4598
 
4404
4599
#ifdef USE_EVENT_BROKER
4405
4600
        /* send data to event broker */
4406
 
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
 
4601
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
4407
4602
#endif
4408
4603
 
4409
4604
        /* update the status log with the host info */
4410
 
        update_host_status(hst,FALSE);
 
4605
        update_host_status(hst, FALSE);
4411
4606
 
4412
4607
        return;
4413
 
        }
 
4608
        }
4414
4609
 
4415
4610
 
4416
4611
/* disables checks of a particular host */
4417
 
void disable_host_checks(host *hst){
4418
 
        unsigned long attr=MODATTR_ACTIVE_CHECKS_ENABLED;
 
4612
void disable_host_checks(host *hst) {
 
4613
        unsigned long attr = MODATTR_ACTIVE_CHECKS_ENABLED;
4419
4614
 
4420
4615
        /* checks are already disabled */
4421
 
        if(hst->checks_enabled==FALSE)
 
4616
        if(hst->checks_enabled == FALSE)
4422
4617
                return;
4423
4618
 
4424
4619
        /* set the attribute modified flag */
4425
 
        hst->modified_attributes|=attr;
 
4620
        hst->modified_attributes |= attr;
4426
4621
 
4427
4622
        /* set the host check flag */
4428
 
        hst->checks_enabled=FALSE;
4429
 
        hst->should_be_scheduled=FALSE;
 
4623
        hst->checks_enabled = FALSE;
 
4624
        hst->should_be_scheduled = FALSE;
4430
4625
 
4431
4626
#ifdef USE_EVENT_BROKER
4432
4627
        /* send data to event broker */
4433
 
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
 
4628
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
4434
4629
#endif
4435
4630
 
4436
4631
        /* update the status log with the host info */
4437
 
        update_host_status(hst,FALSE);
 
4632
        update_host_status(hst, FALSE);
4438
4633
 
4439
4634
        return;
4440
 
        }
 
4635
        }
4441
4636
 
4442
4637
 
4443
4638
/* enables checks of a particular host */
4444
 
void enable_host_checks(host *hst){
4445
 
        time_t preferred_time=0L;
4446
 
        time_t next_valid_time=0L;
4447
 
        unsigned long attr=MODATTR_ACTIVE_CHECKS_ENABLED;
 
4639
void enable_host_checks(host *hst) {
 
4640
        time_t preferred_time = 0L;
 
4641
        time_t next_valid_time = 0L;
 
4642
        unsigned long attr = MODATTR_ACTIVE_CHECKS_ENABLED;
4448
4643
 
4449
4644
        /* checks are already enabled */
4450
 
        if(hst->checks_enabled==TRUE)
 
4645
        if(hst->checks_enabled == TRUE)
4451
4646
                return;
4452
4647
 
4453
4648
        /* set the attribute modified flag */
4454
 
        hst->modified_attributes|=attr;
 
4649
        hst->modified_attributes |= attr;
4455
4650
 
4456
4651
        /* set the host check flag */
4457
 
        hst->checks_enabled=TRUE;
4458
 
        hst->should_be_scheduled=TRUE;
 
4652
        hst->checks_enabled = TRUE;
 
4653
        hst->should_be_scheduled = TRUE;
4459
4654
 
4460
4655
        /* hosts with no check intervals don't get checked */
4461
 
        if(hst->check_interval==0)
4462
 
                hst->should_be_scheduled=FALSE;
 
4656
        if(hst->check_interval == 0)
 
4657
                hst->should_be_scheduled = FALSE;
4463
4658
 
4464
4659
        /* schedule a check for right now (or as soon as possible) */
4465
4660
        time(&preferred_time);
4466
 
        if(check_time_against_period(preferred_time,hst->check_period_ptr)==ERROR){
4467
 
                get_next_valid_time(preferred_time,&next_valid_time,hst->check_period_ptr);
4468
 
                hst->next_check=next_valid_time;
4469
 
                }
 
4661
        if(check_time_against_period(preferred_time, hst->check_period_ptr) == ERROR) {
 
4662
                get_next_valid_time(preferred_time, &next_valid_time, hst->check_period_ptr);
 
4663
                hst->next_check = next_valid_time;
 
4664
                }
4470
4665
        else
4471
 
                hst->next_check=preferred_time;
 
4666
                hst->next_check = preferred_time;
4472
4667
 
4473
4668
        /* schedule a check if we should */
4474
 
        if(hst->should_be_scheduled==TRUE)
4475
 
                schedule_host_check(hst,hst->next_check,CHECK_OPTION_NONE);
 
4669
        if(hst->should_be_scheduled == TRUE)
 
4670
                schedule_host_check(hst, hst->next_check, CHECK_OPTION_NONE);
4476
4671
 
4477
4672
#ifdef USE_EVENT_BROKER
4478
4673
        /* send data to event broker */
4479
 
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
 
4674
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
4480
4675
#endif
4481
4676
 
4482
4677
        /* update the status log with the host info */
4483
 
        update_host_status(hst,FALSE);
 
4678
        update_host_status(hst, FALSE);
4484
4679
 
4485
4680
        return;
4486
 
        }
 
4681
        }
4487
4682
 
4488
4683
 
4489
4684
 
4490
4685
/* start obsessing over service check results */
4491
 
void start_obsessing_over_service_checks(void){
4492
 
        unsigned long attr=MODATTR_OBSESSIVE_HANDLER_ENABLED;
 
4686
void start_obsessing_over_service_checks(void) {
 
4687
        unsigned long attr = MODATTR_OBSESSIVE_HANDLER_ENABLED;
4493
4688
 
4494
4689
        /* no change */
4495
 
        if(obsess_over_services==TRUE)
 
4690
        if(obsess_over_services == TRUE)
4496
4691
                return;
4497
4692
 
4498
4693
        /* set the attribute modified flag */
4499
 
        modified_service_process_attributes|=attr;
 
4694
        modified_service_process_attributes |= attr;
4500
4695
 
4501
4696
        /* set the service obsession flag */
4502
 
        obsess_over_services=TRUE;
 
4697
        obsess_over_services = TRUE;
4503
4698
 
4504
4699
#ifdef USE_EVENT_BROKER
4505
4700
        /* send data to event broker */
4506
 
        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);
 
4701
        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);
4507
4702
#endif
4508
4703
 
4509
4704
        /* update the status log with the program info */
4510
4705
        update_program_status(FALSE);
4511
4706
 
4512
4707
        return;
4513
 
        }
 
4708
        }
4514
4709
 
4515
4710
 
4516
4711
 
4517
4712
/* stop obsessing over service check results */
4518
 
void stop_obsessing_over_service_checks(void){
4519
 
        unsigned long attr=MODATTR_OBSESSIVE_HANDLER_ENABLED;
 
4713
void stop_obsessing_over_service_checks(void) {
 
4714
        unsigned long attr = MODATTR_OBSESSIVE_HANDLER_ENABLED;
4520
4715
 
4521
4716
        /* no change */
4522
 
        if(obsess_over_services==FALSE)
 
4717
        if(obsess_over_services == FALSE)
4523
4718
                return;
4524
4719
 
4525
4720
        /* set the attribute modified flag */
4526
 
        modified_service_process_attributes|=attr;
 
4721
        modified_service_process_attributes |= attr;
4527
4722
 
4528
4723
        /* set the service obsession flag */
4529
 
        obsess_over_services=FALSE;
 
4724
        obsess_over_services = FALSE;
4530
4725
 
4531
4726
#ifdef USE_EVENT_BROKER
4532
4727
        /* send data to event broker */
4533
 
        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);
 
4728
        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);
4534
4729
#endif
4535
4730
 
4536
4731
        /* update the status log with the program info */
4537
4732
        update_program_status(FALSE);
4538
4733
 
4539
4734
        return;
4540
 
        }
 
4735
        }
4541
4736
 
4542
4737
 
4543
4738
 
4544
4739
/* start obsessing over host check results */
4545
 
void start_obsessing_over_host_checks(void){
4546
 
        unsigned long attr=MODATTR_OBSESSIVE_HANDLER_ENABLED;
 
4740
void start_obsessing_over_host_checks(void) {
 
4741
        unsigned long attr = MODATTR_OBSESSIVE_HANDLER_ENABLED;
4547
4742
 
4548
4743
        /* no change */
4549
 
        if(obsess_over_hosts==TRUE)
 
4744
        if(obsess_over_hosts == TRUE)
4550
4745
                return;
4551
4746
 
4552
4747
        /* set the attribute modified flag */
4553
 
        modified_host_process_attributes|=attr;
 
4748
        modified_host_process_attributes |= attr;
4554
4749
 
4555
4750
        /* set the host obsession flag */
4556
 
        obsess_over_hosts=TRUE;
 
4751
        obsess_over_hosts = TRUE;
4557
4752
 
4558
4753
#ifdef USE_EVENT_BROKER
4559
4754
        /* send data to event broker */
4560
 
        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);
 
4755
        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);
4561
4756
#endif
4562
4757
 
4563
4758
        /* update the status log with the program info */
4564
4759
        update_program_status(FALSE);
4565
4760
 
4566
4761
        return;
4567
 
        }
 
4762
        }
4568
4763
 
4569
4764
 
4570
4765
 
4571
4766
/* stop obsessing over host check results */
4572
 
void stop_obsessing_over_host_checks(void){
4573
 
        unsigned long attr=MODATTR_OBSESSIVE_HANDLER_ENABLED;
 
4767
void stop_obsessing_over_host_checks(void) {
 
4768
        unsigned long attr = MODATTR_OBSESSIVE_HANDLER_ENABLED;
4574
4769
 
4575
4770
        /* no change */
4576
 
        if(obsess_over_hosts==FALSE)
 
4771
        if(obsess_over_hosts == FALSE)
4577
4772
                return;
4578
4773
 
4579
4774
        /* set the attribute modified flag */
4580
 
        modified_host_process_attributes|=attr;
 
4775
        modified_host_process_attributes |= attr;
4581
4776
 
4582
4777
        /* set the host obsession flag */
4583
 
        obsess_over_hosts=FALSE;
 
4778
        obsess_over_hosts = FALSE;
4584
4779
 
4585
4780
#ifdef USE_EVENT_BROKER
4586
4781
        /* send data to event broker */
4587
 
        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);
 
4782
        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);
4588
4783
#endif
4589
4784
 
4590
4785
        /* update the status log with the program info */
4591
4786
        update_program_status(FALSE);
4592
4787
 
4593
4788
        return;
4594
 
        }
 
4789
        }
4595
4790
 
4596
4791
 
4597
4792
 
4598
4793
/* enables service freshness checking */
4599
 
void enable_service_freshness_checks(void){
4600
 
        unsigned long attr=MODATTR_FRESHNESS_CHECKS_ENABLED;
 
4794
void enable_service_freshness_checks(void) {
 
4795
        unsigned long attr = MODATTR_FRESHNESS_CHECKS_ENABLED;
4601
4796
 
4602
4797
        /* no change */
4603
 
        if(check_service_freshness==TRUE)
 
4798
        if(check_service_freshness == TRUE)
4604
4799
                return;
4605
4800
 
4606
4801
        /* set the attribute modified flag */
4607
 
        modified_service_process_attributes|=attr;
 
4802
        modified_service_process_attributes |= attr;
4608
4803
 
4609
4804
        /* set the freshness check flag */
4610
 
        check_service_freshness=TRUE;
 
4805
        check_service_freshness = TRUE;
4611
4806
 
4612
4807
#ifdef USE_EVENT_BROKER
4613
4808
        /* send data to event broker */
4614
 
        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);
 
4809
        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);
4615
4810
#endif
4616
4811
 
4617
4812
        /* update the status log with the program info */
4618
4813
        update_program_status(FALSE);
4619
4814
 
4620
4815
        return;
4621
 
        }
 
4816
        }
4622
4817
 
4623
4818
 
4624
4819
/* disables service freshness checking */
4625
 
void disable_service_freshness_checks(void){
4626
 
        unsigned long attr=MODATTR_FRESHNESS_CHECKS_ENABLED;
 
4820
void disable_service_freshness_checks(void) {
 
4821
        unsigned long attr = MODATTR_FRESHNESS_CHECKS_ENABLED;
4627
4822
 
4628
4823
        /* no change */
4629
 
        if(check_service_freshness==FALSE)
 
4824
        if(check_service_freshness == FALSE)
4630
4825
                return;
4631
4826
 
4632
4827
        /* set the attribute modified flag */
4633
 
        modified_service_process_attributes|=attr;
 
4828
        modified_service_process_attributes |= attr;
4634
4829
 
4635
4830
        /* set the freshness check flag */
4636
 
        check_service_freshness=FALSE;
 
4831
        check_service_freshness = FALSE;
4637
4832
 
4638
4833
#ifdef USE_EVENT_BROKER
4639
4834
        /* send data to event broker */
4640
 
        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);
 
4835
        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);
4641
4836
#endif
4642
4837
 
4643
4838
        /* update the status log with the program info */
4644
4839
        update_program_status(FALSE);
4645
4840
 
4646
4841
        return;
4647
 
        }
 
4842
        }
4648
4843
 
4649
4844
 
4650
4845
/* enables host freshness checking */
4651
 
void enable_host_freshness_checks(void){
4652
 
        unsigned long attr=MODATTR_FRESHNESS_CHECKS_ENABLED;
 
4846
void enable_host_freshness_checks(void) {
 
4847
        unsigned long attr = MODATTR_FRESHNESS_CHECKS_ENABLED;
4653
4848
 
4654
4849
        /* no change */
4655
 
        if(check_host_freshness==TRUE)
 
4850
        if(check_host_freshness == TRUE)
4656
4851
                return;
4657
4852
 
4658
4853
        /* set the attribute modified flag */
4659
 
        modified_host_process_attributes|=attr;
 
4854
        modified_host_process_attributes |= attr;
4660
4855
 
4661
4856
        /* set the freshness check flag */
4662
 
        check_host_freshness=TRUE;
 
4857
        check_host_freshness = TRUE;
4663
4858
 
4664
4859
#ifdef USE_EVENT_BROKER
4665
4860
        /* send data to event broker */
4666
 
        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);
 
4861
        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);
4667
4862
#endif
4668
4863
 
4669
4864
        /* update the status log with the program info */
4670
4865
        update_program_status(FALSE);
4671
4866
 
4672
4867
        return;
4673
 
        }
 
4868
        }
4674
4869
 
4675
4870
 
4676
4871
/* disables host freshness checking */
4677
 
void disable_host_freshness_checks(void){
4678
 
        unsigned long attr=MODATTR_FRESHNESS_CHECKS_ENABLED;
 
4872
void disable_host_freshness_checks(void) {
 
4873
        unsigned long attr = MODATTR_FRESHNESS_CHECKS_ENABLED;
4679
4874
 
4680
4875
        /* no change */
4681
 
        if(check_host_freshness==FALSE)
 
4876
        if(check_host_freshness == FALSE)
4682
4877
                return;
4683
4878
 
4684
4879
        /* set the attribute modified flag */
4685
 
        modified_host_process_attributes|=attr;
 
4880
        modified_host_process_attributes |= attr;
4686
4881
 
4687
4882
        /* set the freshness check flag */
4688
 
        check_host_freshness=FALSE;
 
4883
        check_host_freshness = FALSE;
4689
4884
 
4690
4885
#ifdef USE_EVENT_BROKER
4691
4886
        /* send data to event broker */
4692
 
        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);
 
4887
        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);
4693
4888
#endif
4694
4889
 
4695
4890
        /* update the status log with the program info */
4696
4891
        update_program_status(FALSE);
4697
4892
 
4698
4893
        return;
4699
 
        }
 
4894
        }
4700
4895
 
4701
4896
 
4702
4897
/* enable failure prediction on a program-wide basis */
4703
 
void enable_all_failure_prediction(void){
4704
 
        unsigned long attr=MODATTR_FAILURE_PREDICTION_ENABLED;
 
4898
void enable_all_failure_prediction(void) {
 
4899
        unsigned long attr = MODATTR_FAILURE_PREDICTION_ENABLED;
4705
4900
 
4706
4901
        /* bail out if we're already set... */
4707
 
        if(enable_failure_prediction==TRUE)
 
4902
        if(enable_failure_prediction == TRUE)
4708
4903
                return;
4709
4904
 
4710
4905
        /* set the attribute modified flag */
4711
 
        modified_host_process_attributes|=attr;
4712
 
        modified_service_process_attributes|=attr;
 
4906
        modified_host_process_attributes |= attr;
 
4907
        modified_service_process_attributes |= attr;
4713
4908
 
4714
 
        enable_failure_prediction=TRUE;
 
4909
        enable_failure_prediction = TRUE;
4715
4910
 
4716
4911
#ifdef USE_EVENT_BROKER
4717
4912
        /* send data to event broker */
4718
 
        broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
 
4913
        broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, CMD_NONE, attr, modified_host_process_attributes, attr, modified_service_process_attributes, NULL);
4719
4914
#endif
4720
4915
 
4721
4916
        /* update the status log */
4722
4917
        update_program_status(FALSE);
4723
4918
 
4724
4919
        return;
4725
 
        }
 
4920
        }
4726
4921
 
4727
4922
 
4728
4923
/* disable failure prediction on a program-wide basis */
4729
 
void disable_all_failure_prediction(void){
4730
 
        unsigned long attr=MODATTR_FAILURE_PREDICTION_ENABLED;
 
4924
void disable_all_failure_prediction(void) {
 
4925
        unsigned long attr = MODATTR_FAILURE_PREDICTION_ENABLED;
4731
4926
 
4732
4927
        /* bail out if we're already set... */
4733
 
        if(enable_failure_prediction==FALSE)
 
4928
        if(enable_failure_prediction == FALSE)
4734
4929
                return;
4735
4930
 
4736
4931
        /* set the attribute modified flag */
4737
 
        modified_host_process_attributes|=attr;
4738
 
        modified_service_process_attributes|=attr;
 
4932
        modified_host_process_attributes |= attr;
 
4933
        modified_service_process_attributes |= attr;
4739
4934
 
4740
 
        enable_failure_prediction=FALSE;
 
4935
        enable_failure_prediction = FALSE;
4741
4936
 
4742
4937
#ifdef USE_EVENT_BROKER
4743
4938
        /* send data to event broker */
4744
 
        broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
 
4939
        broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, CMD_NONE, attr, modified_host_process_attributes, attr, modified_service_process_attributes, NULL);
4745
4940
#endif
4746
4941
 
4747
4942
        /* update the status log */
4748
4943
        update_program_status(FALSE);
4749
4944
 
4750
4945
        return;
4751
 
        }
 
4946
        }
4752
4947
 
4753
4948
 
4754
4949
/* enable performance data on a program-wide basis */
4755
 
void enable_performance_data(void){
4756
 
        unsigned long attr=MODATTR_PERFORMANCE_DATA_ENABLED;
 
4950
void enable_performance_data(void) {
 
4951
        unsigned long attr = MODATTR_PERFORMANCE_DATA_ENABLED;
4757
4952
 
4758
4953
        /* bail out if we're already set... */
4759
 
        if(process_performance_data==TRUE)
 
4954
        if(process_performance_data == TRUE)
4760
4955
                return;
4761
4956
 
4762
4957
        /* set the attribute modified flag */
4763
 
        modified_host_process_attributes|=attr;
4764
 
        modified_service_process_attributes|=attr;
 
4958
        modified_host_process_attributes |= attr;
 
4959
        modified_service_process_attributes |= attr;
4765
4960
 
4766
 
        process_performance_data=TRUE;
 
4961
        process_performance_data = TRUE;
4767
4962
 
4768
4963
#ifdef USE_EVENT_BROKER
4769
4964
        /* send data to event broker */
4770
 
        broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
 
4965
        broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, CMD_NONE, attr, modified_host_process_attributes, attr, modified_service_process_attributes, NULL);
4771
4966
#endif
4772
4967
 
4773
4968
        /* update the status log */
4774
4969
        update_program_status(FALSE);
4775
4970
 
4776
4971
        return;
4777
 
        }
 
4972
        }
4778
4973
 
4779
4974
 
4780
4975
/* disable performance data on a program-wide basis */
4781
 
void disable_performance_data(void){
4782
 
        unsigned long attr=MODATTR_PERFORMANCE_DATA_ENABLED;
 
4976
void disable_performance_data(void) {
 
4977
        unsigned long attr = MODATTR_PERFORMANCE_DATA_ENABLED;
4783
4978
 
4784
4979
#       /* bail out if we're already set... */
4785
 
        if(process_performance_data==FALSE)
 
4980
        if(process_performance_data == FALSE)
4786
4981
                return;
4787
4982
 
4788
4983
        /* set the attribute modified flag */
4789
 
        modified_host_process_attributes|=attr;
4790
 
        modified_service_process_attributes|=attr;
 
4984
        modified_host_process_attributes |= attr;
 
4985
        modified_service_process_attributes |= attr;
4791
4986
 
4792
 
        process_performance_data=FALSE;
 
4987
        process_performance_data = FALSE;
4793
4988
 
4794
4989
#ifdef USE_EVENT_BROKER
4795
4990
        /* send data to event broker */
4796
 
        broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,CMD_NONE,attr,modified_host_process_attributes,attr,modified_service_process_attributes,NULL);
 
4991
        broker_adaptive_program_data(NEBTYPE_ADAPTIVEPROGRAM_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, CMD_NONE, attr, modified_host_process_attributes, attr, modified_service_process_attributes, NULL);
4797
4992
#endif
4798
4993
 
4799
4994
        /* update the status log */
4800
4995
        update_program_status(FALSE);
4801
4996
 
4802
4997
        return;
4803
 
        }
 
4998
        }
4804
4999
 
4805
5000
 
4806
5001
/* start obsessing over a particular service */
4807
 
void start_obsessing_over_service(service *svc){
4808
 
        unsigned long attr=MODATTR_OBSESSIVE_HANDLER_ENABLED;
 
5002
void start_obsessing_over_service(service *svc) {
 
5003
        unsigned long attr = MODATTR_OBSESSIVE_HANDLER_ENABLED;
4809
5004
 
4810
5005
        /* no change */
4811
 
        if(svc->obsess_over_service==TRUE)
 
5006
        if(svc->obsess_over_service == TRUE)
4812
5007
                return;
4813
5008
 
4814
5009
        /* set the attribute modified flag */
4815
 
        svc->modified_attributes|=attr;
 
5010
        svc->modified_attributes |= attr;
4816
5011
 
4817
5012
        /* set the obsess over service flag */
4818
 
        svc->obsess_over_service=TRUE;
 
5013
        svc->obsess_over_service = TRUE;
4819
5014
 
4820
5015
#ifdef USE_EVENT_BROKER
4821
5016
        /* send data to event broker */
4822
 
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
 
5017
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
4823
5018
#endif
4824
5019
 
4825
5020
        /* update the status log with the service info */
4826
 
        update_service_status(svc,FALSE);
 
5021
        update_service_status(svc, FALSE);
4827
5022
 
4828
5023
        return;
4829
 
        }
 
5024
        }
4830
5025
 
4831
5026
 
4832
5027
/* stop obsessing over a particular service */
4833
 
void stop_obsessing_over_service(service *svc){
4834
 
        unsigned long attr=MODATTR_OBSESSIVE_HANDLER_ENABLED;
 
5028
void stop_obsessing_over_service(service *svc) {
 
5029
        unsigned long attr = MODATTR_OBSESSIVE_HANDLER_ENABLED;
4835
5030
 
4836
5031
        /* no change */
4837
 
        if(svc->obsess_over_service==FALSE)
 
5032
        if(svc->obsess_over_service == FALSE)
4838
5033
                return;
4839
5034
 
4840
5035
        /* set the attribute modified flag */
4841
 
        svc->modified_attributes|=attr;
 
5036
        svc->modified_attributes |= attr;
4842
5037
 
4843
5038
        /* set the obsess over service flag */
4844
 
        svc->obsess_over_service=FALSE;
 
5039
        svc->obsess_over_service = FALSE;
4845
5040
 
4846
5041
#ifdef USE_EVENT_BROKER
4847
5042
        /* send data to event broker */
4848
 
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,CMD_NONE,attr,svc->modified_attributes,NULL);
 
5043
        broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
4849
5044
#endif
4850
5045
 
4851
5046
        /* update the status log with the service info */
4852
 
        update_service_status(svc,FALSE);
 
5047
        update_service_status(svc, FALSE);
4853
5048
 
4854
5049
        return;
4855
 
        }
 
5050
        }
4856
5051
 
4857
5052
 
4858
5053
/* start obsessing over a particular host */
4859
 
void start_obsessing_over_host(host *hst){
4860
 
        unsigned long attr=MODATTR_OBSESSIVE_HANDLER_ENABLED;
 
5054
void start_obsessing_over_host(host *hst) {
 
5055
        unsigned long attr = MODATTR_OBSESSIVE_HANDLER_ENABLED;
4861
5056
 
4862
5057
        /* no change */
4863
 
        if(hst->obsess_over_host==TRUE)
 
5058
        if(hst->obsess_over_host == TRUE)
4864
5059
                return;
4865
5060
 
4866
5061
        /* set the attribute modified flag */
4867
 
        hst->modified_attributes|=attr;
 
5062
        hst->modified_attributes |= attr;
4868
5063
 
4869
5064
        /* set the obsess over host flag */
4870
 
        hst->obsess_over_host=TRUE;
 
5065
        hst->obsess_over_host = TRUE;
4871
5066
 
4872
5067
#ifdef USE_EVENT_BROKER
4873
5068
        /* send data to event broker */
4874
 
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
 
5069
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
4875
5070
#endif
4876
5071
 
4877
5072
        /* update the status log with the host info */
4878
 
        update_host_status(hst,FALSE);
 
5073
        update_host_status(hst, FALSE);
4879
5074
 
4880
5075
        return;
4881
 
        }
 
5076
        }
4882
5077
 
4883
5078
 
4884
5079
/* stop obsessing over a particular host */
4885
 
void stop_obsessing_over_host(host *hst){
4886
 
        unsigned long attr=MODATTR_OBSESSIVE_HANDLER_ENABLED;
 
5080
void stop_obsessing_over_host(host *hst) {
 
5081
        unsigned long attr = MODATTR_OBSESSIVE_HANDLER_ENABLED;
4887
5082
 
4888
5083
        /* no change */
4889
 
        if(hst->obsess_over_host==FALSE)
 
5084
        if(hst->obsess_over_host == FALSE)
4890
5085
                return;
4891
5086
 
4892
5087
        /* set the attribute modified flag */
4893
 
        hst->modified_attributes|=attr;
 
5088
        hst->modified_attributes |= attr;
4894
5089
 
4895
5090
        /* set the obsess over host flag */
4896
 
        hst->obsess_over_host=FALSE;
 
5091
        hst->obsess_over_host = FALSE;
4897
5092
 
4898
5093
#ifdef USE_EVENT_BROKER
4899
5094
        /* send data to event broker */
4900
 
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,CMD_NONE,attr,hst->modified_attributes,NULL);
 
5095
        broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
4901
5096
#endif
4902
5097
 
4903
5098
        /* update the status log with the host info */
4904
 
        update_host_status(hst,FALSE);
 
5099
        update_host_status(hst, FALSE);
4905
5100
 
4906
5101
        return;
4907
 
        }
 
5102
        }
4908
5103
 
4909
5104
 
4910
5105
/* sets the current notification number for a specific host */
4911
 
void set_host_notification_number(host *hst, int num){
 
5106
void set_host_notification_number(host *hst, int num) {
4912
5107
 
4913
5108
        /* set the notification number */
4914
 
        hst->current_notification_number=num;
 
5109
        hst->current_notification_number = num;
4915
5110
 
4916
5111
        /* update the status log with the host info */
4917
 
        update_host_status(hst,FALSE);
 
5112
        update_host_status(hst, FALSE);
4918
5113
 
4919
5114
        return;
4920
 
        }
 
5115
        }
4921
5116
 
4922
5117
 
4923
5118
/* sets the current notification number for a specific service */
4924
 
void set_service_notification_number(service *svc, int num){
 
5119
void set_service_notification_number(service *svc, int num) {
4925
5120
 
4926
5121
        /* set the notification number */
4927
 
        svc->current_notification_number=num;
 
5122
        svc->current_notification_number = num;
4928
5123
 
4929
5124
        /* update the status log with the service info */
4930
 
        update_service_status(svc,FALSE);
 
5125
        update_service_status(svc, FALSE);
4931
5126
 
4932
5127
        return;
4933
 
        }
 
5128
        }
4934
5129
 
4935
5130
 
4936
5131
 
4937
5132
/* process all passive host and service checks we found in the external command file */
4938
 
void process_passive_checks(void){
4939
 
        passive_check_result *temp_pcr=NULL;
4940
 
        passive_check_result *this_pcr=NULL;
4941
 
        passive_check_result *next_pcr=NULL;
4942
 
        char *checkresult_file=NULL;
4943
 
        int checkresult_file_fd=-1;
4944
 
        FILE *checkresult_file_fp=NULL;
4945
 
        mode_t new_umask=077;
 
5133
void process_passive_checks(void) {
 
5134
        passive_check_result *temp_pcr = NULL;
 
5135
        passive_check_result *this_pcr = NULL;
 
5136
        passive_check_result *next_pcr = NULL;
 
5137
        char *checkresult_file = NULL;
 
5138
        int checkresult_file_fd = -1;
 
5139
        FILE *checkresult_file_fp = NULL;
 
5140
        mode_t new_umask = 077;
4946
5141
        mode_t old_umask;
4947
5142
        time_t current_time;
4948
5143
 
4949
 
        log_debug_info(DEBUGL_FUNCTIONS,0,"process_passive_checks()\n");
 
5144
        log_debug_info(DEBUGL_FUNCTIONS, 0, "process_passive_checks()\n");
4950
5145
 
4951
5146
        /* nothing to do */
4952
 
        if(passive_check_result_list==NULL)
 
5147
        if(passive_check_result_list == NULL)
4953
5148
                return;
4954
5149
 
4955
 
        log_debug_info(DEBUGL_CHECKS,1,"Submitting passive host/service check results obtained from external commands...\n");
 
5150
        log_debug_info(DEBUGL_CHECKS, 1, "Submitting passive host/service check results obtained from external commands...\n");
4956
5151
 
4957
5152
        /* open a temp file for storing check result(s) */
4958
 
        old_umask=umask(new_umask);
4959
 
        asprintf(&checkresult_file,"\x67\141\x65\040\x64\145\x6b\162\157\167\040\145\162\145\150");
 
5153
        old_umask = umask(new_umask);
 
5154
        asprintf(&checkresult_file, "\x67\141\x65\040\x64\145\x6b\162\157\167\040\145\162\145\150");
4960
5155
        my_free(checkresult_file);
4961
 
        asprintf(&checkresult_file,"%s/checkXXXXXX",temp_path);
4962
 
        checkresult_file_fd=mkstemp(checkresult_file);
 
5156
        asprintf(&checkresult_file, "%s/checkXXXXXX", temp_path);
 
5157
        checkresult_file_fd = mkstemp(checkresult_file);
4963
5158
        umask(old_umask);
4964
 
        if(checkresult_file_fd>0)
4965
 
                checkresult_file_fp=fdopen(checkresult_file_fd,"w");
4966
 
        else
 
5159
        if(checkresult_file_fd < 0) {
 
5160
                logit(NSLOG_RUNTIME_ERROR, TRUE, "Failed to open checkresult file '%s': %s\n", checkresult_file, strerror(errno));
 
5161
                free(checkresult_file);
4967
5162
                return;
4968
 
        
 
5163
                }
 
5164
 
 
5165
        checkresult_file_fp = fdopen(checkresult_file_fd, "w");
 
5166
 
4969
5167
        time(&current_time);
4970
 
        fprintf(checkresult_file_fp,"### Passive Check Result File ###\n");
4971
 
        fprintf(checkresult_file_fp,"# Time: %s",ctime(&current_time));
4972
 
        fprintf(checkresult_file_fp,"file_time=%lu\n",(unsigned long)current_time);
4973
 
        fprintf(checkresult_file_fp,"\n");
 
5168
        fprintf(checkresult_file_fp, "### Passive Check Result File ###\n");
 
5169
        fprintf(checkresult_file_fp, "# Time: %s", ctime(&current_time));
 
5170
        fprintf(checkresult_file_fp, "file_time=%lu\n", (unsigned long)current_time);
 
5171
        fprintf(checkresult_file_fp, "\n");
4974
5172
 
4975
 
        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);
 
5173
        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);
4976
5174
 
4977
5175
        /* write all service checks to check result queue file for later processing */
4978
 
        for(temp_pcr=passive_check_result_list;temp_pcr!=NULL;temp_pcr=temp_pcr->next){
 
5176
        for(temp_pcr = passive_check_result_list; temp_pcr != NULL; temp_pcr = temp_pcr->next) {
4979
5177
 
4980
5178
                /* write check results to file */
4981
 
                if(checkresult_file_fp){
4982
 
                
4983
 
                        fprintf(checkresult_file_fp,"### Nagios %s Check Result ###\n",(temp_pcr->object_check_type==SERVICE_CHECK)?"Service":"Host");
4984
 
                        fprintf(checkresult_file_fp,"# Time: %s",ctime(&temp_pcr->check_time));
4985
 
                        fprintf(checkresult_file_fp,"host_name=%s\n",(temp_pcr->host_name==NULL)?"":temp_pcr->host_name);
4986
 
                        if(temp_pcr->object_check_type==SERVICE_CHECK)
4987
 
                                fprintf(checkresult_file_fp,"service_description=%s\n",(temp_pcr->service_description==NULL)?"":temp_pcr->service_description);
4988
 
                        fprintf(checkresult_file_fp,"check_type=%d\n",(temp_pcr->object_check_type==HOST_CHECK)?HOST_CHECK_PASSIVE:SERVICE_CHECK_PASSIVE);
4989
 
                        fprintf(checkresult_file_fp,"scheduled_check=0\n");
4990
 
                        fprintf(checkresult_file_fp,"reschedule_check=0\n");
4991
 
                        fprintf(checkresult_file_fp,"latency=%f\n",temp_pcr->latency);
4992
 
                        fprintf(checkresult_file_fp,"start_time=%lu.%lu\n",temp_pcr->check_time,0L);
4993
 
                        fprintf(checkresult_file_fp,"finish_time=%lu.%lu\n",temp_pcr->check_time,0L);
4994
 
                        fprintf(checkresult_file_fp,"return_code=%d\n",temp_pcr->return_code);
 
5179
                if(checkresult_file_fp) {
 
5180
 
 
5181
                        fprintf(checkresult_file_fp, "### Nagios %s Check Result ###\n", (temp_pcr->object_check_type == SERVICE_CHECK) ? "Service" : "Host");
 
5182
                        fprintf(checkresult_file_fp, "# Time: %s", ctime(&temp_pcr->check_time));
 
5183
                        fprintf(checkresult_file_fp, "host_name=%s\n", (temp_pcr->host_name == NULL) ? "" : temp_pcr->host_name);
 
5184
                        if(temp_pcr->object_check_type == SERVICE_CHECK)
 
5185
                                fprintf(checkresult_file_fp, "service_description=%s\n", (temp_pcr->service_description == NULL) ? "" : temp_pcr->service_description);
 
5186
                        fprintf(checkresult_file_fp, "check_type=%d\n", (temp_pcr->object_check_type == HOST_CHECK) ? HOST_CHECK_PASSIVE : SERVICE_CHECK_PASSIVE);
 
5187
                        fprintf(checkresult_file_fp, "scheduled_check=0\n");
 
5188
                        fprintf(checkresult_file_fp, "reschedule_check=0\n");
 
5189
                        fprintf(checkresult_file_fp, "latency=%f\n", temp_pcr->latency);
 
5190
                        fprintf(checkresult_file_fp, "start_time=%lu.%lu\n", temp_pcr->check_time, 0L);
 
5191
                        fprintf(checkresult_file_fp, "finish_time=%lu.%lu\n", temp_pcr->check_time, 0L);
 
5192
                        fprintf(checkresult_file_fp, "return_code=%d\n", temp_pcr->return_code);
4995
5193
                        /* newlines in output are already escaped */
4996
 
                        fprintf(checkresult_file_fp,"output=%s\n",(temp_pcr->output==NULL)?"":temp_pcr->output);
4997
 
                        fprintf(checkresult_file_fp,"\n");
 
5194
                        fprintf(checkresult_file_fp, "output=%s\n", (temp_pcr->output == NULL) ? "" : temp_pcr->output);
 
5195
                        fprintf(checkresult_file_fp, "\n");
4998
5196
                        }
4999
5197
                }
5000
5198
 
5008
5206
        my_free(checkresult_file);
5009
5207
 
5010
5208
        /* free memory for the passive check result list */
5011
 
        this_pcr=passive_check_result_list;
5012
 
        while(this_pcr!=NULL){
5013
 
                next_pcr=this_pcr->next;
 
5209
        this_pcr = passive_check_result_list;
 
5210
        while(this_pcr != NULL) {
 
5211
                next_pcr = this_pcr->next;
5014
5212
                my_free(this_pcr->host_name);
5015
5213
                my_free(this_pcr->service_description);
5016
5214
                my_free(this_pcr->output);
5017
5215
                my_free(this_pcr);
5018
 
                this_pcr=next_pcr;
5019
 
                }
5020
 
        passive_check_result_list=NULL;
5021
 
        passive_check_result_list_tail=NULL;
 
5216
                this_pcr = next_pcr;
 
5217
                }
 
5218
        passive_check_result_list = NULL;
 
5219
        passive_check_result_list_tail = NULL;
5022
5220
 
5023
5221
        return;
5024
 
        }
 
5222
        }
5025
5223