1 /*****************************************************************************
2 *
3 * COMMANDS.C - External command functions for Nagios
4 *
5 * Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
6 * Last Modified: 11-30-2008
7 *
8 * License:
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 *****************************************************************************/
24
25 #include "../include/config.h"
26 #include "../include/common.h"
27 #include "../include/comments.h"
28 #include "../include/downtime.h"
29 #include "../include/statusdata.h"
30 #include "../include/perfdata.h"
31 #include "../include/sretention.h"
32 #include "../include/broker.h"
33 #include "../include/nagios.h"
34
35 extern char *config_file;
36 extern char *log_file;
37 extern char *command_file;
38 extern char *temp_file;
39 extern char *temp_path;
40
41 extern int sigshutdown;
42 extern int sigrestart;
43
44 extern int check_external_commands;
45
46 extern int ipc_pipe[2];
47
48 extern time_t last_command_check;
49 extern time_t last_command_status_update;
50
51 extern int command_check_interval;
52
53 extern int enable_notifications;
54 extern int execute_service_checks;
55 extern int accept_passive_service_checks;
56 extern int execute_host_checks;
57 extern int accept_passive_host_checks;
58 extern int enable_event_handlers;
59 extern int obsess_over_services;
60 extern int obsess_over_hosts;
61 extern int check_service_freshness;
62 extern int check_host_freshness;
63 extern int enable_failure_prediction;
64 extern int process_performance_data;
65
66 extern int log_external_commands;
67 extern int log_passive_checks;
68
69 extern unsigned long modified_host_process_attributes;
70 extern unsigned long modified_service_process_attributes;
71
72 extern char *global_host_event_handler;
73 extern char *global_service_event_handler;
74 extern command *global_host_event_handler_ptr;
75 extern command *global_service_event_handler_ptr;
76
77 extern host *host_list;
78 extern service *service_list;
79
80 extern FILE *command_file_fp;
81 extern int command_file_fd;
82
83 passive_check_result *passive_check_result_list = NULL;
84 passive_check_result *passive_check_result_list_tail = NULL;
85
86 extern pthread_t worker_threads[TOTAL_WORKER_THREADS];
87 extern circular_buffer external_command_buffer;
88 extern int external_command_buffer_slots;
89
90
91
92 /******************************************************************/
93 /****************** EXTERNAL COMMAND PROCESSING *******************/
94 /******************************************************************/
95
96
97 /* checks for the existence of the external command file and processes all commands found in it */
check_for_external_commands(void)98 int check_for_external_commands(void) {
99 char *buffer = NULL;
100 int update_status = FALSE;
101
102 log_debug_info(DEBUGL_FUNCTIONS, 0, "check_for_external_commands()\n");
103
104 /* bail out if we shouldn't be checking for external commands */
105 if(check_external_commands == FALSE)
106 return ERROR;
107
108 /* update last command check time */
109 last_command_check = time(NULL);
110
111 /* update the status log with new program information */
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;
115 else
116 update_status = TRUE;
117 if(update_status == TRUE) {
118 last_command_status_update = last_command_check;
119 update_program_status(FALSE);
120 }
121
122 /* reset passive check result list pointers */
123 passive_check_result_list = NULL;
124 passive_check_result_list_tail = NULL;
125
126 /* process all commands found in the buffer */
127 while(1) {
128
129 /* get a lock on the buffer */
130 pthread_mutex_lock(&external_command_buffer.buffer_lock);
131
132 /* if no items present, bail out */
133 if(external_command_buffer.items <= 0) {
134 pthread_mutex_unlock(&external_command_buffer.buffer_lock);
135 break;
136 }
137
138 if(external_command_buffer.buffer[external_command_buffer.tail])
139 buffer = strdup(((char **)external_command_buffer.buffer)[external_command_buffer.tail]);
140
141 /* free memory allocated for buffer slot */
142 my_free(((char **)external_command_buffer.buffer)[external_command_buffer.tail]);
143
144 /* adjust tail counter and number of items */
145 external_command_buffer.tail = (external_command_buffer.tail + 1) % external_command_buffer_slots;
146 external_command_buffer.items--;
147
148 /* release the lock on the buffer */
149 pthread_mutex_unlock(&external_command_buffer.buffer_lock);
150
151 /* process the command */
152 process_external_command1(buffer);
153
154 /* free memory */
155 my_free(buffer);
156 }
157
158 /**** PROCESS ALL PASSIVE HOST AND SERVICE CHECK RESULTS AT ONE TIME ****/
159 if(passive_check_result_list != NULL)
160 process_passive_checks();
161
162 return OK;
163 }
164
165
166
167 /* processes all external commands in a (regular) file */
process_external_commands_from_file(char * fname,int delete_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)
176 return ERROR;
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");
179
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);
183 return ERROR;
184 }
185
186 /* process all commands in the file */
187 while(1) {
188
189 /* free memory */
190 my_free(input);
191
192 /* read the next line */
193 if((input = mmap_fgets(thefile)) == NULL)
194 break;
195
196 /* process the command */
197 process_external_command1(input);
198 }
199
200 /* close the file */
201 mmap_fclose(thefile);
202
203 /* delete the file */
204 if(delete_file == TRUE)
205 unlink(fname);
206
207 return OK;
208 }
209
210
211
212 /* top-level external command processor */
process_external_command1(char * cmd)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 return ERROR;
225
226 /* strip the command of newlines and carriage returns */
227 strip(cmd);
228
229 log_debug_info(DEBUGL_EXTERNALCOMMANDS, 2, "Raw command entry: %s\n", cmd);
230
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);
237
238 /* get the command identifier */
239 if((temp_ptr = my_strtok(NULL, ";")) == NULL)
240 return ERROR;
241 if((command_id = (char *)strdup(temp_ptr + 1)) == NULL)
242 return ERROR;
243
244 /* get the command arguments */
245 if((temp_ptr = my_strtok(NULL, "\n")) == NULL)
246 args = (char *)strdup("");
247 else
248 args = (char *)strdup(temp_ptr);
249 if(args == NULL) {
250 my_free(command_id);
251 return ERROR;
252 }
253
254 /* decide what type of command this is... */
255
256 /**************************/
257 /**** PROCESS COMMANDS ****/
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;
342
343
344 /*******************************/
345 /**** HOST-RELATED COMMANDS ****/
346 /*******************************/
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 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;
472
473
474 /************************************/
475 /**** HOSTGROUP-RELATED COMMANDS ****/
476 /************************************/
477
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;
512
513
514 /**********************************/
515 /**** SERVICE-RELATED COMMANDS ****/
516 /**********************************/
517
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;
610
611
612 /***************************************/
613 /**** SERVICEGROUP-RELATED COMMANDS ****/
614 /***************************************/
615
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;
650
651
652 /**********************************/
653 /**** CONTACT-RELATED COMMANDS ****/
654 /**********************************/
655
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;
678
679 /***************************************/
680 /**** CONTACTGROUP-RELATED COMMANDS ****/
681 /***************************************/
682
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;
687
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;
692
693
694 /**************************/
695 /****** MISC COMMANDS *****/
696 /**************************/
697
698 else if(!strcmp(command_id, "PROCESS_FILE"))
699 command_type = CMD_PROCESS_FILE;
700
701
702
703 /****************************/
704 /****** CUSTOM COMMANDS *****/
705 /****************************/
706
707 else if(command_id[0] == '_')
708 command_type = CMD_CUSTOM_COMMAND;
709
710
711
712 /**** UNKNOWN COMMAND ****/
713 else {
714 /* log the bad external command */
715 logit(NSLOG_EXTERNAL_COMMAND | NSLOG_RUNTIME_WARNING, TRUE, "Warning: Unrecognized external command -> %s;%s\n", command_id, args);
716
717 /* free memory */
718 my_free(command_id);
719 my_free(args);
720
721 return ERROR;
722 }
723
724 /* update statistics for external commands */
725 update_check_stats(EXTERNAL_COMMAND_STATS, time(NULL));
726
727 /* log the external command */
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) {
730 /* passive checks are logged in checks.c as well, as some my bypass external commands by getting dropped in checkresults dir */
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 }
738 my_free(temp_buffer);
739
740 #ifdef USE_EVENT_BROKER
741 /* send data to event broker */
742 broker_external_command(NEBTYPE_EXTERNALCOMMAND_START, NEBFLAG_NONE, NEBATTR_NONE, command_type, entry_time, command_id, args, NULL);
743 #endif
744
745 /* process the command */
746 process_external_command2(command_type, entry_time, args);
747
748 #ifdef USE_EVENT_BROKER
749 /* send data to event broker */
750 broker_external_command(NEBTYPE_EXTERNALCOMMAND_END, NEBFLAG_NONE, NEBATTR_NONE, command_type, entry_time, command_id, args, NULL);
751 #endif
752
753 /* free memory */
754 my_free(command_id);
755 my_free(args);
756
757 return OK;
758 }
759
760
761
762 /* top-level processor for a single external command */
process_external_command2(int cmd,time_t entry_time,char * 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);
770
771 /* how shall we execute the command? */
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 /*****************************/
929
930 case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
931 case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
932 case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
933 case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
934 case CMD_ENABLE_HOSTGROUP_HOST_CHECKS:
935 case CMD_DISABLE_HOSTGROUP_HOST_CHECKS:
936 case CMD_ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS:
937 case CMD_DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS:
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 */
1156 break;
1157
1158 default:
1159 return ERROR;
1160 break;
1161 }
1162
1163 return OK;
1164 }
1165
1166
1167 /* processes an external host command */
process_host_command(int cmd,time_t entry_time,char * args)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)
1217 continue;
1218 if(cmd == CMD_ENABLE_HOST_SVC_NOTIFICATIONS)
1219 enable_service_notifications(temp_service);
1220 else
1221 disable_service_notifications(temp_service);
1222 }
1223 break;
1224
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)
1231 enable_service_checks(temp_service);
1232 else
1233 disable_service_checks(temp_service);
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 */
process_hostgroup_command(int cmd,time_t entry_time,char * args)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:
1331 enable_host_notifications(temp_host);
1332 break;
1333
1334 case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
1335 disable_host_notifications(temp_host);
1336 break;
1337
1338 case CMD_ENABLE_HOSTGROUP_HOST_CHECKS:
1339 enable_host_checks(temp_host);
1340 break;
1341
1342 case CMD_DISABLE_HOSTGROUP_HOST_CHECKS:
1343 disable_host_checks(temp_host);
1344 break;
1345
1346 case CMD_ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS:
1347 enable_passive_host_checks(temp_host);
1348 break;
1349
1350 case CMD_DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS:
1351 disable_passive_host_checks(temp_host);
1352 break;
1353
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
1392 break;
1393 }
1394
1395 }
1396
1397 return OK;
1398 }
1399
1400
1401
1402 /* processes an external service command */
process_service_command(int cmd,time_t entry_time,char * args)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 */
process_servicegroup_command(int cmd,time_t entry_time,char * args)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 }
1625
1626
1627
1628 /* processes an external contact command */
process_contact_command(int cmd,time_t entry_time,char * args)1629 int process_contact_command(int cmd, time_t entry_time, char *args) {
1630 char *contact_name = NULL;
1631 contact *temp_contact = NULL;
1632
1633 /* get the contact name */
1634 if((contact_name = my_strtok(args, ";")) == NULL)
1635 return ERROR;
1636
1637 /* find the contact */
1638 if((temp_contact = find_contact(contact_name)) == NULL)
1639 return ERROR;
1640
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 }
1662
1663 return OK;
1664 }
1665
1666
1667 /* processes an external contactgroup command */
process_contactgroup_command(int cmd,time_t entry_time,char * args)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;
1673
1674 /* get the contactgroup name */
1675 if((contactgroup_name = my_strtok(args, ";")) == NULL)
1676 return ERROR;
1677
1678 /* find the contactgroup */
1679 if((temp_contactgroup = find_contactgroup(contactgroup_name)) == NULL)
1680 return ERROR;
1681
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 }
1723
1724 return OK;
1725 }
1726
1727
1728
1729 /******************************************************************/
1730 /*************** EXTERNAL COMMAND IMPLEMENTATIONS ****************/
1731 /******************************************************************/
1732
1733 /* adds a host or service comment to the status log */
cmd_add_comment(int cmd,time_t entry_time,char * args)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;
1744
1745 /* get the host name */
1746 if((host_name = my_strtok(args, ";")) == NULL)
1747 return ERROR;
1748
1749 /* if we're adding a service comment... */
1750 if(cmd == CMD_ADD_SVC_COMMENT) {
1751
1752 /* get the service description */
1753 if((svc_description = my_strtok(NULL, ";")) == NULL)
1754 return ERROR;
1755
1756 /* verify that the service is valid */
1757 if((temp_service = find_service(host_name, svc_description)) == NULL)
1758 return ERROR;
1759 }
1760
1761 /* else verify that the host is valid */
1762 if((temp_host = find_host(host_name)) == NULL)
1763 return ERROR;
1764
1765 /* get the persistent flag */
1766 if((temp_ptr = my_strtok(NULL, ";")) == NULL)
1767 return ERROR;
1768 persistent = atoi(temp_ptr);
1769 if(persistent > 1)
1770 persistent = 1;
1771 else if(persistent < 0)
1772 persistent = 0;
1773
1774 /* get the name of the user who entered the comment */
1775 if((user = my_strtok(NULL, ";")) == NULL)
1776 return ERROR;
1777
1778 /* get the comment */
1779 if((comment_data = my_strtok(NULL, "\n")) == NULL)
1780 return ERROR;
1781
1782 /* add the comment */
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);
1784
1785 if(result < 0)
1786 return ERROR;
1787
1788 return OK;
1789 }
1790
1791
1792
1793 /* removes a host or service comment from the status log */
cmd_delete_comment(int cmd,char * args)1794 int cmd_delete_comment(int cmd, char *args) {
1795 unsigned long comment_id = 0L;
1796
1797 /* get the comment id we should delete */
1798 if((comment_id = strtoul(args, NULL, 10)) == 0)
1799 return ERROR;
1800
1801 /* delete the specified comment */
1802 if(cmd == CMD_DEL_HOST_COMMENT)
1803 delete_host_comment(comment_id);
1804 else
1805 delete_service_comment(comment_id);
1806
1807 return OK;
1808 }
1809
1810
1811
1812 /* removes all comments associated with a host or service from the status log */
cmd_delete_all_comments(int cmd,char * args)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;
1818
1819 /* get the host name */
1820 if((host_name = my_strtok(args, ";")) == NULL)
1821 return ERROR;
1822
1823 /* if we're deleting service comments... */
1824 if(cmd == CMD_DEL_ALL_SVC_COMMENTS) {
1825
1826 /* get the service description */
1827 if((svc_description = my_strtok(NULL, ";")) == NULL)
1828 return ERROR;
1829
1830 /* verify that the service is valid */
1831 if((temp_service = find_service(host_name, svc_description)) == NULL)
1832 return ERROR;
1833 }
1834
1835 /* else verify that the host is valid */
1836 if((temp_host = find_host(host_name)) == NULL)
1837 return ERROR;
1838
1839 /* delete comments */
1840 delete_all_comments((cmd == CMD_DEL_ALL_HOST_COMMENTS) ? HOST_COMMENT : SERVICE_COMMENT, host_name, svc_description);
1841
1842 return OK;
1843 }
1844
1845
1846
1847 /* delays a host or service notification for given number of minutes */
cmd_delay_notification(int cmd,char * args)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;
1855
1856 /* get the host name */
1857 if((host_name = my_strtok(args, ";")) == NULL)
1858 return ERROR;
1859
1860 /* if this is a service notification delay... */
1861 if(cmd == CMD_DELAY_SVC_NOTIFICATION) {
1862
1863 /* get the service description */
1864 if((svc_description = my_strtok(NULL, ";")) == NULL)
1865 return ERROR;
1866
1867 /* verify that the service is valid */
1868 if((temp_service = find_service(host_name, svc_description)) == NULL)
1869 return ERROR;
1870 }
1871
1872 /* else verify that the host is valid */
1873 else {
1874
1875 if((temp_host = find_host(host_name)) == NULL)
1876 return ERROR;
1877 }
1878
1879 /* get the time that we should delay until... */
1880 if((temp_ptr = my_strtok(NULL, "\n")) == NULL)
1881 return ERROR;
1882 delay_time = strtoul(temp_ptr, NULL, 10);
1883
1884 /* delay the next notification... */
1885 if(cmd == CMD_DELAY_HOST_NOTIFICATION)
1886 temp_host->next_host_notification = delay_time;
1887 else
1888 temp_service->next_notification = delay_time;
1889
1890 return OK;
1891 }
1892
1893
1894
1895 /* schedules a host check at a particular time */
cmd_schedule_check(int cmd,char * args)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;
1904
1905 /* get the host name */
1906 if((host_name = my_strtok(args, ";")) == NULL)
1907 return ERROR;
1908
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) {
1910
1911 /* verify that the host is valid */
1912 if((temp_host = find_host(host_name)) == NULL)
1913 return ERROR;
1914 }
1915
1916 else {
1917
1918 /* get the service description */
1919 if((svc_description = my_strtok(NULL, ";")) == NULL)
1920 return ERROR;
1921
1922 /* verify that the service is valid */
1923 if((temp_service = find_service(host_name, svc_description)) == NULL)
1924 return ERROR;
1925 }
1926
1927 /* get the next check time */
1928 if((temp_ptr = my_strtok(NULL, "\n")) == NULL)
1929 return ERROR;
1930 delay_time = strtoul(temp_ptr, NULL, 10);
1931
1932 /* schedule the host check */
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);
1935
1936 /* schedule service checks */
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)
1940 continue;
1941 schedule_service_check(temp_service, delay_time, (cmd == CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS) ? CHECK_OPTION_FORCE_EXECUTION : CHECK_OPTION_NONE);
1942 }
1943 }
1944 else
1945 schedule_service_check(temp_service, delay_time, (cmd == CMD_SCHEDULE_FORCED_SVC_CHECK) ? CHECK_OPTION_FORCE_EXECUTION : CHECK_OPTION_NONE);
1946
1947 return OK;
1948 }
1949
1950
1951
1952 /* schedules all service checks on a host for a particular time */
cmd_schedule_host_service_checks(int cmd,char * args,int force)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;
1960
1961 /* get the host name */
1962 if((host_name = my_strtok(args, ";")) == NULL)
1963 return ERROR;
1964
1965 /* verify that the host is valid */
1966 if((temp_host = find_host(host_name)) == NULL)
1967 return ERROR;
1968
1969 /* get the next check time */
1970 if((temp_ptr = my_strtok(NULL, "\n")) == NULL)
1971 return ERROR;
1972 delay_time = strtoul(temp_ptr, NULL, 10);
1973
1974 /* reschedule all services on the specified host */
1975 for(temp_servicesmember = temp_host->services; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {
1976 if((temp_service = temp_servicesmember->service_ptr) == NULL)
1977 continue;
1978 schedule_service_check(temp_service, delay_time, (force == TRUE) ? CHECK_OPTION_FORCE_EXECUTION : CHECK_OPTION_NONE);
1979 }
1980
1981 return OK;
1982 }
1983
1984
1985
1986
1987 /* schedules a program shutdown or restart */
cmd_signal_process(int cmd,char * args)1988 int cmd_signal_process(int cmd, char *args) {
1989 time_t scheduled_time = 0L;
1990 char *temp_ptr = NULL;
1991 int result = OK;
1992
1993 /* get the time to schedule the event */
1994 if((temp_ptr = my_strtok(args, "\n")) == NULL)
1995 scheduled_time = 0L;
1996 else
1997 scheduled_time = strtoul(temp_ptr, NULL, 10);
1998
1999 /* add a scheduled program shutdown or restart to the event list */
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);
2001
2002 return result;
2003 }
2004
2005
2006
2007 /* processes results of an external service check */
cmd_process_service_check_result(int cmd,time_t check_time,char * args)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;
2015
2016 /* get the host name */
2017 if((temp_ptr = my_strtok(args, ";")) == NULL)
2018 return ERROR;
2019 host_name = (char *)strdup(temp_ptr);
2020
2021 /* get the service description */
2022 if((temp_ptr = my_strtok(NULL, ";")) == NULL) {
2023 my_free(host_name);
2024 return ERROR;
2025 }
2026 svc_description = (char *)strdup(temp_ptr);
2027
2028 /* get the service check return code */
2029 if((temp_ptr = my_strtok(NULL, ";")) == NULL) {
2030 my_free(host_name);
2031 my_free(svc_description);
2032 return ERROR;
2033 }
2034 return_code = atoi(temp_ptr);
2035
2036 /* get the plugin output (may be empty) */
2037 if((temp_ptr = my_strtok(NULL, "\n")) == NULL)
2038 output = (char *)strdup("");
2039 else
2040 output = (char *)strdup(temp_ptr);
2041
2042 /* submit the passive check result */
2043 result = process_passive_service_check(check_time, host_name, svc_description, return_code, output);
2044
2045 /* free memory */
2046 my_free(host_name);
2047 my_free(svc_description);
2048 my_free(output);
2049
2050 return result;
2051 }
2052
2053
2054
2055 /* submits a passive service check result for later processing */
process_passive_service_check(time_t check_time,char * host_name,char * svc_description,int return_code,char * output)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;
2061 struct timeval tv;
2062 int result = OK;
2063
2064 /* skip this service check result if we aren't accepting passive service checks */
2065 if(accept_passive_service_checks == FALSE)
2066 return ERROR;
2067
2068 /* make sure we have all required data */
2069 if(host_name == NULL || svc_description == NULL || output == NULL)
2070 return ERROR;
2071
2072 /* find the host by its name or address */
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;
2079 break;
2080 }
2081 }
2082 }
2083
2084 /* we couldn't find the host */
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);
2087 return ERROR;
2088 }
2089
2090 /* make sure the service exists */
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);
2093 return ERROR;
2094 }
2095
2096 /* skip this is we aren't accepting passive checks for this service */
2097 if(temp_service->accept_passive_service_checks == FALSE)
2098 return ERROR;
2099
2100 /* allocate memory for the passive check result */
2101 new_pcr = (passive_check_result *)malloc(sizeof(passive_check_result));
2102 if(new_pcr == NULL)
2103 return ERROR;
2104
2105 /* initialize vars */
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;
2111
2112 /* save string vars */
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;
2119
2120 /* handle errors */
2121 if(result == ERROR) {
2122 my_free(new_pcr->output);
2123 my_free(new_pcr->service_description);
2124 my_free(new_pcr->host_name);
2125 my_free(new_pcr);
2126 return ERROR;
2127 }
2128
2129 /* save the return code */
2130 new_pcr->return_code = return_code;
2131
2132 /* make sure the return code is within bounds */
2133 if(new_pcr->return_code < 0 || new_pcr->return_code > 3)
2134 new_pcr->return_code = STATE_UNKNOWN;
2135
2136 new_pcr->check_time = check_time;
2137
2138 /* calculate latency */
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;
2143
2144 /* add the passive check result to the end of the list in memory */
2145 if(passive_check_result_list == NULL)
2146 passive_check_result_list = new_pcr;
2147 else
2148 passive_check_result_list_tail->next = new_pcr;
2149 passive_check_result_list_tail = new_pcr;
2150
2151 return OK;
2152 }
2153
2154
2155
2156 /* process passive host check result */
cmd_process_host_check_result(int cmd,time_t check_time,char * args)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;
2163
2164 /* get the host name */
2165 if((temp_ptr = my_strtok(args, ";")) == NULL)
2166 return ERROR;
2167 host_name = (char *)strdup(temp_ptr);
2168
2169 /* get the host check return code */
2170 if((temp_ptr = my_strtok(NULL, ";")) == NULL) {
2171 my_free(host_name);
2172 return ERROR;
2173 }
2174 return_code = atoi(temp_ptr);
2175
2176 /* get the plugin output (may be empty) */
2177 if((temp_ptr = my_strtok(NULL, "\n")) == NULL)
2178 output = (char *)strdup("");
2179 else
2180 output = (char *)strdup(temp_ptr);
2181
2182 /* submit the check result */
2183 result = process_passive_host_check(check_time, host_name, return_code, output);
2184
2185 /* free memory */
2186 my_free(host_name);
2187 my_free(output);
2188
2189 return result;
2190 }
2191
2192
2193 /* process passive host check result */
process_passive_host_check(time_t check_time,char * host_name,int return_code,char * output)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;
2198 struct timeval tv;
2199 int result = OK;
2200
2201 /* skip this host check result if we aren't accepting passive host checks */
2202 if(accept_passive_service_checks == FALSE)
2203 return ERROR;
2204
2205 /* make sure we have all required data */
2206 if(host_name == NULL || output == NULL)
2207 return ERROR;
2208
2209 /* make sure we have a reasonable return code */
2210 if(return_code < 0 || return_code > 2)
2211 return ERROR;
2212
2213 /* find the host by its name or address */
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;
2220 break;
2221 }
2222 }
2223 }
2224
2225 /* we couldn't find the host */
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);
2228 return ERROR;
2229 }
2230
2231 /* skip this is we aren't accepting passive checks for this host */
2232 if(temp_host->accept_passive_host_checks == FALSE)
2233 return ERROR;
2234
2235 /* allocate memory for the passive check result */
2236 new_pcr = (passive_check_result *)malloc(sizeof(passive_check_result));
2237 if(new_pcr == NULL)
2238 return ERROR;
2239
2240 /* initialize vars */
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;
2246
2247 /* save string vars */
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;
2252
2253 /* handle errors */
2254 if(result == ERROR) {
2255 my_free(new_pcr->output);
2256 my_free(new_pcr->service_description);
2257 my_free(new_pcr->host_name);
2258 my_free(new_pcr);
2259 return ERROR;
2260 }
2261
2262 /* save the return code */
2263 new_pcr->return_code = return_code;
2264
2265 /* make sure the return code is within bounds */
2266 if(new_pcr->return_code < 0 || new_pcr->return_code > 3)
2267 new_pcr->return_code = STATE_UNKNOWN;
2268
2269 new_pcr->check_time = check_time;
2270
2271 /* calculate latency */
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;
2276
2277 /* add the passive check result to the end of the list in memory */
2278 if(passive_check_result_list == NULL)
2279 passive_check_result_list = new_pcr;
2280 else
2281 passive_check_result_list_tail->next = new_pcr;
2282 passive_check_result_list_tail = new_pcr;
2283
2284 return OK;
2285 }
2286
2287
2288
2289 /* acknowledges a host or service problem */
cmd_acknowledge_problem(int cmd,char * args)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;
2301
2302 /* get the host name */
2303 if((host_name = my_strtok(args, ";")) == NULL)
2304 return ERROR;
2305
2306 /* verify that the host is valid */
2307 if((temp_host = find_host(host_name)) == NULL)
2308 return ERROR;
2309
2310 /* this is a service acknowledgement */
2311 if(cmd == CMD_ACKNOWLEDGE_SVC_PROBLEM) {
2312
2313 /* get the service name */
2314 if((svc_description = my_strtok(NULL, ";")) == NULL)
2315 return ERROR;
2316
2317 /* verify that the service is valid */
2318 if((temp_service = find_service(temp_host->name, svc_description)) == NULL)
2319 return ERROR;
2320 }
2321
2322 /* get the type */
2323 if((temp_ptr = my_strtok(NULL, ";")) == NULL)
2324 return ERROR;
2325 type = atoi(temp_ptr);
2326
2327 /* get the notification option */
2328 if((temp_ptr = my_strtok(NULL, ";")) == NULL)
2329 return ERROR;
2330 notify = (atoi(temp_ptr) > 0) ? TRUE : FALSE;
2331
2332 /* get the persistent option */
2333 if((temp_ptr = my_strtok(NULL, ";")) == NULL)
2334 return ERROR;
2335 persistent = (atoi(temp_ptr) > 0) ? TRUE : FALSE;
2336
2337 /* get the acknowledgement author */
2338 if((temp_ptr = my_strtok(NULL, ";")) == NULL)
2339 return ERROR;
2340 ack_author = (char *)strdup(temp_ptr);
2341
2342 /* get the acknowledgement data */
2343 if((temp_ptr = my_strtok(NULL, "\n")) == NULL) {
2344 my_free(ack_author);
2345 return ERROR;
2346 }
2347 ack_data = (char *)strdup(temp_ptr);
2348
2349 /* acknowledge the host problem */
2350 if(cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM)
2351 acknowledge_host_problem(temp_host, ack_author, ack_data, type, notify, persistent);
2352
2353 /* acknowledge the service problem */
2354 else
2355 acknowledge_service_problem(temp_service, ack_author, ack_data, type, notify, persistent);
2356
2357 /* free memory */
2358 my_free(ack_author);
2359 my_free(ack_data);
2360
2361 return OK;
2362 }
2363
2364
2365
2366 /* removes a host or service acknowledgement */
cmd_remove_acknowledgement(int cmd,char * args)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;
2372
2373 /* get the host name */
2374 if((host_name = my_strtok(args, ";")) == NULL)
2375 return ERROR;
2376
2377 /* verify that the host is valid */
2378 if((temp_host = find_host(host_name)) == NULL)
2379 return ERROR;
2380
2381 /* we are removing a service acknowledgement */
2382 if(cmd == CMD_REMOVE_SVC_ACKNOWLEDGEMENT) {
2383
2384 /* get the service name */
2385 if((svc_description = my_strtok(NULL, ";")) == NULL)
2386 return ERROR;
2387
2388 /* verify that the service is valid */
2389 if((temp_service = find_service(temp_host->name, svc_description)) == NULL)
2390 return ERROR;
2391 }
2392
2393 /* acknowledge the host problem */
2394 if(cmd == CMD_REMOVE_HOST_ACKNOWLEDGEMENT)
2395 remove_host_acknowledgement(temp_host);
2396
2397 /* acknowledge the service problem */
2398 else
2399 remove_service_acknowledgement(temp_service);
2400
2401 return OK;
2402 }
2403
2404
2405
2406 /* schedules downtime for a specific host or service */
cmd_schedule_downtime(int cmd,time_t entry_time,char * args)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
2432 /* get the hostgroup name */
2433 if((hostgroup_name = my_strtok(args, ";")) == NULL)
2434 return ERROR;
2435
2436 /* verify that the hostgroup is valid */
2437 if((temp_hostgroup = find_hostgroup(hostgroup_name)) == NULL)
2438 return ERROR;
2439 }
2440
2441 else if(cmd == CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME || cmd == CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME) {
2442
2443 /* get the servicegroup name */
2444 if((servicegroup_name = my_strtok(args, ";")) == NULL)
2445 return ERROR;
2446
2447 /* verify that the servicegroup is valid */
2448 if((temp_servicegroup = find_servicegroup(servicegroup_name)) == NULL)
2449 return ERROR;
2450 }
2451
2452 else {
2453
2454 /* get the host name */
2455 if((host_name = my_strtok(args, ";")) == NULL)
2456 return ERROR;
2457
2458 /* verify that the host is valid */
2459 if((temp_host = find_host(host_name)) == NULL)
2460 return ERROR;
2461
2462 /* this is a service downtime */
2463 if(cmd == CMD_SCHEDULE_SVC_DOWNTIME) {
2464
2465 /* get the service name */
2466 if((svc_description = my_strtok(NULL, ";")) == NULL)
2467 return ERROR;
2468
2469 /* verify that the service is valid */
2470 if((temp_service = find_service(temp_host->name, svc_description)) == NULL)
2471 return ERROR;
2472 }
2473 }
2474
2475 /* get the start time */
2476 if((temp_ptr = my_strtok(NULL, ";")) == NULL)
2477 return ERROR;
2478 start_time = (time_t)strtoul(temp_ptr, NULL, 10);
2479
2480 /* get the end time */
2481 if((temp_ptr = my_strtok(NULL, ";")) == NULL)
2482 return ERROR;
2483 end_time = (time_t)strtoul(temp_ptr, NULL, 10);
2484
2485 /* get the fixed flag */
2486 if((temp_ptr = my_strtok(NULL, ";")) == NULL)
2487 return ERROR;
2488 fixed = atoi(temp_ptr);
2489
2490 /* get the trigger id */
2491 if((temp_ptr = my_strtok(NULL, ";")) == NULL)
2492 return ERROR;
2493 triggered_by = strtoul(temp_ptr, NULL, 10);
2494
2495 /* get the duration */
2496 if((temp_ptr = my_strtok(NULL, ";")) == NULL)
2497 return ERROR;
2498 duration = strtoul(temp_ptr, NULL, 10);
2499
2500 /* get the author */
2501 if((author = my_strtok(NULL, ";")) == NULL)
2502 return ERROR;
2503
2504 /* get the comment */
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
2518
2519 /* duration should be auto-calculated, not user-specified */
2520 if(fixed > 0)
2521 duration = (unsigned long)(end_time - start_time);
2522
2523 /* schedule downtime */
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 }
2598
2599 return OK;
2600 }
2601
2602
2603
2604 /* deletes scheduled host or service downtime */
cmd_delete_downtime(int cmd,char * args)2605 int cmd_delete_downtime(int cmd, char *args) {
2606 unsigned long downtime_id = 0L;
2607 char *temp_ptr = NULL;
2608
2609 /* get the id of the downtime to delete */
2610 if((temp_ptr = my_strtok(args, "\n")) == NULL)
2611 return ERROR;
2612 downtime_id = strtoul(temp_ptr, NULL, 10);
2613
2614 if(cmd == CMD_DEL_HOST_DOWNTIME)
2615 unschedule_downtime(HOST_DOWNTIME, downtime_id);
2616 else
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 */
cmd_delete_downtime_by_host_name(int cmd,char * args)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 */
cmd_delete_downtime_by_hostgroup_name(int cmd,char * args)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 */
cmd_delete_downtime_by_start_time_comment(int cmd,char * args)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
2787 /* changes a host or service (integer) variable */
cmd_change_object_int_var(int cmd,char * args)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 }
2858
2859 /* get the value */
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 }
2988
2989
2990 /* send data to event broker and update status file */
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
3034 case CMD_CHANGE_CONTACT_MODATTR:
3035 case CMD_CHANGE_CONTACT_MODHATTR:
3036 case CMD_CHANGE_CONTACT_MODSATTR:
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);
3060 break;
3061
3062 default:
3063 break;
3064 }
3065
3066 return OK;
3067 }
3068
3069
3070
3071 /* changes a host or service (char) variable */
cmd_change_object_char_var(int cmd,char * args)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
3089 /* SECURITY PATCH - disable these for the time being */
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;
3098 }
3099
3100
3101 /* get the command arguments */
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)
3177 return ERROR;
3178
3179
3180 /* do some validation */
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 }
3221
3222
3223 /* update the variable */
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 }
3325
3326
3327 /* send data to event broker and update status file */
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 }
3414
3415 return OK;
3416 }
3417
3418
3419
3420 /* changes a custom host or service variable */
cmd_change_object_custom_var(int cmd,char * args)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;
3432
3433 /* get the host or contact name */
3434 if((temp_ptr = my_strtok(args, ";")) == NULL)
3435 return ERROR;
3436 if((name1 = (char *)strdup(temp_ptr)) == NULL)
3437 return ERROR;
3438
3439 /* get the service description if necessary */
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 }
3450
3451 /* get the custom variable name */
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 }
3462
3463 /* get the custom variable value */
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 }
3476
3477 /* find the object */
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 }
3497
3498 /* capitalize the custom variable name */
3499 for(x = 0; varname[x] != '\x0'; x++)
3500 varname[x] = toupper(varname[x]);
3501
3502 /* find the proper variable */
3503 for(; temp_customvariablesmember != NULL; temp_customvariablesmember = temp_customvariablesmember->next) {
3504
3505 /* we found the variable, so update the value */
3506 if(!strcmp(varname, temp_customvariablesmember->variable_name)) {
3507
3508 /* update the value */
3509 if(temp_customvariablesmember->variable_value)
3510 my_free(temp_customvariablesmember->variable_value);
3511 temp_customvariablesmember->variable_value = (char *)strdup(varvalue);
3512
3513 /* mark the variable value as having been changed */
3514 temp_customvariablesmember->has_been_modified = TRUE;
3515
3516 break;
3517 }
3518 }
3519
3520 /* free memory */
3521 my_free(name1);
3522 my_free(name2);
3523 my_free(varname);
3524 my_free(varvalue);
3525
3526 /* set the modified attributes and update the status of the object */
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 }
3543
3544 return OK;
3545 }
3546
3547
3548 /* processes an external host command */
cmd_process_external_commands_from_file(int cmd,char * args)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;
3553
3554 /* get the file name */
3555 if((temp_ptr = my_strtok(args, ";")) == NULL)
3556 return ERROR;
3557 if((fname = (char *)strdup(temp_ptr)) == NULL)
3558 return ERROR;
3559
3560 /* find the deletion option */
3561 if((temp_ptr = my_strtok(NULL, "\n")) == NULL) {
3562 my_free(fname);
3563 return ERROR;
3564 }
3565 if(atoi(temp_ptr) == 0)
3566 delete_file = FALSE;
3567 else
3568 delete_file = TRUE;
3569
3570 /* process the file */
3571 process_external_commands_from_file(fname, delete_file);
3572
3573 /* free memory */
3574 my_free(fname);
3575
3576 return OK;
3577 }
3578
3579
3580 /******************************************************************/
3581 /*************** INTERNAL COMMAND IMPLEMENTATIONS ****************/
3582 /******************************************************************/
3583
3584 /* temporarily disables a service check */
disable_service_checks(service * svc)3585 void disable_service_checks(service *svc) {
3586 unsigned long attr = MODATTR_ACTIVE_CHECKS_ENABLED;
3587
3588 /* checks are already disabled */
3589 if(svc->checks_enabled == FALSE)
3590 return;
3591
3592 /* set the attribute modified flag */
3593 svc->modified_attributes |= attr;
3594
3595 /* disable the service check... */
3596 svc->checks_enabled = FALSE;
3597 svc->should_be_scheduled = FALSE;
3598
3599 #ifdef USE_EVENT_BROKER
3600 /* send data to event broker */
3601 broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
3602 #endif
3603
3604 /* update the status log to reflect the new service state */
3605 update_service_status(svc, FALSE);
3606
3607 return;
3608 }
3609
3610
3611
3612 /* enables a service check */
enable_service_checks(service * svc)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;
3617
3618 /* checks are already enabled */
3619 if(svc->checks_enabled == TRUE)
3620 return;
3621
3622 /* set the attribute modified flag */
3623 svc->modified_attributes |= attr;
3624
3625 /* enable the service check... */
3626 svc->checks_enabled = TRUE;
3627 svc->should_be_scheduled = TRUE;
3628
3629 /* services with no check intervals don't get checked */
3630 if(svc->check_interval == 0)
3631 svc->should_be_scheduled = FALSE;
3632
3633 /* schedule a check for right now (or as soon as possible) */
3634 time(&preferred_time);
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 }
3639 else
3640 svc->next_check = preferred_time;
3641
3642 /* schedule a check if we should */
3643 if(svc->should_be_scheduled == TRUE)
3644 schedule_service_check(svc, svc->next_check, CHECK_OPTION_NONE);
3645
3646 #ifdef USE_EVENT_BROKER
3647 /* send data to event broker */
3648 broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
3649 #endif
3650
3651 /* update the status log to reflect the new service state */
3652 update_service_status(svc, FALSE);
3653
3654 return;
3655 }
3656
3657
3658
3659 /* enable notifications on a program-wide basis */
enable_all_notifications(void)3660 void enable_all_notifications(void) {
3661 unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3662
3663 /* bail out if we're already set... */
3664 if(enable_notifications == TRUE)
3665 return;
3666
3667 /* set the attribute modified flag */
3668 modified_host_process_attributes |= attr;
3669 modified_service_process_attributes |= attr;
3670
3671 /* update notification status */
3672 enable_notifications = TRUE;
3673
3674 #ifdef USE_EVENT_BROKER
3675 /* send data to event broker */
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);
3677 #endif
3678
3679 /* update the status log */
3680 update_program_status(FALSE);
3681
3682 return;
3683 }
3684
3685
3686 /* disable notifications on a program-wide basis */
disable_all_notifications(void)3687 void disable_all_notifications(void) {
3688 unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3689
3690 /* bail out if we're already set... */
3691 if(enable_notifications == FALSE)
3692 return;
3693
3694 /* set the attribute modified flag */
3695 modified_host_process_attributes |= attr;
3696 modified_service_process_attributes |= attr;
3697
3698 /* update notification status */
3699 enable_notifications = FALSE;
3700
3701 #ifdef USE_EVENT_BROKER
3702 /* send data to event broker */
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);
3704 #endif
3705
3706 /* update the status log */
3707 update_program_status(FALSE);
3708
3709 return;
3710 }
3711
3712
3713 /* enables notifications for a service */
enable_service_notifications(service * svc)3714 void enable_service_notifications(service *svc) {
3715 unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3716
3717 /* no change */
3718 if(svc->notifications_enabled == TRUE)
3719 return;
3720
3721 /* set the attribute modified flag */
3722 svc->modified_attributes |= attr;
3723
3724 /* enable the service notifications... */
3725 svc->notifications_enabled = TRUE;
3726
3727 #ifdef USE_EVENT_BROKER
3728 /* send data to event broker */
3729 broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
3730 #endif
3731
3732 /* update the status log to reflect the new service state */
3733 update_service_status(svc, FALSE);
3734
3735 return;
3736 }
3737
3738
3739 /* disables notifications for a service */
disable_service_notifications(service * svc)3740 void disable_service_notifications(service *svc) {
3741 unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3742
3743 /* no change */
3744 if(svc->notifications_enabled == FALSE)
3745 return;
3746
3747 /* set the attribute modified flag */
3748 svc->modified_attributes |= attr;
3749
3750 /* disable the service notifications... */
3751 svc->notifications_enabled = FALSE;
3752
3753 #ifdef USE_EVENT_BROKER
3754 /* send data to event broker */
3755 broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
3756 #endif
3757
3758 /* update the status log to reflect the new service state */
3759 update_service_status(svc, FALSE);
3760
3761 return;
3762 }
3763
3764
3765 /* enables notifications for a host */
enable_host_notifications(host * hst)3766 void enable_host_notifications(host *hst) {
3767 unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3768
3769 /* no change */
3770 if(hst->notifications_enabled == TRUE)
3771 return;
3772
3773 /* set the attribute modified flag */
3774 hst->modified_attributes |= attr;
3775
3776 /* enable the host notifications... */
3777 hst->notifications_enabled = TRUE;
3778
3779 #ifdef USE_EVENT_BROKER
3780 /* send data to event broker */
3781 broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
3782 #endif
3783
3784 /* update the status log to reflect the new host state */
3785 update_host_status(hst, FALSE);
3786
3787 return;
3788 }
3789
3790
3791 /* disables notifications for a host */
disable_host_notifications(host * hst)3792 void disable_host_notifications(host *hst) {
3793 unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3794
3795 /* no change */
3796 if(hst->notifications_enabled == FALSE)
3797 return;
3798
3799 /* set the attribute modified flag */
3800 hst->modified_attributes |= attr;
3801
3802 /* disable the host notifications... */
3803 hst->notifications_enabled = FALSE;
3804
3805 #ifdef USE_EVENT_BROKER
3806 /* send data to event broker */
3807 broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
3808 #endif
3809
3810 /* update the status log to reflect the new host state */
3811 update_host_status(hst, FALSE);
3812
3813 return;
3814 }
3815
3816
3817 /* enables notifications for all hosts and services "beyond" a given host */
enable_and_propagate_notifications(host * hst,int level,int affect_top_host,int affect_hosts,int affect_services)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;
3823
3824 /* enable notification for top level host */
3825 if(affect_top_host == TRUE && level == 0)
3826 enable_host_notifications(hst);
3827
3828 /* check all child hosts... */
3829 for(temp_hostsmember = hst->child_hosts; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
3830
3831 if((child_host = temp_hostsmember->host_ptr) == NULL)
3832 continue;
3833
3834 /* recurse... */
3835 enable_and_propagate_notifications(child_host, level + 1, affect_top_host, affect_hosts, affect_services);
3836
3837 /* enable notifications for this host */
3838 if(affect_hosts == TRUE)
3839 enable_host_notifications(child_host);
3840
3841 /* enable notifications for all services on this host... */
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)
3845 continue;
3846 enable_service_notifications(temp_service);
3847 }
3848 }
3849 }
3850
3851 return;
3852 }
3853
3854
3855 /* disables notifications for all hosts and services "beyond" a given host */
disable_and_propagate_notifications(host * hst,int level,int affect_top_host,int affect_hosts,int affect_services)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;
3861
3862 if(hst == NULL)
3863 return;
3864
3865 /* disable notifications for top host */
3866 if(affect_top_host == TRUE && level == 0)
3867 disable_host_notifications(hst);
3868
3869 /* check all child hosts... */
3870 for(temp_hostsmember = hst->child_hosts; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
3871
3872 if((child_host = temp_hostsmember->host_ptr) == NULL)
3873 continue;
3874
3875 /* recurse... */
3876 disable_and_propagate_notifications(child_host, level + 1, affect_top_host, affect_hosts, affect_services);
3877
3878 /* disable notifications for this host */
3879 if(affect_hosts == TRUE)
3880 disable_host_notifications(child_host);
3881
3882 /* disable notifications for all services on this host... */
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)
3886 continue;
3887 disable_service_notifications(temp_service);
3888 }
3889 }
3890 }
3891
3892 return;
3893 }
3894
3895
3896
3897 /* enables host notifications for a contact */
enable_contact_host_notifications(contact * cntct)3898 void enable_contact_host_notifications(contact *cntct) {
3899 unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3900
3901 /* no change */
3902 if(cntct->host_notifications_enabled == TRUE)
3903 return;
3904
3905 /* set the attribute modified flag */
3906 cntct->modified_host_attributes |= attr;
3907
3908 /* enable the host notifications... */
3909 cntct->host_notifications_enabled = TRUE;
3910
3911 #ifdef USE_EVENT_BROKER
3912 /* send data to event broker */
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);
3914 #endif
3915
3916 /* update the status log to reflect the new contact state */
3917 update_contact_status(cntct, FALSE);
3918
3919 return;
3920 }
3921
3922
3923
3924 /* disables host notifications for a contact */
disable_contact_host_notifications(contact * cntct)3925 void disable_contact_host_notifications(contact *cntct) {
3926 unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3927
3928 /* no change */
3929 if(cntct->host_notifications_enabled == FALSE)
3930 return;
3931
3932 /* set the attribute modified flag */
3933 cntct->modified_host_attributes |= attr;
3934
3935 /* enable the host notifications... */
3936 cntct->host_notifications_enabled = FALSE;
3937
3938 #ifdef USE_EVENT_BROKER
3939 /* send data to event broker */
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);
3941 #endif
3942
3943 /* update the status log to reflect the new contact state */
3944 update_contact_status(cntct, FALSE);
3945
3946 return;
3947 }
3948
3949
3950
3951 /* enables service notifications for a contact */
enable_contact_service_notifications(contact * cntct)3952 void enable_contact_service_notifications(contact *cntct) {
3953 unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3954
3955 /* no change */
3956 if(cntct->service_notifications_enabled == TRUE)
3957 return;
3958
3959 /* set the attribute modified flag */
3960 cntct->modified_service_attributes |= attr;
3961
3962 /* enable the host notifications... */
3963 cntct->service_notifications_enabled = TRUE;
3964
3965 #ifdef USE_EVENT_BROKER
3966 /* send data to event broker */
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);
3968 #endif
3969
3970 /* update the status log to reflect the new contact state */
3971 update_contact_status(cntct, FALSE);
3972
3973 return;
3974 }
3975
3976
3977
3978 /* disables service notifications for a contact */
disable_contact_service_notifications(contact * cntct)3979 void disable_contact_service_notifications(contact *cntct) {
3980 unsigned long attr = MODATTR_NOTIFICATIONS_ENABLED;
3981
3982 /* no change */
3983 if(cntct->service_notifications_enabled == FALSE)
3984 return;
3985
3986 /* set the attribute modified flag */
3987 cntct->modified_service_attributes |= attr;
3988
3989 /* enable the host notifications... */
3990 cntct->service_notifications_enabled = FALSE;
3991
3992 #ifdef USE_EVENT_BROKER
3993 /* send data to event broker */
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);
3995 #endif
3996
3997 /* update the status log to reflect the new contact state */
3998 update_contact_status(cntct, FALSE);
3999
4000 return;
4001 }
4002
4003
4004
4005 /* schedules downtime for all hosts "beyond" a given host */
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)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;
4009
4010 /* check all child hosts... */
4011 for(temp_hostsmember = temp_host->child_hosts; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
4012
4013 if((child_host = temp_hostsmember->host_ptr) == NULL)
4014 continue;
4015
4016 /* recurse... */
4017 schedule_and_propagate_downtime(child_host, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration);
4018
4019 /* schedule downtime for this host */
4020 schedule_downtime(HOST_DOWNTIME, child_host->name, NULL, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, NULL);
4021 }
4022
4023 return;
4024 }
4025
4026
4027 /* acknowledges a host problem */
acknowledge_host_problem(host * hst,char * ack_author,char * ack_data,int type,int notify,int persistent)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;
4030
4031 /* cannot acknowledge a non-existent problem */
4032 if(hst->current_state == HOST_UP)
4033 return;
4034
4035 #ifdef USE_EVENT_BROKER
4036 /* send data to event broker */
4037 broker_acknowledgement_data(NEBTYPE_ACKNOWLEDGEMENT_ADD, NEBFLAG_NONE, NEBATTR_NONE, HOST_ACKNOWLEDGEMENT, (void *)hst, ack_author, ack_data, type, notify, persistent, NULL);
4038 #endif
4039
4040 /* send out an acknowledgement notification */
4041 if(notify == TRUE)
4042 host_notification(hst, NOTIFICATION_ACKNOWLEDGEMENT, ack_author, ack_data, NOTIFICATION_OPTION_NONE);
4043
4044 /* set the acknowledgement flag */
4045 hst->problem_has_been_acknowledged = TRUE;
4046
4047 /* set the acknowledgement type */
4048 hst->acknowledgement_type = (type == ACKNOWLEDGEMENT_STICKY) ? ACKNOWLEDGEMENT_STICKY : ACKNOWLEDGEMENT_NORMAL;
4049
4050 /* update the status log with the host info */
4051 update_host_status(hst, FALSE);
4052
4053 /* add a comment for the acknowledgement */
4054 time(¤t_time);
4055 add_new_host_comment(ACKNOWLEDGEMENT_COMMENT, hst->name, current_time, ack_author, ack_data, persistent, COMMENTSOURCE_INTERNAL, FALSE, (time_t)0, NULL);
4056
4057 return;
4058 }
4059
4060
4061 /* acknowledges a service problem */
acknowledge_service_problem(service * svc,char * ack_author,char * ack_data,int type,int notify,int persistent)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;
4064
4065 /* cannot acknowledge a non-existent problem */
4066 if(svc->current_state == STATE_OK)
4067 return;
4068
4069 #ifdef USE_EVENT_BROKER
4070 /* send data to event broker */
4071 broker_acknowledgement_data(NEBTYPE_ACKNOWLEDGEMENT_ADD, NEBFLAG_NONE, NEBATTR_NONE, SERVICE_ACKNOWLEDGEMENT, (void *)svc, ack_author, ack_data, type, notify, persistent, NULL);
4072 #endif
4073
4074 /* send out an acknowledgement notification */
4075 if(notify == TRUE)
4076 service_notification(svc, NOTIFICATION_ACKNOWLEDGEMENT, ack_author, ack_data, NOTIFICATION_OPTION_NONE);
4077
4078 /* set the acknowledgement flag */
4079 svc->problem_has_been_acknowledged = TRUE;
4080
4081 /* set the acknowledgement type */
4082 svc->acknowledgement_type = (type == ACKNOWLEDGEMENT_STICKY) ? ACKNOWLEDGEMENT_STICKY : ACKNOWLEDGEMENT_NORMAL;
4083
4084 /* update the status log with the service info */
4085 update_service_status(svc, FALSE);
4086
4087 /* add a comment for the acknowledgement */
4088 time(¤t_time);
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);
4090
4091 return;
4092 }
4093
4094
4095 /* removes a host acknowledgement */
remove_host_acknowledgement(host * hst)4096 void remove_host_acknowledgement(host *hst) {
4097
4098 /* set the acknowledgement flag */
4099 hst->problem_has_been_acknowledged = FALSE;
4100
4101 /* update the status log with the host info */
4102 update_host_status(hst, FALSE);
4103
4104 /* remove any non-persistant comments associated with the ack */
4105 delete_host_acknowledgement_comments(hst);
4106
4107 return;
4108 }
4109
4110
4111 /* removes a service acknowledgement */
remove_service_acknowledgement(service * svc)4112 void remove_service_acknowledgement(service *svc) {
4113
4114 /* set the acknowledgement flag */
4115 svc->problem_has_been_acknowledged = FALSE;
4116
4117 /* update the status log with the service info */
4118 update_service_status(svc, FALSE);
4119
4120 /* remove any non-persistant comments associated with the ack */
4121 delete_service_acknowledgement_comments(svc);
4122
4123 return;
4124 }
4125
4126
4127 /* starts executing service checks */
start_executing_service_checks(void)4128 void start_executing_service_checks(void) {
4129 unsigned long attr = MODATTR_ACTIVE_CHECKS_ENABLED;
4130
4131 /* bail out if we're already executing services */
4132 if(execute_service_checks == TRUE)
4133 return;
4134
4135 /* set the attribute modified flag */
4136 modified_service_process_attributes |= attr;
4137
4138 /* set the service check execution flag */
4139 execute_service_checks = TRUE;
4140
4141 #ifdef USE_EVENT_BROKER
4142 /* send data to event broker */
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);
4144 #endif
4145
4146 /* update the status log with the program info */
4147 update_program_status(FALSE);
4148
4149 return;
4150 }
4151
4152
4153
4154
4155 /* stops executing service checks */
stop_executing_service_checks(void)4156 void stop_executing_service_checks(void) {
4157 unsigned long attr = MODATTR_ACTIVE_CHECKS_ENABLED;
4158
4159 /* bail out if we're already not executing services */
4160 if(execute_service_checks == FALSE)
4161 return;
4162
4163 /* set the attribute modified flag */
4164 modified_service_process_attributes |= attr;
4165
4166 /* set the service check execution flag */
4167 execute_service_checks = FALSE;
4168
4169 #ifdef USE_EVENT_BROKER
4170 /* send data to event broker */
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);
4172 #endif
4173
4174 /* update the status log with the program info */
4175 update_program_status(FALSE);
4176
4177 return;
4178 }
4179
4180
4181
4182 /* starts accepting passive service checks */
start_accepting_passive_service_checks(void)4183 void start_accepting_passive_service_checks(void) {
4184 unsigned long attr = MODATTR_PASSIVE_CHECKS_ENABLED;
4185
4186 /* bail out if we're already accepting passive services */
4187 if(accept_passive_service_checks == TRUE)
4188 return;
4189
4190 /* set the attribute modified flag */
4191 modified_service_process_attributes |= attr;
4192
4193 /* set the service check flag */
4194 accept_passive_service_checks = TRUE;
4195
4196 #ifdef USE_EVENT_BROKER
4197 /* send data to event broker */
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);
4199 #endif
4200
4201 /* update the status log with the program info */
4202 update_program_status(FALSE);
4203
4204 return;
4205 }
4206
4207
4208
4209 /* stops accepting passive service checks */
stop_accepting_passive_service_checks(void)4210 void stop_accepting_passive_service_checks(void) {
4211 unsigned long attr = MODATTR_PASSIVE_CHECKS_ENABLED;
4212
4213 /* bail out if we're already not accepting passive services */
4214 if(accept_passive_service_checks == FALSE)
4215 return;
4216
4217 /* set the attribute modified flag */
4218 modified_service_process_attributes |= attr;
4219
4220 /* set the service check flag */
4221 accept_passive_service_checks = FALSE;
4222
4223 #ifdef USE_EVENT_BROKER
4224 /* send data to event broker */
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);
4226 #endif
4227
4228 /* update the status log with the program info */
4229 update_program_status(FALSE);
4230
4231 return;
4232 }
4233
4234
4235
4236 /* enables passive service checks for a particular service */
enable_passive_service_checks(service * svc)4237 void enable_passive_service_checks(service *svc) {
4238 unsigned long attr = MODATTR_PASSIVE_CHECKS_ENABLED;
4239
4240 /* no change */
4241 if(svc->accept_passive_service_checks == TRUE)
4242 return;
4243
4244 /* set the attribute modified flag */
4245 svc->modified_attributes |= attr;
4246
4247 /* set the passive check flag */
4248 svc->accept_passive_service_checks = TRUE;
4249
4250 #ifdef USE_EVENT_BROKER
4251 /* send data to event broker */
4252 broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
4253 #endif
4254
4255 /* update the status log with the service info */
4256 update_service_status(svc, FALSE);
4257
4258 return;
4259 }
4260
4261
4262
4263 /* disables passive service checks for a particular service */
disable_passive_service_checks(service * svc)4264 void disable_passive_service_checks(service *svc) {
4265 unsigned long attr = MODATTR_PASSIVE_CHECKS_ENABLED;
4266
4267 /* no change */
4268 if(svc->accept_passive_service_checks == FALSE)
4269 return;
4270
4271 /* set the attribute modified flag */
4272 svc->modified_attributes |= attr;
4273
4274 /* set the passive check flag */
4275 svc->accept_passive_service_checks = FALSE;
4276
4277 #ifdef USE_EVENT_BROKER
4278 /* send data to event broker */
4279 broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
4280 #endif
4281
4282 /* update the status log with the service info */
4283 update_service_status(svc, FALSE);
4284
4285 return;
4286 }
4287
4288
4289
4290 /* starts executing host checks */
start_executing_host_checks(void)4291 void start_executing_host_checks(void) {
4292 unsigned long attr = MODATTR_ACTIVE_CHECKS_ENABLED;
4293
4294 /* bail out if we're already executing hosts */
4295 if(execute_host_checks == TRUE)
4296 return;
4297
4298 /* set the attribute modified flag */
4299 modified_host_process_attributes |= attr;
4300
4301 /* set the host check execution flag */
4302 execute_host_checks = TRUE;
4303
4304 #ifdef USE_EVENT_BROKER
4305 /* send data to event broker */
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);
4307 #endif
4308
4309 /* update the status log with the program info */
4310 update_program_status(FALSE);
4311
4312 return;
4313 }
4314
4315
4316
4317
4318 /* stops executing host checks */
stop_executing_host_checks(void)4319 void stop_executing_host_checks(void) {
4320 unsigned long attr = MODATTR_ACTIVE_CHECKS_ENABLED;
4321
4322 /* bail out if we're already not executing hosts */
4323 if(execute_host_checks == FALSE)
4324 return;
4325
4326 /* set the attribute modified flag */
4327 modified_host_process_attributes |= attr;
4328
4329 /* set the host check execution flag */
4330 execute_host_checks = FALSE;
4331
4332 #ifdef USE_EVENT_BROKER
4333 /* send data to event broker */
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);
4335 #endif
4336
4337 /* update the status log with the program info */
4338 update_program_status(FALSE);
4339
4340 return;
4341 }
4342
4343
4344
4345 /* starts accepting passive host checks */
start_accepting_passive_host_checks(void)4346 void start_accepting_passive_host_checks(void) {
4347 unsigned long attr = MODATTR_PASSIVE_CHECKS_ENABLED;
4348
4349 /* bail out if we're already accepting passive hosts */
4350 if(accept_passive_host_checks == TRUE)
4351 return;
4352
4353 /* set the attribute modified flag */
4354 modified_host_process_attributes |= attr;
4355
4356 /* set the host check flag */
4357 accept_passive_host_checks = TRUE;
4358
4359 #ifdef USE_EVENT_BROKER
4360 /* send data to event broker */
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);
4362 #endif
4363
4364 /* update the status log with the program info */
4365 update_program_status(FALSE);
4366
4367 return;
4368 }
4369
4370
4371
4372 /* stops accepting passive host checks */
stop_accepting_passive_host_checks(void)4373 void stop_accepting_passive_host_checks(void) {
4374 unsigned long attr = MODATTR_PASSIVE_CHECKS_ENABLED;
4375
4376 /* bail out if we're already not accepting passive hosts */
4377 if(accept_passive_host_checks == FALSE)
4378 return;
4379
4380 /* set the attribute modified flag */
4381 modified_host_process_attributes |= attr;
4382
4383 /* set the host check flag */
4384 accept_passive_host_checks = FALSE;
4385
4386 #ifdef USE_EVENT_BROKER
4387 /* send data to event broker */
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);
4389 #endif
4390
4391 /* update the status log with the program info */
4392 update_program_status(FALSE);
4393
4394 return;
4395 }
4396
4397
4398
4399 /* enables passive host checks for a particular host */
enable_passive_host_checks(host * hst)4400 void enable_passive_host_checks(host *hst) {
4401 unsigned long attr = MODATTR_PASSIVE_CHECKS_ENABLED;
4402
4403 /* no change */
4404 if(hst->accept_passive_host_checks == TRUE)
4405 return;
4406
4407 /* set the attribute modified flag */
4408 hst->modified_attributes |= attr;
4409
4410 /* set the passive check flag */
4411 hst->accept_passive_host_checks = TRUE;
4412
4413 #ifdef USE_EVENT_BROKER
4414 /* send data to event broker */
4415 broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
4416 #endif
4417
4418 /* update the status log with the host info */
4419 update_host_status(hst, FALSE);
4420
4421 return;
4422 }
4423
4424
4425
4426 /* disables passive host checks for a particular host */
disable_passive_host_checks(host * hst)4427 void disable_passive_host_checks(host *hst) {
4428 unsigned long attr = MODATTR_PASSIVE_CHECKS_ENABLED;
4429
4430 /* no change */
4431 if(hst->accept_passive_host_checks == FALSE)
4432 return;
4433
4434 /* set the attribute modified flag */
4435 hst->modified_attributes |= attr;
4436
4437 /* set the passive check flag */
4438 hst->accept_passive_host_checks = FALSE;
4439
4440 #ifdef USE_EVENT_BROKER
4441 /* send data to event broker */
4442 broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
4443 #endif
4444
4445 /* update the status log with the host info */
4446 update_host_status(hst, FALSE);
4447
4448 return;
4449 }
4450
4451
4452 /* enables event handlers on a program-wide basis */
start_using_event_handlers(void)4453 void start_using_event_handlers(void) {
4454 unsigned long attr = MODATTR_EVENT_HANDLER_ENABLED;
4455
4456 /* no change */
4457 if(enable_event_handlers == TRUE)
4458 return;
4459
4460 /* set the attribute modified flag */
4461 modified_host_process_attributes |= attr;
4462 modified_service_process_attributes |= attr;
4463
4464 /* set the event handler flag */
4465 enable_event_handlers = TRUE;
4466
4467 #ifdef USE_EVENT_BROKER
4468 /* send data to event broker */
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);
4470 #endif
4471
4472 /* update the status log with the program info */
4473 update_program_status(FALSE);
4474
4475 return;
4476 }
4477
4478
4479 /* disables event handlers on a program-wide basis */
stop_using_event_handlers(void)4480 void stop_using_event_handlers(void) {
4481 unsigned long attr = MODATTR_EVENT_HANDLER_ENABLED;
4482
4483 /* no change */
4484 if(enable_event_handlers == FALSE)
4485 return;
4486
4487 /* set the attribute modified flag */
4488 modified_host_process_attributes |= attr;
4489 modified_service_process_attributes |= attr;
4490
4491 /* set the event handler flag */
4492 enable_event_handlers = FALSE;
4493
4494 #ifdef USE_EVENT_BROKER
4495 /* send data to event broker */
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);
4497 #endif
4498
4499 /* update the status log with the program info */
4500 update_program_status(FALSE);
4501
4502 return;
4503 }
4504
4505
4506 /* enables the event handler for a particular service */
enable_service_event_handler(service * svc)4507 void enable_service_event_handler(service *svc) {
4508 unsigned long attr = MODATTR_EVENT_HANDLER_ENABLED;
4509
4510 /* no change */
4511 if(svc->event_handler_enabled == TRUE)
4512 return;
4513
4514 /* set the attribute modified flag */
4515 svc->modified_attributes |= attr;
4516
4517 /* set the event handler flag */
4518 svc->event_handler_enabled = TRUE;
4519
4520 #ifdef USE_EVENT_BROKER
4521 /* send data to event broker */
4522 broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
4523 #endif
4524
4525 /* update the status log with the service info */
4526 update_service_status(svc, FALSE);
4527
4528 return;
4529 }
4530
4531
4532
4533 /* disables the event handler for a particular service */
disable_service_event_handler(service * svc)4534 void disable_service_event_handler(service *svc) {
4535 unsigned long attr = MODATTR_EVENT_HANDLER_ENABLED;
4536
4537 /* no change */
4538 if(svc->event_handler_enabled == FALSE)
4539 return;
4540
4541 /* set the attribute modified flag */
4542 svc->modified_attributes |= attr;
4543
4544 /* set the event handler flag */
4545 svc->event_handler_enabled = FALSE;
4546
4547 #ifdef USE_EVENT_BROKER
4548 /* send data to event broker */
4549 broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
4550 #endif
4551
4552 /* update the status log with the service info */
4553 update_service_status(svc, FALSE);
4554
4555 return;
4556 }
4557
4558
4559 /* enables the event handler for a particular host */
enable_host_event_handler(host * hst)4560 void enable_host_event_handler(host *hst) {
4561 unsigned long attr = MODATTR_EVENT_HANDLER_ENABLED;
4562
4563 /* no change */
4564 if(hst->event_handler_enabled == TRUE)
4565 return;
4566
4567 /* set the attribute modified flag */
4568 hst->modified_attributes |= attr;
4569
4570 /* set the event handler flag */
4571 hst->event_handler_enabled = TRUE;
4572
4573 #ifdef USE_EVENT_BROKER
4574 /* send data to event broker */
4575 broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
4576 #endif
4577
4578 /* update the status log with the host info */
4579 update_host_status(hst, FALSE);
4580
4581 return;
4582 }
4583
4584
4585 /* disables the event handler for a particular host */
disable_host_event_handler(host * hst)4586 void disable_host_event_handler(host *hst) {
4587 unsigned long attr = MODATTR_EVENT_HANDLER_ENABLED;
4588
4589 /* no change */
4590 if(hst->event_handler_enabled == FALSE)
4591 return;
4592
4593 /* set the attribute modified flag */
4594 hst->modified_attributes |= attr;
4595
4596 /* set the event handler flag */
4597 hst->event_handler_enabled = FALSE;
4598
4599 #ifdef USE_EVENT_BROKER
4600 /* send data to event broker */
4601 broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
4602 #endif
4603
4604 /* update the status log with the host info */
4605 update_host_status(hst, FALSE);
4606
4607 return;
4608 }
4609
4610
4611 /* disables checks of a particular host */
disable_host_checks(host * hst)4612 void disable_host_checks(host *hst) {
4613 unsigned long attr = MODATTR_ACTIVE_CHECKS_ENABLED;
4614
4615 /* checks are already disabled */
4616 if(hst->checks_enabled == FALSE)
4617 return;
4618
4619 /* set the attribute modified flag */
4620 hst->modified_attributes |= attr;
4621
4622 /* set the host check flag */
4623 hst->checks_enabled = FALSE;
4624 hst->should_be_scheduled = FALSE;
4625
4626 #ifdef USE_EVENT_BROKER
4627 /* send data to event broker */
4628 broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
4629 #endif
4630
4631 /* update the status log with the host info */
4632 update_host_status(hst, FALSE);
4633
4634 return;
4635 }
4636
4637
4638 /* enables checks of a particular host */
enable_host_checks(host * hst)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;
4643
4644 /* checks are already enabled */
4645 if(hst->checks_enabled == TRUE)
4646 return;
4647
4648 /* set the attribute modified flag */
4649 hst->modified_attributes |= attr;
4650
4651 /* set the host check flag */
4652 hst->checks_enabled = TRUE;
4653 hst->should_be_scheduled = TRUE;
4654
4655 /* hosts with no check intervals don't get checked */
4656 if(hst->check_interval == 0)
4657 hst->should_be_scheduled = FALSE;
4658
4659 /* schedule a check for right now (or as soon as possible) */
4660 time(&preferred_time);
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 }
4665 else
4666 hst->next_check = preferred_time;
4667
4668 /* schedule a check if we should */
4669 if(hst->should_be_scheduled == TRUE)
4670 schedule_host_check(hst, hst->next_check, CHECK_OPTION_NONE);
4671
4672 #ifdef USE_EVENT_BROKER
4673 /* send data to event broker */
4674 broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
4675 #endif
4676
4677 /* update the status log with the host info */
4678 update_host_status(hst, FALSE);
4679
4680 return;
4681 }
4682
4683
4684
4685 /* start obsessing over service check results */
start_obsessing_over_service_checks(void)4686 void start_obsessing_over_service_checks(void) {
4687 unsigned long attr = MODATTR_OBSESSIVE_HANDLER_ENABLED;
4688
4689 /* no change */
4690 if(obsess_over_services == TRUE)
4691 return;
4692
4693 /* set the attribute modified flag */
4694 modified_service_process_attributes |= attr;
4695
4696 /* set the service obsession flag */
4697 obsess_over_services = TRUE;
4698
4699 #ifdef USE_EVENT_BROKER
4700 /* send data to event broker */
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);
4702 #endif
4703
4704 /* update the status log with the program info */
4705 update_program_status(FALSE);
4706
4707 return;
4708 }
4709
4710
4711
4712 /* stop obsessing over service check results */
stop_obsessing_over_service_checks(void)4713 void stop_obsessing_over_service_checks(void) {
4714 unsigned long attr = MODATTR_OBSESSIVE_HANDLER_ENABLED;
4715
4716 /* no change */
4717 if(obsess_over_services == FALSE)
4718 return;
4719
4720 /* set the attribute modified flag */
4721 modified_service_process_attributes |= attr;
4722
4723 /* set the service obsession flag */
4724 obsess_over_services = FALSE;
4725
4726 #ifdef USE_EVENT_BROKER
4727 /* send data to event broker */
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);
4729 #endif
4730
4731 /* update the status log with the program info */
4732 update_program_status(FALSE);
4733
4734 return;
4735 }
4736
4737
4738
4739 /* start obsessing over host check results */
start_obsessing_over_host_checks(void)4740 void start_obsessing_over_host_checks(void) {
4741 unsigned long attr = MODATTR_OBSESSIVE_HANDLER_ENABLED;
4742
4743 /* no change */
4744 if(obsess_over_hosts == TRUE)
4745 return;
4746
4747 /* set the attribute modified flag */
4748 modified_host_process_attributes |= attr;
4749
4750 /* set the host obsession flag */
4751 obsess_over_hosts = TRUE;
4752
4753 #ifdef USE_EVENT_BROKER
4754 /* send data to event broker */
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);
4756 #endif
4757
4758 /* update the status log with the program info */
4759 update_program_status(FALSE);
4760
4761 return;
4762 }
4763
4764
4765
4766 /* stop obsessing over host check results */
stop_obsessing_over_host_checks(void)4767 void stop_obsessing_over_host_checks(void) {
4768 unsigned long attr = MODATTR_OBSESSIVE_HANDLER_ENABLED;
4769
4770 /* no change */
4771 if(obsess_over_hosts == FALSE)
4772 return;
4773
4774 /* set the attribute modified flag */
4775 modified_host_process_attributes |= attr;
4776
4777 /* set the host obsession flag */
4778 obsess_over_hosts = FALSE;
4779
4780 #ifdef USE_EVENT_BROKER
4781 /* send data to event broker */
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);
4783 #endif
4784
4785 /* update the status log with the program info */
4786 update_program_status(FALSE);
4787
4788 return;
4789 }
4790
4791
4792
4793 /* enables service freshness checking */
enable_service_freshness_checks(void)4794 void enable_service_freshness_checks(void) {
4795 unsigned long attr = MODATTR_FRESHNESS_CHECKS_ENABLED;
4796
4797 /* no change */
4798 if(check_service_freshness == TRUE)
4799 return;
4800
4801 /* set the attribute modified flag */
4802 modified_service_process_attributes |= attr;
4803
4804 /* set the freshness check flag */
4805 check_service_freshness = TRUE;
4806
4807 #ifdef USE_EVENT_BROKER
4808 /* send data to event broker */
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);
4810 #endif
4811
4812 /* update the status log with the program info */
4813 update_program_status(FALSE);
4814
4815 return;
4816 }
4817
4818
4819 /* disables service freshness checking */
disable_service_freshness_checks(void)4820 void disable_service_freshness_checks(void) {
4821 unsigned long attr = MODATTR_FRESHNESS_CHECKS_ENABLED;
4822
4823 /* no change */
4824 if(check_service_freshness == FALSE)
4825 return;
4826
4827 /* set the attribute modified flag */
4828 modified_service_process_attributes |= attr;
4829
4830 /* set the freshness check flag */
4831 check_service_freshness = FALSE;
4832
4833 #ifdef USE_EVENT_BROKER
4834 /* send data to event broker */
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);
4836 #endif
4837
4838 /* update the status log with the program info */
4839 update_program_status(FALSE);
4840
4841 return;
4842 }
4843
4844
4845 /* enables host freshness checking */
enable_host_freshness_checks(void)4846 void enable_host_freshness_checks(void) {
4847 unsigned long attr = MODATTR_FRESHNESS_CHECKS_ENABLED;
4848
4849 /* no change */
4850 if(check_host_freshness == TRUE)
4851 return;
4852
4853 /* set the attribute modified flag */
4854 modified_host_process_attributes |= attr;
4855
4856 /* set the freshness check flag */
4857 check_host_freshness = TRUE;
4858
4859 #ifdef USE_EVENT_BROKER
4860 /* send data to event broker */
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);
4862 #endif
4863
4864 /* update the status log with the program info */
4865 update_program_status(FALSE);
4866
4867 return;
4868 }
4869
4870
4871 /* disables host freshness checking */
disable_host_freshness_checks(void)4872 void disable_host_freshness_checks(void) {
4873 unsigned long attr = MODATTR_FRESHNESS_CHECKS_ENABLED;
4874
4875 /* no change */
4876 if(check_host_freshness == FALSE)
4877 return;
4878
4879 /* set the attribute modified flag */
4880 modified_host_process_attributes |= attr;
4881
4882 /* set the freshness check flag */
4883 check_host_freshness = FALSE;
4884
4885 #ifdef USE_EVENT_BROKER
4886 /* send data to event broker */
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);
4888 #endif
4889
4890 /* update the status log with the program info */
4891 update_program_status(FALSE);
4892
4893 return;
4894 }
4895
4896
4897 /* enable failure prediction on a program-wide basis */
enable_all_failure_prediction(void)4898 void enable_all_failure_prediction(void) {
4899 unsigned long attr = MODATTR_FAILURE_PREDICTION_ENABLED;
4900
4901 /* bail out if we're already set... */
4902 if(enable_failure_prediction == TRUE)
4903 return;
4904
4905 /* set the attribute modified flag */
4906 modified_host_process_attributes |= attr;
4907 modified_service_process_attributes |= attr;
4908
4909 enable_failure_prediction = TRUE;
4910
4911 #ifdef USE_EVENT_BROKER
4912 /* send data to event broker */
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);
4914 #endif
4915
4916 /* update the status log */
4917 update_program_status(FALSE);
4918
4919 return;
4920 }
4921
4922
4923 /* disable failure prediction on a program-wide basis */
disable_all_failure_prediction(void)4924 void disable_all_failure_prediction(void) {
4925 unsigned long attr = MODATTR_FAILURE_PREDICTION_ENABLED;
4926
4927 /* bail out if we're already set... */
4928 if(enable_failure_prediction == FALSE)
4929 return;
4930
4931 /* set the attribute modified flag */
4932 modified_host_process_attributes |= attr;
4933 modified_service_process_attributes |= attr;
4934
4935 enable_failure_prediction = FALSE;
4936
4937 #ifdef USE_EVENT_BROKER
4938 /* send data to event broker */
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);
4940 #endif
4941
4942 /* update the status log */
4943 update_program_status(FALSE);
4944
4945 return;
4946 }
4947
4948
4949 /* enable performance data on a program-wide basis */
enable_performance_data(void)4950 void enable_performance_data(void) {
4951 unsigned long attr = MODATTR_PERFORMANCE_DATA_ENABLED;
4952
4953 /* bail out if we're already set... */
4954 if(process_performance_data == TRUE)
4955 return;
4956
4957 /* set the attribute modified flag */
4958 modified_host_process_attributes |= attr;
4959 modified_service_process_attributes |= attr;
4960
4961 process_performance_data = TRUE;
4962
4963 #ifdef USE_EVENT_BROKER
4964 /* send data to event broker */
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);
4966 #endif
4967
4968 /* update the status log */
4969 update_program_status(FALSE);
4970
4971 return;
4972 }
4973
4974
4975 /* disable performance data on a program-wide basis */
disable_performance_data(void)4976 void disable_performance_data(void) {
4977 unsigned long attr = MODATTR_PERFORMANCE_DATA_ENABLED;
4978
4979 # /* bail out if we're already set... */
4980 if(process_performance_data == FALSE)
4981 return;
4982
4983 /* set the attribute modified flag */
4984 modified_host_process_attributes |= attr;
4985 modified_service_process_attributes |= attr;
4986
4987 process_performance_data = FALSE;
4988
4989 #ifdef USE_EVENT_BROKER
4990 /* send data to event broker */
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);
4992 #endif
4993
4994 /* update the status log */
4995 update_program_status(FALSE);
4996
4997 return;
4998 }
4999
5000
5001 /* start obsessing over a particular service */
start_obsessing_over_service(service * svc)5002 void start_obsessing_over_service(service *svc) {
5003 unsigned long attr = MODATTR_OBSESSIVE_HANDLER_ENABLED;
5004
5005 /* no change */
5006 if(svc->obsess_over_service == TRUE)
5007 return;
5008
5009 /* set the attribute modified flag */
5010 svc->modified_attributes |= attr;
5011
5012 /* set the obsess over service flag */
5013 svc->obsess_over_service = TRUE;
5014
5015 #ifdef USE_EVENT_BROKER
5016 /* send data to event broker */
5017 broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
5018 #endif
5019
5020 /* update the status log with the service info */
5021 update_service_status(svc, FALSE);
5022
5023 return;
5024 }
5025
5026
5027 /* stop obsessing over a particular service */
stop_obsessing_over_service(service * svc)5028 void stop_obsessing_over_service(service *svc) {
5029 unsigned long attr = MODATTR_OBSESSIVE_HANDLER_ENABLED;
5030
5031 /* no change */
5032 if(svc->obsess_over_service == FALSE)
5033 return;
5034
5035 /* set the attribute modified flag */
5036 svc->modified_attributes |= attr;
5037
5038 /* set the obsess over service flag */
5039 svc->obsess_over_service = FALSE;
5040
5041 #ifdef USE_EVENT_BROKER
5042 /* send data to event broker */
5043 broker_adaptive_service_data(NEBTYPE_ADAPTIVESERVICE_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, CMD_NONE, attr, svc->modified_attributes, NULL);
5044 #endif
5045
5046 /* update the status log with the service info */
5047 update_service_status(svc, FALSE);
5048
5049 return;
5050 }
5051
5052
5053 /* start obsessing over a particular host */
start_obsessing_over_host(host * hst)5054 void start_obsessing_over_host(host *hst) {
5055 unsigned long attr = MODATTR_OBSESSIVE_HANDLER_ENABLED;
5056
5057 /* no change */
5058 if(hst->obsess_over_host == TRUE)
5059 return;
5060
5061 /* set the attribute modified flag */
5062 hst->modified_attributes |= attr;
5063
5064 /* set the obsess over host flag */
5065 hst->obsess_over_host = TRUE;
5066
5067 #ifdef USE_EVENT_BROKER
5068 /* send data to event broker */
5069 broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
5070 #endif
5071
5072 /* update the status log with the host info */
5073 update_host_status(hst, FALSE);
5074
5075 return;
5076 }
5077
5078
5079 /* stop obsessing over a particular host */
stop_obsessing_over_host(host * hst)5080 void stop_obsessing_over_host(host *hst) {
5081 unsigned long attr = MODATTR_OBSESSIVE_HANDLER_ENABLED;
5082
5083 /* no change */
5084 if(hst->obsess_over_host == FALSE)
5085 return;
5086
5087 /* set the attribute modified flag */
5088 hst->modified_attributes |= attr;
5089
5090 /* set the obsess over host flag */
5091 hst->obsess_over_host = FALSE;
5092
5093 #ifdef USE_EVENT_BROKER
5094 /* send data to event broker */
5095 broker_adaptive_host_data(NEBTYPE_ADAPTIVEHOST_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, CMD_NONE, attr, hst->modified_attributes, NULL);
5096 #endif
5097
5098 /* update the status log with the host info */
5099 update_host_status(hst, FALSE);
5100
5101 return;
5102 }
5103
5104
5105 /* sets the current notification number for a specific host */
set_host_notification_number(host * hst,int num)5106 void set_host_notification_number(host *hst, int num) {
5107
5108 /* set the notification number */
5109 hst->current_notification_number = num;
5110
5111 /* update the status log with the host info */
5112 update_host_status(hst, FALSE);
5113
5114 return;
5115 }
5116
5117
5118 /* sets the current notification number for a specific service */
set_service_notification_number(service * svc,int num)5119 void set_service_notification_number(service *svc, int num) {
5120
5121 /* set the notification number */
5122 svc->current_notification_number = num;
5123
5124 /* update the status log with the service info */
5125 update_service_status(svc, FALSE);
5126
5127 return;
5128 }
5129
5130
5131
5132 /* process all passive host and service checks we found in the external command file */
process_passive_checks(void)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;
5141 mode_t old_umask;
5142 time_t current_time;
5143
5144 log_debug_info(DEBUGL_FUNCTIONS, 0, "process_passive_checks()\n");
5145
5146 /* nothing to do */
5147 if(passive_check_result_list == NULL)
5148 return;
5149
5150 log_debug_info(DEBUGL_CHECKS, 1, "Submitting passive host/service check results obtained from external commands...\n");
5151
5152 /* open a temp file for storing check result(s) */
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");
5155 my_free(checkresult_file);
5156 asprintf(&checkresult_file, "%s/checkXXXXXX", temp_path);
5157 checkresult_file_fd = mkstemp(checkresult_file);
5158 umask(old_umask);
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);
5162 return;
5163 }
5164
5165 checkresult_file_fp = fdopen(checkresult_file_fd, "w");
5166
5167 time(¤t_time);
5168 fprintf(checkresult_file_fp, "### Passive Check Result File ###\n");
5169 fprintf(checkresult_file_fp, "# Time: %s", ctime(¤t_time));
5170 fprintf(checkresult_file_fp, "file_time=%lu\n", (unsigned long)current_time);
5171 fprintf(checkresult_file_fp, "\n");
5172
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);
5174
5175 /* write all service checks to check result queue file for later processing */
5176 for(temp_pcr = passive_check_result_list; temp_pcr != NULL; temp_pcr = temp_pcr->next) {
5177
5178 /* write check results to file */
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);
5193 /* newlines in output are already escaped */
5194 fprintf(checkresult_file_fp, "output=%s\n", (temp_pcr->output == NULL) ? "" : temp_pcr->output);
5195 fprintf(checkresult_file_fp, "\n");
5196 }
5197 }
5198
5199 /* close the temp file */
5200 fclose(checkresult_file_fp);
5201
5202 /* move check result to queue directory */
5203 move_check_result_to_queue(checkresult_file);
5204
5205 /* free memory */
5206 my_free(checkresult_file);
5207
5208 /* free memory for the passive check result list */
5209 this_pcr = passive_check_result_list;
5210 while(this_pcr != NULL) {
5211 next_pcr = this_pcr->next;
5212 my_free(this_pcr->host_name);
5213 my_free(this_pcr->service_description);
5214 my_free(this_pcr->output);
5215 my_free(this_pcr);
5216 this_pcr = next_pcr;
5217 }
5218 passive_check_result_list = NULL;
5219 passive_check_result_list_tail = NULL;
5220
5221 return;
5222 }
5223
5224