Пример #1
0
static int handle_worker_check(wproc_result *wpres, struct wproc_worker *wp, struct wproc_job *job)
{
	int result = ERROR;
	check_result *cr = (check_result *)job->arg;

	memcpy(&cr->rusage, &wpres->rusage, sizeof(wpres->rusage));
	cr->start_time.tv_sec = wpres->start.tv_sec;
	cr->start_time.tv_usec = wpres->start.tv_usec;
	cr->finish_time.tv_sec = wpres->stop.tv_sec;
	cr->finish_time.tv_usec = wpres->stop.tv_usec;
	if (WIFEXITED(wpres->wait_status)) {
		cr->return_code = WEXITSTATUS(wpres->wait_status);
	} else {
		cr->return_code = STATE_UNKNOWN;
	}

	if (wpres->outstd && *wpres->outstd) {
		cr->output = strdup(wpres->outstd);
	} else if (wpres->outerr) {
		asprintf(&cr->output, "(No output on stdout) stderr: %s", wpres->outerr);
	} else {
		cr->output = NULL;
	}

	cr->early_timeout = wpres->early_timeout;
	cr->exited_ok = wpres->exited_ok;
	cr->engine = NULL;
	cr->source = wp->name;

	process_check_result(cr);
	free_check_result(cr);

	return result;
}
Пример #2
0
static void process_status(json_t * payload) {
	char * host_name, *service_description = NULL, *output = NULL;
	check_result * newcr = NULL, t;

	init_check_result(&t);
	t.output_file = NULL;
	t.output_file_fp = NULL;
	if(get_values(payload,
		"host_name", JSON_STRING, 1, &host_name,
		"service_description", JSON_STRING, 0, &service_description,
		"output", JSON_STRING, 1, &output,
		"return_code", JSON_INTEGER, 1, &t.return_code,
		"start_time", JSON_TIMEVAL, 0, &t.start_time,
		"finish_time", JSON_TIMEVAL, 1, &t.finish_time,
		"check_type", JSON_INTEGER, 1, &t.check_type,
		"check_options", JSON_INTEGER, 0, &t.check_options,
		"scheduled_check", JSON_INTEGER, 0, &t.scheduled_check,
		"reschedule_check", JSON_INTEGER, 0, &t.reschedule_check,
		"latency", JSON_REAL, 0, &t.latency,
		"early_timeout", JSON_INTEGER, 0, &t.early_timeout,
		"exited_ok", JSON_INTEGER, 0, &t.exited_ok,
		NULL) != 0) {
		json_decref(payload);
		return;
	}

	service * service_target = NULL;
	if(service_description)
		service_target = find_service(host_name, service_description);
	host * host_target = find_host(host_name);
	if(host_target == NULL || (service_description && !service_target)) {
		json_decref(payload);
		return;
	}

	newcr = malloc(sizeof(check_result));
	memcpy(newcr, &t, sizeof(check_result));
	newcr->host_name = strdup(host_name);
	if(service_target) {
		newcr->service_description = strdup(service_description);
		newcr->object_check_type = SERVICE_CHECK;
	}
	newcr->output = strdup(output);
	json_decref(payload);
#ifdef HAVE_NAGIOS4
	newcr->engine = &nagmq_check_engine;
	process_check_result(newcr);
#else
#ifdef HAVE_ADD_CHECK_RESULT_ONE
	add_check_result_to_list(newcr);
#elif defined(HAVE_ADD_CHECK_RESULT_TWO)
	add_check_result_to_list(&check_result_list, newcr);
#endif
#endif
}
Пример #3
0
/* insert results list into core */
static void move_results_to_core() {
    /* safely save off currently local list */
    pthread_mutex_lock(&mod_gm_result_list_mutex);

    objectlist *tmp_list = NULL;
    for (mod_gm_result_list; mod_gm_result_list; mod_gm_result_list = mod_gm_result_list->next) {
        free(tmp_list);
        process_check_result(mod_gm_result_list->object_ptr);
        free_check_result(mod_gm_result_list->object_ptr);
        free(mod_gm_result_list->object_ptr);
        tmp_list = mod_gm_result_list;
    }
    mod_gm_result_list = 0;
    free(tmp_list);

    pthread_mutex_unlock(&mod_gm_result_list_mutex);
}