コード例 #1
0
/******************************************************************************
 *                                                                            *
 * Function: process_event                                                    *
 *                                                                            *
 * Purpose: process new event                                                 *
 *                                                                            *
 * Parameters: event - event data (event.eventid - new event)                 *
 *                                                                            *
 * Return value: SUCCEED - event added                                        *
 *               FAIL    - event not added                                    *
 *                                                                            *
 * Comments: When processing trigger events IT services updates are queued    *
 *           and _must_ be flushed at the end of transaction with             *
 *           DBflush_itservice_updates() function !!!                         *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 ******************************************************************************/
int	process_event(zbx_uint64_t eventid, int source, int object, zbx_uint64_t objectid, const zbx_timespec_t *timespec,
		int value, unsigned char value_changed, int acknowledged, int force_actions)
{
	const char	*__function_name = "process_event";
	DB_EVENT	event;
	int		ret = FAIL;

	zabbix_log(LOG_LEVEL_DEBUG, "In %s() eventid:" ZBX_FS_UI64 " object:%d objectid:" ZBX_FS_UI64 " value:%d"
			" value_changed:%d", __function_name, eventid, object, objectid, value, (int)value_changed);

	/* preparing event for processing */
	memset(&event, 0, sizeof(DB_EVENT));
	event.eventid = eventid;
	event.source = source;
	event.object = object;
	event.objectid = objectid;
	event.clock = timespec->sec;
	event.ns = timespec->ns;
	event.value = value;
	event.value_changed = value_changed;
	event.acknowledged = acknowledged;

	if (TRIGGER_VALUE_CHANGED_YES == event.value_changed || 1 == force_actions)
		if (SUCCEED != add_trigger_info(&event))
			goto fail;

	if (0 == event.eventid)
		event.eventid = DBget_maxid("events");

	DBexecute("insert into events (eventid,source,object,objectid,clock,ns,value,value_changed)"
			" values (" ZBX_FS_UI64 ",%d,%d," ZBX_FS_UI64 ",%d,%d,%d,%d)",
			event.eventid, event.source, event.object, event.objectid, event.clock, event.ns,
			event.value, (int)event.value_changed);

	if (TRIGGER_VALUE_CHANGED_YES == event.value_changed || 1 == force_actions)
		process_actions(&event);

	if (TRIGGER_VALUE_CHANGED_YES == event.value_changed && EVENT_OBJECT_TRIGGER == event.object)
	{
		DBqueue_itservice_update(event.objectid, TRIGGER_VALUE_TRUE == event.value ? event.trigger.priority : 0,
				event.clock);
	}

	ret = SUCCEED;
fail:
	zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret));

	return ret;
}
コード例 #2
0
ファイル: events.c プロジェクト: Shmuma/z
/******************************************************************************
 *                                                                            *
 * Function: process_event                                                    *
 *                                                                            *
 * Purpose: process new event                                                 *
 *                                                                            *
 * Parameters: event - event data (event.eventid - new event)                 *
 *                                                                            *
 * Return value: SUCCESS - event added                                        *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 * Comments: Cannot use action->userid as it may also be groupid              *
 *                                                                            *
 ******************************************************************************/
int	process_event(DB_EVENT *event)
{
	zabbix_log(LOG_LEVEL_DEBUG,"In process_event(eventid:" ZBX_FS_UI64 ",object:%d,objectid:" ZBX_FS_UI64 ")",
			event->eventid,
			event->object,
			event->objectid);

	add_trigger_info(event);

	event->eventid = DBadd_event_low_level (event->source, event->object, event->objectid, event->clock, event->value);

	if (event->source == EVENT_SOURCE_TRIGGERS)
		HFS_add_event (CONFIG_HFS_PATH, CONFIG_SERVER_SITE, event->eventid, event->objectid, 
			       event->clock, event->value, event->acknowledged, event->hostid);

	/* Cancel currently active alerts */
/*	if(event->value == TRIGGER_VALUE_FALSE || event->value == TRIGGER_VALUE_TRUE)
	{
		DBexecute("update alerts set retries=3,error='Trigger changed its status. Will not send repeats.' where triggerid=" ZBX_FS_UI64 " and repeats>0 and status=%d",
			event->triggerid, ALERT_STATUS_NOT_SENT);
	}*/

	if(event->skip_actions == 0)
	{
		process_actions(event);
	}

	if(event->value == TRIGGER_VALUE_TRUE)
	{
		DBupdate_services(event->objectid, event->trigger_priority);
	}
	else
	{
		DBupdate_services(event->objectid, 0);
	}

	free_trigger_info(event);

	zabbix_log(LOG_LEVEL_DEBUG,"End of process_event()");
	
	return SUCCEED;
}