static int
disable_notifications_for_obj(int sd, const char* obj, const char* rest)
{
  (void)rest;

  host*    hst;
  service* svc;
  nez_find_host_or_service(obj, &hst, &svc);

  if (svc) {
    disable_service_notifications(svc);
    nsock_printf_nul(sd, "NOTIFICATIONS DISABLED FOR SERVICE: %s/%s\n", svc->host_name, svc->display_name);
    return 200;
  }

  if (hst) {
    disable_host_notifications(hst);
    nsock_printf_nul(sd, "NOTIFICATIONS DISABLED FOR HOST (AND ITS SERVICES): %s\n", hst->display_name);

    for (servicesmember* svcmem = hst->services; svcmem; svcmem = svcmem->next) {
      disable_service_notifications(svcmem->service_ptr);
    }

    return 200;
  }

  nsock_printf_nul(sd, "NO HOST OR SERVICE FOUND FOR: %s", obj);
  return 404;
}
示例#2
0
static void process_cmd(json_t * payload) {
	host * host_target = NULL;
	service * service_target = NULL;
	char * host_name = NULL, *service_description = NULL, *cmd_name;

	if(get_values(payload,
		"host_name", JSON_STRING, 1, &host_name,
		"service_description", JSON_STRING, 0, &service_description,
		"command_name", JSON_STRING, 1, &cmd_name,
		NULL) != 0) {
		json_decref(payload);
		return;
	}

	if(host_name)
		host_target = find_host(host_name);
	if(host_target && service_description)
		service_target = find_service(host_name, service_description);

	if(strcmp(cmd_name, "disable_service_checks") == 0 && service_target)
		disable_service_checks(service_target);
	else if(strcmp(cmd_name, "enable_service_checks") == 0 && service_target)
		enable_service_checks(service_target);
	else if(strcmp(cmd_name, "enable_all_notifications") == 0)
		enable_all_notifications();
	else if(strcmp(cmd_name, "disable_all_notification") == 0)
		disable_all_notifications();
	else if(strcmp(cmd_name, "enable_service_notifications") == 0 && service_target)
		enable_service_notifications(service_target);
	else if(strcmp(cmd_name, "disable_service_notifications") == 0 && service_target)
		disable_service_notifications(service_target);
	else if(strcmp(cmd_name, "enable_host_notifications") == 0 && host_target)
		enable_host_notifications(host_target);
	else if(strcmp(cmd_name, "disable_host_notifications") == 0 && host_target)
		disable_host_notifications(host_target);
	else if(strcmp(cmd_name, "remove_host_acknowledgement") == 0 && host_target)
		remove_host_acknowledgement(host_target);
	else if(strcmp(cmd_name, "remove_service_acknowledgement") == 0 && service_target)
		remove_service_acknowledgement(service_target);
	else if(strcmp(cmd_name, "start_executing_service_checks") == 0)
		start_executing_service_checks();
	else if(strcmp(cmd_name, "stop_executing_service_checks") == 0)
		stop_executing_service_checks();
	else if(strcmp(cmd_name, "start_accepting_passive_service_checks") == 0)
		start_accepting_passive_service_checks();
	else if(strcmp(cmd_name, "stop_accepting_passive_service_checks") == 0)
		stop_accepting_passive_service_checks();
	else if(strcmp(cmd_name, "enable_passive_service_checks") == 0 && service_target)
		enable_passive_service_checks(service_target);
	else if(strcmp(cmd_name, "disable_passive_service_checks") == 0 && service_target)
		disable_passive_service_checks(service_target);
	else if(strcmp(cmd_name, "start_using_event_handlers") == 0)
		start_using_event_handlers();
	else if(strcmp(cmd_name, "stop_using_event_handlers") == 0)
		stop_using_event_handlers();
	else if(strcmp(cmd_name, "enable_service_event_handler") == 0 && service_target)
		enable_service_event_handler(service_target);
	else if(strcmp(cmd_name, "disable_service_event_handler") == 0 && service_target)
		disable_service_event_handler(service_target);
	else if(strcmp(cmd_name, "enable_host_event_handler") == 0 && host_target)
		enable_host_event_handler(host_target);
	else if(strcmp(cmd_name, "disable_host_event_handler") == 0 && host_target)
		disable_host_event_handler(host_target);
	else if(strcmp(cmd_name, "enable_host_checks") == 0 && host_target)
		enable_host_checks(host_target);
	else if(strcmp(cmd_name, "disable_host_checks") == 0 && host_target)
		disable_host_checks(host_target);
	else if(strcmp(cmd_name, "enable_service_freshness_checks") == 0)
		enable_service_freshness_checks();
	else if(strcmp(cmd_name, "start_obsessing_over_service") == 0 && service_target)
		start_obsessing_over_service(service_target);
	else if(strcmp(cmd_name, "stop_obsessing_over_service") == 0 && service_target)
		stop_obsessing_over_service(service_target);
	else if(strcmp(cmd_name, "start_obsessing_over_host") == 0 && host_target)
		start_obsessing_over_host(host_target);
	else if(strcmp(cmd_name, "stop_obsessing_over_host") == 0 && host_target)
		stop_obsessing_over_host(host_target);
	else if(strcmp(cmd_name, "enable_performance_data") == 0)
		enable_performance_data();
	else if(strcmp(cmd_name, "disable_performance_data") == 0)
		disable_performance_data();
	else if(strcmp(cmd_name, "start_executing_host_checks") == 0)
		start_executing_host_checks();
	else if(strcmp(cmd_name, "stop_executing_host_checks") == 0)
		stop_executing_host_checks();
	else if(strcmp(cmd_name, "start_accepting_passive_host_checks") == 0)
		start_accepting_passive_host_checks();
	else if(strcmp(cmd_name, "stop_accepting_passive_host_checks") == 0)
		stop_accepting_passive_host_checks();
	else if(strcmp(cmd_name, "enable_passive_host_checks") == 0 && host_target)
		enable_passive_host_checks(host_target);
	else if(strcmp(cmd_name, "disable_passive_host_checks") == 0 && host_target)
		disable_passive_host_checks(host_target);
	else if(strcmp(cmd_name, "enable_host_flap_detection") == 0 && host_target)
		enable_host_flap_detection(host_target);
	else if(strcmp(cmd_name, "disable_host_flap_detection") == 0 && host_target)
		disable_host_flap_detection(host_target);
	else if(strcmp(cmd_name, "enable_service_flap_detection") == 0 && service_target)
		enable_service_flap_detection(service_target);
	else if(strcmp(cmd_name, "disable_service_flap_detection") == 0 && service_target)
		disable_service_flap_detection(service_target);
	else if((strcmp(cmd_name, "schedule_host_check") == 0 && host_target) ||
		(strcmp(cmd_name, "schedule_service_check") == 0&& service_target)) {
		time_t next_check;
		int force_execution = 0, freshness_check = 0, orphan_check = 0;
		if(get_values(payload,
			"next_check", JSON_INTEGER, 1, &next_check,
			"force_execution", JSON_TRUE, 0, &force_execution,
			"freshness_check", JSON_TRUE, 0, &freshness_check,
			"orphan_check", JSON_TRUE, 0, &orphan_check,
			NULL) != 0) {
			json_decref(payload);
			return;
		}
		int flags = CHECK_OPTION_NONE;
		if(force_execution)
			flags |= CHECK_OPTION_FORCE_EXECUTION;
		if(freshness_check)
			flags |= CHECK_OPTION_FRESHNESS_CHECK;
		if(orphan_check)
			flags |= CHECK_OPTION_ORPHAN_CHECK;
		if(service_target)
			schedule_service_check(service_target, next_check, flags);
		else
			schedule_host_check(host_target, next_check, flags);
	}
	else if((strcmp(cmd_name, "disable_and_propagate_notifications") == 0||
		strcmp(cmd_name, "enable_and_propagate_notifications") == 0) &&
		host_target) {
		int affect_top_host = 0, affect_hosts = 0, affect_services = 0,
			level = 0;
		if(get_values(payload,
			"affect_top_host", JSON_TRUE, 0, &affect_top_host,
			"affect_hosts", JSON_TRUE, 0, &affect_hosts,
			"affect_services", JSON_TRUE, 0, &affect_services,
			"level", JSON_INTEGER, 0, &level,
			NULL) != 0) {
			json_decref(payload);
			return;
		}
		if(strcmp(cmd_name, "disable_and_propagate_notifications") == 0)
			disable_and_propagate_notifications(host_target, level,
				affect_top_host, affect_hosts, affect_services);
		else if(strcmp(cmd_name, "enable_and_propagate_notifications") == 0)
			enable_and_propagate_notifications(host_target, level,
				affect_top_host, affect_hosts, affect_services);
	}
#ifdef HAVE_DELETE_DOWNTIME_LONGNAME
	else if(strcmp(cmd_name, "delete_downtime") == 0) {
		char * comment = NULL;
		time_t start_time = 0;
		get_values(payload,
			"comment", JSON_STRING, 0, &comment,
			"start_time", JSON_INTEGER, 0, &start_time,
			NULL);
		delete_downtime_by_hostname_service_description_start_time_comment(
			host_name, service_description, start_time, comment);
	}
#endif

	json_decref(payload);
}