Esempio n. 1
0
static void process_acknowledgement(json_t * payload) {
	char *host_name, *service_description = NULL,
		*author_name, *comment_data;
	int persistent_comment = 0, notify_contacts = 0,
		acknowledgement_type = 0, end_time = 0;
	host * host_target = NULL;
	service * service_target = NULL;
	json_error_t err;
	if(get_values(payload,
		"host_name", JSON_STRING, 1, &host_name,
		"service_description", JSON_STRING, 0, &service_description,
		"author_name", JSON_STRING, 1, &author_name,
		"comment_data", JSON_STRING, 1, &comment_data,
		"acknowledgement_type", JSON_INTEGER, 0, &acknowledgement_type,
		"notify_contacts", JSON_TRUE, 0, &notify_contacts,
		"persistent_comment", JSON_TRUE, 0, &persistent_comment,
#ifdef HAVE_ICINGA
		"end_time", JSON_INTEGER, 0, &end_time,
#endif
		NULL) != 0) {
		json_decref(payload);
		return;
	}

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

#ifdef HAVE_ICINGA
	if(service_target)
		acknowledge_service_problem(service_target, author_name, comment_data,
			acknowledgement_type, notify_contacts, persistent_comment, end_time);
	else if(host_target)
		acknowledge_host_problem(host_target, author_name, comment_data,
			acknowledgement_type, notify_contacts, persistent_comment, end_time);
#else
	if(service_target)
		acknowledge_service_problem(service_target, author_name, comment_data,
			acknowledgement_type, notify_contacts, persistent_comment);
	else if(host_target)
		acknowledge_host_problem(host_target, author_name, comment_data,
			acknowledgement_type, notify_contacts, persistent_comment);
#endif
	json_decref(payload);
}
static int
acknowledge_problem_for_obj(int sd, const char* obj, char* comment)
{
  host*    hst;
  service* svc;
  nez_find_host_or_service(obj, &hst, &svc);

  char* author     = "nagioseasier";
  int   sticky     = 1; // DO NOT send notifications until this service/host recovers
  int   notify     = 1; // DO send a notification that we have ack'd this
  int   persistent = 0; // we don't want persistent comments in Nagios

  if (svc) {
    acknowledge_service_problem(
      svc,
      author,
      comment,
      sticky,
      notify,
      persistent);

    nsock_printf_nul(sd, "ACKNOWLEDGED PROBLEMS ON %s WITH: %s\n", obj, comment);
    return 200;
  }

  if (hst) {
    acknowledge_host_problem(
      hst,
      author,
      comment,
      sticky,
      notify,
      persistent);

    nsock_printf_nul(sd, "ACKNOWLEDGED PROBLEMS ON %s WITH: %s\n", obj, comment);
    return 200;
  }

  nsock_printf_nul(sd, "NO HOST OR SERVICE FOUND FOR %s\n", obj);
  return 404;
}