Beispiel #1
0
/*
 * Deletes all host and service downtimes on a host by hostname,
 * optionally filtered by service description, start time and comment.
 * All char* must be set or NULL - "" will silently fail to match
 * Returns number deleted
 */
int delete_downtime_by_hostname_service_description_start_time_comment(char *hostname, char *service_description, time_t start_time, char *cmnt) {
	scheduled_downtime *temp_downtime;
	scheduled_downtime *next_downtime;
	void *downtime_cpy;
	int deleted = 0;
	objectlist *matches = NULL, *tmp_match = NULL;

	/* Do not allow deletion of everything - must have at least 1 filter on */
	if(hostname == NULL && service_description == NULL && start_time == 0 && cmnt == NULL)
		return deleted;

	for(temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = next_downtime) {
		next_downtime = temp_downtime->next;
		if(start_time != 0 && temp_downtime->start_time != start_time) {
			continue;
			}
		if(cmnt != NULL && strcmp(temp_downtime->comment, cmnt) != 0)
			continue;
		if(temp_downtime->type == HOST_DOWNTIME) {
			/* If service is specified, then do not delete the host downtime */
			if(service_description != NULL)
				continue;
			if(hostname != NULL && strcmp(temp_downtime->host_name, hostname) != 0)
				continue;
			}
		else if(temp_downtime->type == SERVICE_DOWNTIME) {
			if(hostname != NULL && strcmp(temp_downtime->host_name, hostname) != 0)
				continue;
			if(service_description != NULL && strcmp(temp_downtime->service_description, service_description) != 0)
				continue;
			}

		downtime_cpy = malloc(sizeof(scheduled_downtime));
		memcpy(downtime_cpy, temp_downtime, sizeof(scheduled_downtime));
		prepend_object_to_objectlist(&matches, downtime_cpy);
		deleted++;
		}

	for(tmp_match = matches; tmp_match != NULL; tmp_match = tmp_match->next) {
		temp_downtime = (scheduled_downtime *)tmp_match->object_ptr;
		unschedule_downtime(temp_downtime->type, temp_downtime->downtime_id);
		my_free(temp_downtime);
		}

	free_objectlist(&matches);

	return deleted;
	}
serviceescalation *add_serviceescalation(char *host_name, char *description, int first_notification, int last_notification, double notification_interval, char *escalation_period, int escalation_options)
{
	serviceescalation *new_serviceescalation = NULL;
	service *svc;
	timeperiod *tp = NULL;

	/* make sure we have the data we need */
	if (host_name == NULL || !*host_name || description == NULL || !*description) {
		nm_log(NSLOG_CONFIG_ERROR, "Error: Service escalation host name or description is NULL\n");
		return NULL;
	}
	if (!(svc = find_service(host_name, description))) {
		nm_log(NSLOG_CONFIG_ERROR, "Error: Service '%s' on host '%s' has an escalation but is not defined anywhere!\n",
		       host_name, description);
		return NULL;
	}
	if (escalation_period && !(tp = find_timeperiod(escalation_period))) {
		nm_log(NSLOG_VERIFICATION_ERROR, "Error: Escalation period '%s' specified in service escalation for service '%s' on host '%s' is not defined anywhere!\n",
		       escalation_period, description, host_name);
		return NULL ;
	}

	new_serviceescalation = nm_calloc(1, sizeof(*new_serviceescalation));

	if (prepend_object_to_objectlist(&svc->escalation_list, new_serviceescalation) != OK) {
		nm_log(NSLOG_CONFIG_ERROR, "Could not add escalation to service '%s' on host '%s'\n",
		       svc->host_name, svc->description);
		return NULL;
	}

	/* assign vars. object names are immutable, so no need to copy */
	new_serviceescalation->host_name = svc->host_name;
	new_serviceescalation->description = svc->description;
	new_serviceescalation->service_ptr = svc;
	new_serviceescalation->escalation_period_ptr = tp;
	if (tp)
		new_serviceescalation->escalation_period = tp->name;

	new_serviceescalation->first_notification = first_notification;
	new_serviceescalation->last_notification = last_notification;
	new_serviceescalation->notification_interval = (notification_interval <= 0) ? 0 : notification_interval;
	new_serviceescalation->escalation_options = escalation_options;

	new_serviceescalation->id = num_objects.serviceescalations++;
	return new_serviceescalation;
}
Beispiel #3
0
static int subscribe(int sd, struct nerd_channel *chan, char *fmt)
{
	struct nerd_subscription *subscr;

	if(!(subscr = calloc(1, sizeof(*subscr))))
		return -1;

	subscr->sd = sd;
	subscr->chan = chan;
	subscr->format = fmt ? strdup(fmt) : NULL;

	if(!chan->subscriptions) {
		nerd_register_channel_callbacks(chan);
	}

	prepend_object_to_objectlist(&chan->subscriptions, subscr);
	return 0;
}
hostescalation *add_hostescalation(char *host_name, int first_notification, int last_notification, double notification_interval, char *escalation_period, int escalation_options)
{
	hostescalation *new_hostescalation = NULL;
	host *h;
	timeperiod *tp = NULL;

	/* make sure we have the data we need */
	if (host_name == NULL || !*host_name) {
		nm_log(NSLOG_CONFIG_ERROR, "Error: Host escalation host name is NULL\n");
		return NULL;
	}
	if (!(h = find_host(host_name))) {
		nm_log(NSLOG_CONFIG_ERROR, "Error: Host '%s' has an escalation, but is not defined anywhere!\n", host_name);
		return NULL;
	}
	if (escalation_period && !(tp = find_timeperiod(escalation_period))) {
		nm_log(NSLOG_CONFIG_ERROR, "Error: Unable to locate timeperiod '%s' for hostescalation '%s'\n",
		       escalation_period, host_name);
		return NULL;
	}

	new_hostescalation = nm_calloc(1, sizeof(*new_hostescalation));

	/* add the escalation to its host */
	if (prepend_object_to_objectlist(&h->escalation_list, new_hostescalation) != OK) {
		nm_log(NSLOG_CONFIG_ERROR, "Error: Could not add hostescalation to host '%s'\n", host_name);
		free(new_hostescalation);
		return NULL;
	}

	/* assign vars. Object names are immutable, so no need to copy */
	new_hostescalation->host_name = h->name;
	new_hostescalation->host_ptr = h;
	new_hostescalation->escalation_period = tp ? tp->name : NULL;
	new_hostescalation->escalation_period_ptr = tp;
	new_hostescalation->first_notification = first_notification;
	new_hostescalation->last_notification = last_notification;
	new_hostescalation->notification_interval = (notification_interval <= 0) ? 0 : notification_interval;
	new_hostescalation->escalation_options = escalation_options;

	new_hostescalation->id = num_objects.hostescalations++;
	return new_hostescalation;
}
Beispiel #5
0
static const char *host_parent_path(host *leaf, char sep)
{
	char *ret;
	unsigned int len = 0, pos = 0;
	objectlist *stack = NULL, *list, *next;
	host *h = leaf;

	if(!h->parent_hosts)
		return h->name;

	if(!host_parent_path_cache) {
		host_parent_path_cache = calloc(num_objects.hosts, sizeof(char *));
	}
	if(host_parent_path_cache[h->id]) {
		return host_parent_path_cache[h->id];
	}

	while(h) {
		len += strlen(h->name) + 2; /* room for separator */
		prepend_object_to_objectlist(&stack, h->name);
		if(h->parent_hosts && h->parent_hosts->host_ptr)
			h = h->parent_hosts->host_ptr;
		else
			break;
	}

	ret = malloc(len + 1);
	for(list = stack; list; list = next) {
		char *ppart = (char *)list->object_ptr;
		next = list->next;
		free(list);
		ret[pos++] = sep;
		memcpy(ret + pos, ppart, strlen(ppart));
		pos += strlen(ppart);
	}
	ret[pos++] = 0;
	host_parent_path_cache[leaf->id] = ret;
	return ret;
}