Exemple #1
0
/* handles changes in the state of a service */
int handle_service_event(service *svc)
{
	nagios_macros mac;

	if (svc == NULL)
		return ERROR;

	broker_statechange_data(NEBTYPE_STATECHANGE_END, NEBFLAG_NONE, NEBATTR_NONE, SERVICE_STATECHANGE, (void *)svc, svc->current_state, svc->state_type, svc->current_attempt, svc->max_attempts);

	/* bail out if we shouldn't be running event handlers */
	if (enable_event_handlers == FALSE)
		return OK;
	if (svc->event_handler_enabled == FALSE)
		return OK;

	/* update service macros */
	memset(&mac, 0, sizeof(mac));
	grab_service_macros_r(&mac, svc);

	/* run the global service event handler */
	run_global_service_event_handler(&mac, svc);

	/* run the event handler command if there is one */
	if (svc->event_handler != NULL)
		run_service_event_handler(&mac, svc);
	clear_volatile_macros_r(&mac);

	return OK;
}
Exemple #2
0
/* handles changes in the state of a service */
int handle_service_event(service *svc) {
	host *temp_host = NULL;
	icinga_macros mac;

	log_debug_info(DEBUGL_FUNCTIONS, 0, "handle_service_event()\n");

	if (svc == NULL)
		return ERROR;

#ifdef USE_EVENT_BROKER
	/* send event data to broker */
	broker_statechange_data(NEBTYPE_STATECHANGE_END, NEBFLAG_NONE, NEBATTR_NONE, SERVICE_STATECHANGE, (void *)svc, svc->current_state, svc->state_type, svc->current_attempt, svc->max_attempts, NULL);
#endif

	/* bail out if we shouldn't be running event handlers */
	if (enable_event_handlers == FALSE)
		return OK;
	if (svc->event_handler_enabled == FALSE)
		return OK;

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

	/* update service macros */
	memset(&mac, 0, sizeof(mac));
	grab_host_macros_r(&mac, temp_host);
	grab_service_macros_r(&mac, svc);

	/* run the global service event handler */
	run_global_service_event_handler(&mac, svc);

	/* run the event handler command if there is one */
	if (svc->event_handler != NULL)
		run_service_event_handler(&mac, svc);
	clear_volatile_macros_r(&mac);

	/* check for external commands - the event handler may have given us some directives... */
	check_for_external_commands();

	return OK;
}