zabbix-agent2/src/libs/zbxdbcache/dbconfig.c
/******************************************************************************
 *                                                                            *
 * Function: dc_trigger_update_cache                                          *
 *                                                                            *
 * Purpose: updates trigger related cache data;                               *
 *              1) time triggers assigned to timer processes                  *
 *              2) trigger functionality (if it uses contain disabled         *
 *                 items/hosts)                                               *
 *              3) list of triggers each item is used by                      *
 *                                                                            *
 ******************************************************************************/
dc_trigger_update_cache

Purpose: updates trigger related cache data;
1) time triggers assigned to timer processes
2) trigger functionality (if it uses contain disabled
items/hosts)
3) list of triggers each item is used by
dc_trigger_update_cache Purpose : updates trigger related cache data ; 1 ) time triggers assigned to timer processes 2 ) trigger functionality ( if it uses contain disabled items / hosts ) 3 ) list of triggers each item is used by
static void	dc_trigger_update_cache(void)
{
	zbx_hashset_iter_t	iter;
	ZBX_DC_TRIGGER		*trigger;
	ZBX_DC_FUNCTION		*function;
	ZBX_DC_ITEM		*item;
	int			i, j, k;
	zbx_ptr_pair_t		itemtrig;
	zbx_vector_ptr_pair_t	itemtrigs;
	ZBX_DC_HOST		*host;
	zbx_hashset_iter_reset(&config->triggers, &iter);
	while (NULL != (trigger = (ZBX_DC_TRIGGER *)zbx_hashset_iter_next(&iter)))
		trigger->functional = TRIGGER_FUNCTIONAL_TRUE;
	zbx_vector_ptr_pair_create(&itemtrigs);
	zbx_hashset_iter_reset(&config->functions, &iter);
	while (NULL != (function = (ZBX_DC_FUNCTION *)zbx_hashset_iter_next(&iter)))
	{
		if (NULL == (item = (ZBX_DC_ITEM *)zbx_hashset_search(&config->items, &function->itemid)) ||
				NULL == (trigger = (ZBX_DC_TRIGGER *)zbx_hashset_search(&config->triggers, &function->triggerid)))
		{
			continue;
		}
		if (0 != item->update_triggers)
		{
			itemtrig.first = item;
			itemtrig.second = trigger;
			zbx_vector_ptr_pair_append(&itemtrigs, itemtrig);
		}
		if (TRIGGER_FUNCTIONAL_FALSE == trigger->functional)
			continue;
		if (ITEM_STATUS_DISABLED == item->status ||
				(NULL == (host = (ZBX_DC_HOST *)zbx_hashset_search(&config->hosts, &item->hostid)) ||
						HOST_STATUS_NOT_MONITORED == host->status))
		{
			trigger->functional = TRIGGER_FUNCTIONAL_FALSE;
		}
	}
	zbx_vector_ptr_pair_sort(&itemtrigs, zbx_default_ptr_pair_ptr_compare_func);
	zbx_vector_ptr_pair_uniq(&itemtrigs, zbx_default_ptr_pair_ptr_compare_func);
	for (i = 0; i < itemtrigs.values_num; i++)
	{
		for (j = i + 1; j < itemtrigs.values_num; j++)
		{
			if (itemtrigs.values[i].first != itemtrigs.values[j].first)
				break;
		}
		item = (ZBX_DC_ITEM *)itemtrigs.values[i].first;
		item->update_triggers = 0;
		item->triggers = (ZBX_DC_TRIGGER **)config->items.mem_realloc_func(item->triggers, (j - i + 1) * sizeof(ZBX_DC_TRIGGER *));
		for (k = i; k < j; k++)
			item->triggers[k - i] = (ZBX_DC_TRIGGER *)itemtrigs.values[k].second;
		item->triggers[j - i] = NULL;
		i = j - 1;
	}
	zbx_vector_ptr_pair_destroy(&itemtrigs);
}
static void dc_trigger_update_cache ( void ) { zbx_hashset_iter_t iter ; ZBX_DC_TRIGGER * trigger ; ZBX_DC_FUNCTION * function ; ZBX_DC_ITEM * item ; int i , j , k ; zbx_ptr_pair_t itemtrig ; zbx_vector_ptr_pair_t itemtrigs ; ZBX_DC_HOST * host ; zbx_hashset_iter_reset ( & config -> triggers , & iter ) ; while ( NULL != ( trigger = ( ZBX_DC_TRIGGER * ) zbx_hashset_iter_next ( & iter ) ) ) trigger -> functional = TRIGGER_FUNCTIONAL_TRUE ; zbx_vector_ptr_pair_create ( & itemtrigs ) ; zbx_hashset_iter_reset ( & config -> functions , & iter ) ; while ( NULL != ( function = ( ZBX_DC_FUNCTION * ) zbx_hashset_iter_next ( & iter ) ) ) { if ( NULL == ( item = ( ZBX_DC_ITEM * ) zbx_hashset_search ( & config -> items , & function -> itemid ) ) || NULL == ( trigger = ( ZBX_DC_TRIGGER * ) zbx_hashset_search ( & config -> triggers , & function -> triggerid ) ) ) { continue ; } if ( 0 != item -> update_triggers ) { itemtrig . first = item ; itemtrig . second = trigger ; zbx_vector_ptr_pair_append ( & itemtrigs , itemtrig ) ; } if ( TRIGGER_FUNCTIONAL_FALSE == trigger -> functional ) continue ; if ( ITEM_STATUS_DISABLED == item -> status || ( NULL == ( host = ( ZBX_DC_HOST * ) zbx_hashset_search ( & config -> hosts , & item -> hostid ) ) || HOST_STATUS_NOT_MONITORED == host -> status ) ) { trigger -> functional = TRIGGER_FUNCTIONAL_FALSE ; } } zbx_vector_ptr_pair_sort ( & itemtrigs , zbx_default_ptr_pair_ptr_compare_func ) ; zbx_vector_ptr_pair_uniq ( & itemtrigs , zbx_default_ptr_pair_ptr_compare_func ) ; for ( i = 0 ; i < itemtrigs . values_num ; i ++ ) { for ( j = i + 1 ; j < itemtrigs . values_num ; j ++ ) { if ( itemtrigs . values [ i ] . first != itemtrigs . values [ j ] . first ) break ; } item = ( ZBX_DC_ITEM * ) itemtrigs . values [ i ] . first ; item -> update_triggers = 0 ; item -> triggers = ( ZBX_DC_TRIGGER * * ) config -> items . mem_realloc_func ( item -> triggers , ( j - i + 1 ) * sizeof ( ZBX_DC_TRIGGER * ) ) ; for ( k = i ; k < j ; k ++ ) item -> triggers [ k - i ] = ( ZBX_DC_TRIGGER * ) itemtrigs . values [ k ] . second ; item -> triggers [ j - i ] = NULL ; i = j - 1 ; } zbx_vector_ptr_pair_destroy ( & itemtrigs ) ; }
Function: dc_trigger_update_cache                                          
                                                                            
 Purpose: updates trigger related cache data;                               
              1) time triggers assigned to timer processes                  
              2) trigger functionality (if it uses contain disabled         
                 items/hosts)                                               
              3) list of triggers each item is used by
Function : dc_trigger_update_cache Purpose : updates trigger related cache data ; 1 ) time triggers assigned to timer processes 2 ) trigger functionality ( if it uses contain disabled items / hosts ) 3 ) list of triggers each item is used by
/* cache item - trigger link */ /* disable functionality for triggers with expression containing */ /* disabled or not monitored items                               */ /* update links from items to triggers */