diff --git a/src/zabbix_server/lld/lld_item.c b/src/zabbix_server/lld/lld_item.c index 150701fa17e..e677b4707ea 100644 --- a/src/zabbix_server/lld/lld_item.c +++ b/src/zabbix_server/lld/lld_item.c @@ -985,137 +985,6 @@ static zbx_item_dependence_t *lld_item_dependence_add(zbx_vector_item_dependence return dependence; } -/****************************************************************************** - * * - * Purpose: Recursively gets dependencies with dependent items taking into * - * account item prototypes. * - * * - * Parameters: item_prototypes - [IN] * - * item_dependencies - [OUT] list of dependencies * - * * - ******************************************************************************/ -static void lld_item_dependencies_get(const zbx_vector_lld_item_prototype_ptr_t *item_prototypes, - zbx_vector_item_dependence_ptr_t *item_dependencies) -{ -#define NEXT_CHECK_BY_ITEM_IDS 0 -#define NEXT_CHECK_BY_MASTERITEM_IDS 1 - - int i, check_type; - zbx_vector_uint64_t processed_masterid, processed_itemid, next_check_itemids, next_check_masterids, - *check_ids; - char *sql = NULL; - size_t sql_alloc = 0, sql_offset; - zbx_db_result_t result; - zbx_db_row_t row; - - zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__); - - zbx_vector_uint64_create(&processed_masterid); - zbx_vector_uint64_create(&processed_itemid); - zbx_vector_uint64_create(&next_check_itemids); - zbx_vector_uint64_create(&next_check_masterids); - - /* collect the item id of prototypes for searching dependencies into database */ - for (i = 0; i < item_prototypes->values_num; i++) - { - const zbx_lld_item_prototype_t *item_prototype = item_prototypes->values[i]; - - if (0 != item_prototype->master_itemid) - { - lld_item_dependence_add(item_dependencies, item_prototype->itemid, - item_prototype->master_itemid, ZBX_FLAG_DISCOVERY_PROTOTYPE); - zbx_vector_uint64_append(&next_check_itemids, item_prototype->master_itemid); - zbx_vector_uint64_append(&next_check_masterids, item_prototype->master_itemid); - } - } - - /* search dependency in two directions (masteritem_id->itemid and itemid->masteritem_id) */ - while (0 < next_check_itemids.values_num || 0 < next_check_masterids.values_num) - { - if (0 < next_check_itemids.values_num) - { - check_type = NEXT_CHECK_BY_ITEM_IDS; - check_ids = &next_check_itemids; - } - else - { - check_type = NEXT_CHECK_BY_MASTERITEM_IDS; - check_ids = &next_check_masterids; - } - - sql_offset = 0; - zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset, "select itemid,master_itemid,flags from items where"); - zbx_db_add_condition_alloc(&sql, &sql_alloc, &sql_offset, - NEXT_CHECK_BY_ITEM_IDS == check_type ? "itemid" : "master_itemid", - check_ids->values, check_ids->values_num); - - if (NEXT_CHECK_BY_ITEM_IDS == check_type) - zbx_vector_uint64_append_array(&processed_itemid, check_ids->values, check_ids->values_num); - else - zbx_vector_uint64_append_array(&processed_masterid, check_ids->values, check_ids->values_num); - - zbx_vector_uint64_clear(check_ids); - - result = zbx_db_select("%s", sql); - - while (NULL != (row = zbx_db_fetch(result))) - { - int dependence_found = 0; - zbx_item_dependence_t *dependence = NULL; - zbx_uint64_t itemid, master_itemid; - unsigned int item_flags; - - ZBX_STR2UINT64(itemid, row[0]); - ZBX_DBROW2UINT64(master_itemid, row[1]); - ZBX_STR2UCHAR(item_flags, row[2]); - - for (i = 0; i < item_dependencies->values_num; i++) - { - dependence = item_dependencies->values[i]; - - if (dependence->itemid == itemid && dependence->master_itemid == master_itemid) - { - dependence_found = 1; - break; - } - } - - if (0 == dependence_found) - { - dependence = lld_item_dependence_add(item_dependencies, itemid, master_itemid, - item_flags); - } - - if (FAIL == zbx_vector_uint64_search(&processed_masterid, dependence->itemid, - ZBX_DEFAULT_UINT64_COMPARE_FUNC)) - { - zbx_vector_uint64_append(&next_check_masterids, dependence->itemid); - } - - if (NEXT_CHECK_BY_ITEM_IDS != check_type || 0 == dependence->master_itemid) - continue; - - if (FAIL == zbx_vector_uint64_search(&processed_itemid, dependence->master_itemid, - ZBX_DEFAULT_UINT64_COMPARE_FUNC)) - { - zbx_vector_uint64_append(&next_check_itemids, dependence->master_itemid); - } - } - zbx_db_free_result(result); - } - zbx_free(sql); - - zbx_vector_uint64_destroy(&processed_masterid); - zbx_vector_uint64_destroy(&processed_itemid); - zbx_vector_uint64_destroy(&next_check_itemids); - zbx_vector_uint64_destroy(&next_check_masterids); - - zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__); - -#undef NEXT_CHECK_BY_ITEM_IDS -#undef NEXT_CHECK_BY_MASTERITEM_IDS -} - /****************************************************************************** * * * Purpose: recursively counts number of dependencies * @@ -1717,42 +1586,6 @@ static void lld_items_validate(zbx_uint64_t hostid, zbx_vector_lld_item_full_ptr zbx_vector_uint64_destroy(&itemids); /* check limit of dependent items in the dependency tree */ - if (0 != item_dependencies->values_num) - { - for (int i = 0; i < items->values_num; i++) - { - int index; - const zbx_lld_item_prototype_t *item_prototype; - - item = items->values[i]; - - if (0 == (item->flags & ZBX_FLAG_LLD_ITEM_DISCOVERED) || 0 == item->master_itemid - || (0 != item->itemid && 0 == (item->flags & ZBX_FLAG_LLD_ITEM_UPDATE_TYPE))) - { - continue; - } - - zbx_lld_item_prototype_t cmp = {.itemid = item->parent_itemid}; - - if (FAIL == (index = zbx_vector_lld_item_prototype_ptr_bsearch(item_prototypes, - &cmp, lld_item_prototype_compare_func))) - { - THIS_SHOULD_NEVER_HAPPEN; - continue; - } - - item_prototype = item_prototypes->values[index]; - - if (SUCCEED != lld_item_dependencies_check(item, item_prototype, item_dependencies)) - { - *error = zbx_strdcatf(*error, - "Cannot create item \"%s\": maximum dependent item count reached.\n", - item->key); - - item->flags &= ~ZBX_FLAG_LLD_ITEM_DISCOVERED; - } - } - } /* check for broken dependent items */ for (int i = 0; i < items->values_num; i++) @@ -4576,7 +4409,6 @@ int lld_update_items(zbx_uint64_t hostid, zbx_uint64_t lld_ruleid, zbx_vector_ll lld_link_dependent_items(&items, &items_index); zbx_vector_item_dependence_ptr_create(&item_dependencies); - lld_item_dependencies_get(&item_prototypes, &item_dependencies); lld_items_validate(hostid, &items, &item_prototypes, &item_dependencies, error);