Example #1
0
/* write a service problem/recovery to the icinga log file */
int log_service_event(service *svc) {
	char *temp_buffer = NULL;
	unsigned long log_options = 0L;
	host *temp_host = NULL;

	/* don't log soft errors if the user doesn't want to */
	if (svc->state_type == SOFT_STATE && !log_service_retries)
		return OK;

	/* get the log options */
	if (svc->current_state == STATE_UNKNOWN)
		log_options = NSLOG_SERVICE_UNKNOWN;
	else if (svc->current_state == STATE_WARNING)
		log_options = NSLOG_SERVICE_WARNING;
	else if (svc->current_state == STATE_CRITICAL)
		log_options = NSLOG_SERVICE_CRITICAL;
	else
		log_options = NSLOG_SERVICE_OK;

	/* find the associated host */
	if ((temp_host = svc->host_ptr) == NULL)
		return ERROR;

	/* either log only the output, or if enabled, add long_output */
	if (log_long_plugin_output == TRUE && svc->long_plugin_output != NULL) {
		asprintf(&temp_buffer, "SERVICE ALERT: %s;%s;%s;%s;%d;%s\\n%s\n",
				svc->host_name, svc->description,
				service_state_name(svc->current_state),
				state_type_name(svc->state_type),
				svc->current_attempt,
				(svc->plugin_output == NULL) ? "" : svc->plugin_output,
				svc->long_plugin_output
				);
	} else {
		asprintf(&temp_buffer, "SERVICE ALERT: %s;%s;%s;%s;%d;%s\n",
				svc->host_name, svc->description,
				service_state_name(svc->current_state),
				state_type_name(svc->state_type),
				svc->current_attempt,
				(svc->plugin_output == NULL) ? "" : svc->plugin_output
				);
	}

	write_to_all_logs_with_host_service(temp_buffer, log_options, temp_host, svc);
	my_free(temp_buffer);

	return OK;
}
Example #2
0
/* logs service states */
int log_service_states(int type, time_t *timestamp) {
    char *temp_buffer = NULL;
    service *temp_service = NULL;
    host *temp_host = NULL;;

    /* bail if we shouldn't be logging initial states */
    if(type == INITIAL_STATES && log_initial_states == FALSE)
        return OK;

    for(temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) {

        /* find the associated host */
        if((temp_host = temp_service->host_ptr) == NULL)
            continue;

        asprintf(&temp_buffer, "%s SERVICE STATE: %s;%s;%s;%s;%d;%s\n",
                 (type == INITIAL_STATES) ? "INITIAL" : "CURRENT",
                 temp_service->host_name, temp_service->description,
                 service_state_name(temp_service->current_state),
                 state_type_name(temp_service->state_type),
                 temp_service->current_attempt,
                 temp_service->plugin_output);

        write_to_all_logs_with_timestamp(temp_buffer, NSLOG_INFO_MESSAGE, timestamp);

        my_free(temp_buffer);
    }

    return OK;
}
Example #3
0
/* write a host problem/recovery to the log file */
int log_host_event(host *hst) {
    char *temp_buffer = NULL;
    unsigned long log_options = 0L;

    /* get the log options */
    if(hst->current_state == HOST_DOWN)
        log_options = NSLOG_HOST_DOWN;
    else if(hst->current_state == HOST_UNREACHABLE)
        log_options = NSLOG_HOST_UNREACHABLE;
    else
        log_options = NSLOG_HOST_UP;

    asprintf(&temp_buffer, "HOST ALERT: %s;%s;%s;%d;%s\n",
             hst->name,
             host_state_name(hst->current_state),
             state_type_name(hst->state_type),
             hst->current_attempt,
             (hst->plugin_output == NULL) ? "" : hst->plugin_output);

    write_to_all_logs(temp_buffer, log_options);

    my_free(temp_buffer);

    return OK;
}
Example #4
0
EXPORT	void fprint_state_type(
	FILE		*file,
	const char	*message,
	int		state_type)
{
        (void) fprintf(file,"%s%s\n",message,state_type_name(state_type));
}		/*end fprint_state_type*/
Example #5
0
/* write a service problem/recovery to the naemon log file */
int log_service_event(service *svc)
{
    unsigned long log_options = 0L;

    /* don't log soft errors if the user doesn't want to */
    if (svc->state_type == SOFT_STATE && !log_service_retries)
        return OK;

    /* get the log options */
    if (svc->current_state == STATE_UNKNOWN)
        log_options = NSLOG_SERVICE_UNKNOWN;
    else if (svc->current_state == STATE_WARNING)
        log_options = NSLOG_SERVICE_WARNING;
    else if (svc->current_state == STATE_CRITICAL)
        log_options = NSLOG_SERVICE_CRITICAL;
    else
        log_options = NSLOG_SERVICE_OK;

    nm_log(log_options, "SERVICE ALERT: %s;%s;%s;%s;%d;%s",
           svc->host_name, svc->description,
           service_state_name(svc->current_state),
           state_type_name(svc->state_type),
           svc->current_attempt,
           (svc->plugin_output == NULL) ? "" : svc->plugin_output);

    return OK;
}
Example #6
0
/* logs host states */
int log_host_states(int type, time_t *timestamp) {
	char *temp_buffer = NULL;
	host *temp_host = NULL;

	/* bail if we shouldn't be logging initial states */
	if (type == INITIAL_STATES && log_initial_states == FALSE)
		return OK;

	for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {

		asprintf(&temp_buffer, "%s HOST STATE: %s;%s;%s;%d;%s\n",
				(type == INITIAL_STATES) ? "INITIAL" : "CURRENT",
				temp_host->name,
				host_state_name(temp_host->current_state),
				state_type_name(temp_host->state_type),
				temp_host->current_attempt,
				(temp_host->plugin_output == NULL) ? "" : temp_host->plugin_output
				);

		write_to_all_logs_with_timestamp_with_host_service(temp_buffer, NSLOG_INFO_MESSAGE, timestamp, temp_host, NULL);

		my_free(temp_buffer);
	}

	return OK;
}
Example #7
0
/* write a host problem/recovery to the log file */
int log_host_event(host *hst) {
	char *temp_buffer = NULL;
	unsigned long log_options = 0L;

	/* get the log options */
	if (hst->current_state == HOST_DOWN)
		log_options = NSLOG_HOST_DOWN;
	else if (hst->current_state == HOST_UNREACHABLE)
		log_options = NSLOG_HOST_UNREACHABLE;
	else
		log_options = NSLOG_HOST_UP;

	/* either log only the output, or if enabled, add long_output */
	if (log_long_plugin_output == TRUE && hst->long_plugin_output != NULL) {
		asprintf(&temp_buffer, "HOST ALERT: %s;%s;%s;%d;%s\\n%s\n",
				hst->name,
				host_state_name(hst->current_state),
				state_type_name(hst->state_type),
				hst->current_attempt,
				(hst->plugin_output == NULL) ? "" : hst->plugin_output,
				hst->long_plugin_output
				);
	} else {
		asprintf(&temp_buffer, "HOST ALERT: %s;%s;%s;%d;%s\n",
				hst->name,
				host_state_name(hst->current_state),
				state_type_name(hst->state_type),
				hst->current_attempt,
				(hst->plugin_output == NULL) ? "" : hst->plugin_output
				);
	}

	write_to_all_logs_with_host_service(temp_buffer, log_options, hst, NULL);
	my_free(temp_buffer);

	return OK;
}
Example #8
0
/* logs host states */
int log_host_states(int type, time_t *timestamp)
{
	host *temp_host = NULL;;

	/* bail if we shouldn't be logging initial states */
	if (type == INITIAL_STATES && log_initial_states == FALSE)
		return OK;

	for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
		nm_log(NSLOG_INFO_MESSAGE, "%s HOST STATE: %s;%s;%s;%d;%s\n", (type == INITIAL_STATES) ? "INITIAL" : "CURRENT",
					temp_host->name,
					host_state_name(temp_host->current_state),
					state_type_name(temp_host->state_type),
					temp_host->current_attempt,
					(temp_host->plugin_output == NULL) ? "" : temp_host->plugin_output);
	}

	return OK;
}
Example #9
0
/* logs service states */
int log_service_states(int type, time_t *timestamp)
{
    service *temp_service = NULL;

    /* bail if we shouldn't be logging initial states */
    if (type == INITIAL_STATES && log_initial_states == FALSE)
        return OK;

    for (temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) {

        nm_log(type, "%s SERVICE STATE: %s;%s;%s;%s;%d;%s",
               (type == INITIAL_STATES) ? "INITIAL" : "CURRENT",
               temp_service->host_name, temp_service->description,
               service_state_name(temp_service->current_state),
               state_type_name(temp_service->state_type),
               temp_service->current_attempt,
               temp_service->plugin_output);
    }

    return OK;
}
Example #10
0
/* write a host problem/recovery to the log file */
int log_host_event(host *hst)
{
	unsigned long log_options = 0L;

	/* get the log options */
	if (hst->current_state == STATE_DOWN)
		log_options = NSLOG_HOST_DOWN;
	else if (hst->current_state == STATE_UNREACHABLE)
		log_options = NSLOG_HOST_UNREACHABLE;
	else
		log_options = NSLOG_HOST_UP;

	nm_log(log_options, "HOST ALERT: %s;%s;%s;%d;%s\n",
				hst->name,
				host_state_name(hst->current_state),
				state_type_name(hst->state_type),
				hst->current_attempt,
				(hst->plugin_output == NULL) ? "" : hst->plugin_output);

	return OK;
}