zabbix-agent2/src/libs/zbxdbcache/dbconfig.c
/******************************************************************************
 *                                                                            *
 * Function: DCconfig_get_triggers_by_itemids                                 *
 *                                                                            *
 * Purpose: get enabled triggers for specified items                          *
 *                                                                            *
 * Author: Aleksandrs Saveljevs                                               *
 *                                                                            *
 ******************************************************************************/
DCconfig_get_triggers_by_itemids

Purpose: get enabled triggers for specified items

Author: Aleksandrs Saveljevs
DCconfig_get_triggers_by_itemids Purpose : get enabled triggers for specified items Author : Aleksandrs Saveljevs
void	DCconfig_get_triggers_by_itemids(zbx_hashset_t *trigger_info, zbx_vector_ptr_t *trigger_order,
		const zbx_uint64_t *itemids, const zbx_timespec_t *timespecs, int itemids_num)
{
	int			i, j, found;
	const ZBX_DC_ITEM	*dc_item;
	const ZBX_DC_TRIGGER	*dc_trigger;
	DC_TRIGGER		*trigger;
	RDLOCK_CACHE;
	for (i = 0; i < itemids_num; i++)
	{
		if (NULL == (dc_item = (ZBX_DC_ITEM *)zbx_hashset_search(&config->items, &itemids[i])) || NULL == dc_item->triggers)
			continue;
		for (j = 0; NULL != (dc_trigger = dc_item->triggers[j]); j++)
		{
			if (TRIGGER_STATUS_ENABLED != dc_trigger->status)
				continue;
			trigger = (DC_TRIGGER *)DCfind_id(trigger_info, dc_trigger->triggerid, sizeof(DC_TRIGGER), &found);
			if (0 == found)
			{
				DCget_trigger(trigger, dc_trigger);
				zbx_vector_ptr_append(trigger_order, trigger);
			}
			if (trigger->timespec.sec < timespecs[i].sec ||
					(trigger->timespec.sec == timespecs[i].sec &&
					trigger->timespec.ns < timespecs[i].ns))
			{
				trigger->timespec = timespecs[i];
			}
		}
	}
	UNLOCK_CACHE;
}
void DCconfig_get_triggers_by_itemids ( zbx_hashset_t * trigger_info , zbx_vector_ptr_t * trigger_order , const zbx_uint64_t * itemids , const zbx_timespec_t * timespecs , int itemids_num ) { int i , j , found ; const ZBX_DC_ITEM * dc_item ; const ZBX_DC_TRIGGER * dc_trigger ; DC_TRIGGER * trigger ; RDLOCK_CACHE ; for ( i = 0 ; i < itemids_num ; i ++ ) { if ( NULL == ( dc_item = ( ZBX_DC_ITEM * ) zbx_hashset_search ( & config -> items , & itemids [ i ] ) ) || NULL == dc_item -> triggers ) continue ; for ( j = 0 ; NULL != ( dc_trigger = dc_item -> triggers [ j ] ) ; j ++ ) { if ( TRIGGER_STATUS_ENABLED != dc_trigger -> status ) continue ; trigger = ( DC_TRIGGER * ) DCfind_id ( trigger_info , dc_trigger -> triggerid , sizeof ( DC_TRIGGER ) , & found ) ; if ( 0 == found ) { DCget_trigger ( trigger , dc_trigger ) ; zbx_vector_ptr_append ( trigger_order , trigger ) ; } if ( trigger -> timespec . sec < timespecs [ i ] . sec || ( trigger -> timespec . sec == timespecs [ i ] . sec && trigger -> timespec . ns < timespecs [ i ] . ns ) ) { trigger -> timespec = timespecs [ i ] ; } } } UNLOCK_CACHE ; }
Function: DCconfig_get_triggers_by_itemids                                 
                                                                            
 Purpose: get enabled triggers for specified items                          
                                                                            
 Author: Aleksandrs Saveljevs
Function : DCconfig_get_triggers_by_itemids Purpose : get enabled triggers for specified items Author : Aleksandrs Saveljevs
/* skip items which are not in configuration cache and items without triggers */ /* process all triggers for the specified item */ /* find trigger by id or create a new record in hashset if not found */ /* copy latest change timestamp */ /* DCconfig_get_triggers_by_itemids() function is called during trigger processing */ /* when syncing history cache. A trigger cannot be processed by two syncers at the */ /* same time, so its safe to update trigger timespec within read lock.             */