zabbix-agent2/src/libs/zbxdbcache/dbsync.c
/******************************************************************************
 *                                                                            *
 * Function: zbx_dbsync_compare_host_inventory                                *
 *                                                                            *
 * Purpose: compares host_inventory table with cached configuration data      *
 *                                                                            *
 * Parameter: sync - [OUT] the changeset                                      *
 *                                                                            *
 * Return value: SUCCEED - the changeset was successfully calculated          *
 *               FAIL    - otherwise                                          *
 *                                                                            *
 ******************************************************************************/
zbx_dbsync_compare_host_inventory

Purpose: compares host_inventory table with cached configuration data

Parameter: sync - [OUT] the changeset

Return value: SUCCEED - the changeset was successfully calculated
FAIL    - otherwise
zbx_dbsync_compare_host_inventory Purpose : compares host_inventory table with cached configuration data Parameter : sync - [ OUT ] the changeset Return value : SUCCEED - the changeset was successfully calculated FAIL - otherwise
int	zbx_dbsync_compare_host_inventory(zbx_dbsync_t *sync)
{
	DB_ROW			dbrow;
	DB_RESULT		result;
	zbx_hashset_t		ids;
	zbx_hashset_iter_t	iter;
	zbx_uint64_t		rowid;
	ZBX_DC_HOST_INVENTORY	*hi;
	const char		*sql;
	sql = "select hostid,inventory_mode,type,type_full,name,alias,os,os_full,os_short,serialno_a,"
			"serialno_b,tag,asset_tag,macaddress_a,macaddress_b,hardware,hardware_full,software,"
			"software_full,software_app_a,software_app_b,software_app_c,software_app_d,"
			"software_app_e,contact,location,location_lat,location_lon,notes,chassis,model,"
			"hw_arch,vendor,contract_number,installer_name,deployment_status,url_a,url_b,"
			"url_c,host_networks,host_netmask,host_router,oob_ip,oob_netmask,oob_router,"
			"date_hw_purchase,date_hw_install,date_hw_expiry,date_hw_decomm,site_address_a,"
			"site_address_b,site_address_c,site_city,site_state,site_country,site_zip,site_rack,"
			"site_notes,poc_1_name,poc_1_email,poc_1_phone_a,poc_1_phone_b,poc_1_cell,"
			"poc_1_screen,poc_1_notes,poc_2_name,poc_2_email,poc_2_phone_a,poc_2_phone_b,"
			"poc_2_cell,poc_2_screen,poc_2_notes"
			" from host_inventory";
	if (NULL == (result = DBselect("%s", sql)))
		return FAIL;
	dbsync_prepare(sync, 72, NULL);
	if (ZBX_DBSYNC_INIT == sync->mode)
	{
		sync->dbresult = result;
		return SUCCEED;
	}
	zbx_hashset_create(&ids, dbsync_env.cache->host_inventories.num_data, ZBX_DEFAULT_UINT64_HASH_FUNC,
			ZBX_DEFAULT_UINT64_COMPARE_FUNC);
	while (NULL != (dbrow = DBfetch(result)))
	{
		unsigned char	tag = ZBX_DBSYNC_ROW_NONE;
		ZBX_STR2UINT64(rowid, dbrow[0]);
		zbx_hashset_insert(&ids, &rowid, sizeof(rowid));
		if (NULL == (hi = (ZBX_DC_HOST_INVENTORY *)zbx_hashset_search(&dbsync_env.cache->host_inventories,
				&rowid)))
		{
			tag = ZBX_DBSYNC_ROW_ADD;
		}
		else if (FAIL == dbsync_compare_host_inventory(hi, dbrow))
			tag = ZBX_DBSYNC_ROW_UPDATE;
		if (ZBX_DBSYNC_ROW_NONE != tag)
			dbsync_add_row(sync, rowid, tag, dbrow);
	}
	zbx_hashset_iter_reset(&dbsync_env.cache->host_inventories, &iter);
	while (NULL != (hi = (ZBX_DC_HOST_INVENTORY *)zbx_hashset_iter_next(&iter)))
	{
		if (NULL == zbx_hashset_search(&ids, &hi->hostid))
			dbsync_add_row(sync, hi->hostid, ZBX_DBSYNC_ROW_REMOVE, NULL);
	}
	zbx_hashset_destroy(&ids);
	DBfree_result(result);
	return SUCCEED;
}
int zbx_dbsync_compare_host_inventory ( zbx_dbsync_t * sync ) { DB_ROW dbrow ; DB_RESULT result ; zbx_hashset_t ids ; zbx_hashset_iter_t iter ; zbx_uint64_t rowid ; ZBX_DC_HOST_INVENTORY * hi ; const char * sql ; sql = " " " " " " " " " " " " " " " " " " " " " " " " ; if ( NULL == ( result = DBselect ( " " , sql ) ) ) return FAIL ; dbsync_prepare ( sync , 72 , NULL ) ; if ( ZBX_DBSYNC_INIT == sync -> mode ) { sync -> dbresult = result ; return SUCCEED ; } zbx_hashset_create ( & ids , dbsync_env . cache -> host_inventories . num_data , ZBX_DEFAULT_UINT64_HASH_FUNC , ZBX_DEFAULT_UINT64_COMPARE_FUNC ) ; while ( NULL != ( dbrow = DBfetch ( result ) ) ) { unsigned char tag = ZBX_DBSYNC_ROW_NONE ; ZBX_STR2UINT64 ( rowid , dbrow [ 0 ] ) ; zbx_hashset_insert ( & ids , & rowid , sizeof ( rowid ) ) ; if ( NULL == ( hi = ( ZBX_DC_HOST_INVENTORY * ) zbx_hashset_search ( & dbsync_env . cache -> host_inventories , & rowid ) ) ) { tag = ZBX_DBSYNC_ROW_ADD ; } else if ( FAIL == dbsync_compare_host_inventory ( hi , dbrow ) ) tag = ZBX_DBSYNC_ROW_UPDATE ; if ( ZBX_DBSYNC_ROW_NONE != tag ) dbsync_add_row ( sync , rowid , tag , dbrow ) ; } zbx_hashset_iter_reset ( & dbsync_env . cache -> host_inventories , & iter ) ; while ( NULL != ( hi = ( ZBX_DC_HOST_INVENTORY * ) zbx_hashset_iter_next ( & iter ) ) ) { if ( NULL == zbx_hashset_search ( & ids , & hi -> hostid ) ) dbsync_add_row ( sync , hi -> hostid , ZBX_DBSYNC_ROW_REMOVE , NULL ) ; } zbx_hashset_destroy ( & ids ) ; DBfree_result ( result ) ; return SUCCEED ; }
Function: zbx_dbsync_compare_host_inventory                                
                                                                            
 Purpose: compares host_inventory table with cached configuration data      
                                                                            
 Parameter: sync - [OUT] the changeset                                      
                                                                            
 Return value: SUCCEED - the changeset was successfully calculated          
               FAIL    - otherwise
Function : zbx_dbsync_compare_host_inventory Purpose : compares host_inventory table with cached configuration data Parameter : sync - [ OUT ] the changeset Return value : SUCCEED - the changeset was successfully calculated FAIL - otherwise