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