zabbix-agent2/src/zabbix_server/lld/lld_item.c
/******************************************************************************
 *                                                                            *
 * Function: lld_update_items                                                 *
 *                                                                            *
 * Purpose: add or update discovered items                                    *
 *                                                                            *
 * Return value: SUCCEED - if items were successfully added/updated or        *
 *                         adding/updating was not necessary                  *
 *               FAIL    - items cannot be added/updated                      *
 *                                                                            *
 ******************************************************************************/
lld_update_items

Purpose: add or update discovered items

Return value: SUCCEED - if items were successfully added/updated or
adding/updating was not necessary
FAIL    - items cannot be added/updated
lld_update_items Purpose : add or update discovered items Return value : SUCCEED - if items were successfully added / updated or adding / updating was not necessary FAIL - items cannot be added / updated
int	lld_update_items(zbx_uint64_t hostid, zbx_uint64_t lld_ruleid, zbx_vector_ptr_t *lld_rows,
		const zbx_vector_ptr_t *lld_macro_paths, char **error, int lifetime, int lastcheck)
{
	zbx_vector_ptr_t	items, item_prototypes, item_dependencies;
	zbx_hashset_t		items_index;
	int			ret = SUCCEED, host_record_is_locked = 0;
	zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
	zbx_vector_ptr_create(&item_prototypes);
	lld_item_prototypes_get(lld_ruleid, &item_prototypes);
	if (0 == item_prototypes.values_num)
		goto out;
	zbx_vector_ptr_create(&items);
	zbx_hashset_create(&items_index, item_prototypes.values_num * lld_rows->values_num, lld_item_index_hash_func,
			lld_item_index_compare_func);
	lld_items_get(&item_prototypes, &items);
	lld_items_make(&item_prototypes, lld_rows, lld_macro_paths, &items, &items_index, error);
	lld_items_preproc_make(&item_prototypes, lld_macro_paths, &items);
	lld_items_param_make(&item_prototypes, lld_macro_paths, &items);
	lld_items_tags_make(&item_prototypes, lld_macro_paths, &items);
	lld_link_dependent_items(&items, &items_index);
	zbx_vector_ptr_create(&item_dependencies);
	lld_item_dependencies_get(&item_prototypes, &item_dependencies);
	lld_items_validate(hostid, &items, &item_prototypes, &item_dependencies, error);
	DBbegin();
	if (SUCCEED == lld_items_save(hostid, &item_prototypes, &items, &items_index, &host_record_is_locked) &&
			SUCCEED == lld_items_preproc_save(hostid, &items, &host_record_is_locked) &&
			SUCCEED == lld_items_param_save(hostid, &items, &host_record_is_locked) &&
			SUCCEED == lld_items_tags_save(hostid, &items, &host_record_is_locked))
	{
		if (ZBX_DB_OK != DBcommit())
		{
			ret = FAIL;
			goto clean;
		}
	}
	else
	{
		ret = FAIL;
		DBrollback();
		goto clean;
	}
	lld_item_links_populate(&item_prototypes, lld_rows, &items_index);
	lld_remove_lost_objects("item_discovery", "itemid", &items, lifetime, lastcheck, DBdelete_items, get_item_info);
clean:
	zbx_hashset_destroy(&items_index);
	zbx_vector_ptr_clear_ext(&item_dependencies, zbx_ptr_free);
	zbx_vector_ptr_destroy(&item_dependencies);
	zbx_vector_ptr_clear_ext(&items, (zbx_clean_func_t)lld_item_free);
	zbx_vector_ptr_destroy(&items);
	zbx_vector_ptr_clear_ext(&item_prototypes, (zbx_clean_func_t)lld_item_prototype_free);
out:
	zbx_vector_ptr_destroy(&item_prototypes);
	zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__);
	return ret;
}
int lld_update_items ( zbx_uint64_t hostid , zbx_uint64_t lld_ruleid , zbx_vector_ptr_t * lld_rows , const zbx_vector_ptr_t * lld_macro_paths , char * * error , int lifetime , int lastcheck ) { zbx_vector_ptr_t items , item_prototypes , item_dependencies ; zbx_hashset_t items_index ; int ret = SUCCEED , host_record_is_locked = 0 ; zabbix_log ( LOG_LEVEL_DEBUG , " " , __func__ ) ; zbx_vector_ptr_create ( & item_prototypes ) ; lld_item_prototypes_get ( lld_ruleid , & item_prototypes ) ; if ( 0 == item_prototypes . values_num ) goto out ; zbx_vector_ptr_create ( & items ) ; zbx_hashset_create ( & items_index , item_prototypes . values_num * lld_rows -> values_num , lld_item_index_hash_func , lld_item_index_compare_func ) ; lld_items_get ( & item_prototypes , & items ) ; lld_items_make ( & item_prototypes , lld_rows , lld_macro_paths , & items , & items_index , error ) ; lld_items_preproc_make ( & item_prototypes , lld_macro_paths , & items ) ; lld_items_param_make ( & item_prototypes , lld_macro_paths , & items ) ; lld_items_tags_make ( & item_prototypes , lld_macro_paths , & items ) ; lld_link_dependent_items ( & items , & items_index ) ; zbx_vector_ptr_create ( & item_dependencies ) ; lld_item_dependencies_get ( & item_prototypes , & item_dependencies ) ; lld_items_validate ( hostid , & items , & item_prototypes , & item_dependencies , error ) ; DBbegin ( ) ; if ( SUCCEED == lld_items_save ( hostid , & item_prototypes , & items , & items_index , & host_record_is_locked ) && SUCCEED == lld_items_preproc_save ( hostid , & items , & host_record_is_locked ) && SUCCEED == lld_items_param_save ( hostid , & items , & host_record_is_locked ) && SUCCEED == lld_items_tags_save ( hostid , & items , & host_record_is_locked ) ) { if ( ZBX_DB_OK != DBcommit ( ) ) { ret = FAIL ; goto clean ; } } else { ret = FAIL ; DBrollback ( ) ; goto clean ; } lld_item_links_populate ( & item_prototypes , lld_rows , & items_index ) ; lld_remove_lost_objects ( " " , " " , & items , lifetime , lastcheck , DBdelete_items , get_item_info ) ; clean : zbx_hashset_destroy ( & items_index ) ; zbx_vector_ptr_clear_ext ( & item_dependencies , zbx_ptr_free ) ; zbx_vector_ptr_destroy ( & item_dependencies ) ; zbx_vector_ptr_clear_ext ( & items , ( zbx_clean_func_t ) lld_item_free ) ; zbx_vector_ptr_destroy ( & items ) ; zbx_vector_ptr_clear_ext ( & item_prototypes , ( zbx_clean_func_t ) lld_item_prototype_free ) ; out : zbx_vector_ptr_destroy ( & item_prototypes ) ; zabbix_log ( LOG_LEVEL_DEBUG , " " , __func__ ) ; return ret ; }
Function: lld_update_items                                                 
                                                                            
 Purpose: add or update discovered items                                    
                                                                            
 Return value: SUCCEED - if items were successfully added/updated or        
                         adding/updating was not necessary                  
               FAIL    - items cannot be added/updated
Function : lld_update_items Purpose : add or update discovered items Return value : SUCCEED - if items were successfully added / updated or adding / updating was not necessary FAIL - items cannot be added / updated