zabbix-agent2/src/libs/zbxdbhigh/template_item.c
/******************************************************************************
 *                                                                            *
 * Function: update_template_lld_rule_formulas                                *
 *                                                                            *
 * Purpose: translate template item condition identifiers in expression type  *
 *          discovery rule formulas to refer the host item condition          *
 *          identifiers instead.                                              *
 *                                                                            *
 * Parameters:  items  - [IN] the template items                              *
 *              rules  - [IN] the lld rule mapping                            *
 *                                                                            *
 ******************************************************************************/
update_template_lld_rule_formulas

Purpose: translate template item condition identifiers in expression type
discovery rule formulas to refer the host item condition
identifiers instead.

Parameters:  items  - [IN] the template items
rules  - [IN] the lld rule mapping
update_template_lld_rule_formulas Purpose : translate template item condition identifiers in expression type discovery rule formulas to refer the host item condition identifiers instead . Parameters : items - [ IN ] the template items rules - [ IN ] the lld rule mapping
static void	update_template_lld_rule_formulas(zbx_vector_ptr_t *items, zbx_vector_ptr_t *rules)
{
	zbx_lld_rule_map_t	*rule;
	int			i, j, index;
	char			*formula;
	zbx_uint64_t		conditionid;
	for (i = 0; i < items->values_num; i++)
	{
		zbx_template_item_t	*item = (zbx_template_item_t *)items->values[i];
		if (0 == (ZBX_FLAG_DISCOVERY_RULE & item->flags) || CONDITION_EVAL_TYPE_EXPRESSION != item->evaltype)
			continue;
		index = zbx_vector_ptr_bsearch(rules, &item->templateid, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
		if (FAIL == index)
		{
			THIS_SHOULD_NEVER_HAPPEN;
			continue;
		}
		rule = (zbx_lld_rule_map_t *)rules->values[index];
		formula = zbx_strdup(NULL, item->formula);
		conditionid = rule->conditionid;
		for (j = 0; j < rule->conditions.values_num; j++)
		{
			zbx_uint64_t			id;
			zbx_lld_rule_condition_t	*condition =
					(zbx_lld_rule_condition_t *)rule->conditions.values[j];
			if (j < rule->conditionids.values_num)
				id = rule->conditionids.values[j];
			else
				id = conditionid++;
			update_template_lld_formula(&formula, condition->item_conditionid, id);
		}
		zbx_free(item->formula);
		item->formula = formula;
	}
}
static void update_template_lld_rule_formulas ( zbx_vector_ptr_t * items , zbx_vector_ptr_t * rules ) { zbx_lld_rule_map_t * rule ; int i , j , index ; char * formula ; zbx_uint64_t conditionid ; for ( i = 0 ; i < items -> values_num ; i ++ ) { zbx_template_item_t * item = ( zbx_template_item_t * ) items -> values [ i ] ; if ( 0 == ( ZBX_FLAG_DISCOVERY_RULE & item -> flags ) || CONDITION_EVAL_TYPE_EXPRESSION != item -> evaltype ) continue ; index = zbx_vector_ptr_bsearch ( rules , & item -> templateid , ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC ) ; if ( FAIL == index ) { THIS_SHOULD_NEVER_HAPPEN ; continue ; } rule = ( zbx_lld_rule_map_t * ) rules -> values [ index ] ; formula = zbx_strdup ( NULL , item -> formula ) ; conditionid = rule -> conditionid ; for ( j = 0 ; j < rule -> conditions . values_num ; j ++ ) { zbx_uint64_t id ; zbx_lld_rule_condition_t * condition = ( zbx_lld_rule_condition_t * ) rule -> conditions . values [ j ] ; if ( j < rule -> conditionids . values_num ) id = rule -> conditionids . values [ j ] ; else id = conditionid ++ ; update_template_lld_formula ( & formula , condition -> item_conditionid , id ) ; } zbx_free ( item -> formula ) ; item -> formula = formula ; } }
Function: update_template_lld_rule_formulas                                
                                                                            
 Purpose: translate template item condition identifiers in expression type  
          discovery rule formulas to refer the host item condition          
          identifiers instead.
Function : update_template_lld_rule_formulas Purpose : translate template item condition identifiers in expression type discovery rule formulas to refer the host item condition identifiers instead .