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

Purpose: compares item preproc tables with cached configuration data

Parameter: sync - [OUT] the changeset

Return value: SUCCEED - the changeset was successfully calculated
FAIL    - otherwise
zbx_dbsync_compare_item_preprocessing Purpose : compares item preproc tables with cached configuration data Parameter : sync - [ OUT ] the changeset Return value : SUCCEED - the changeset was successfully calculated FAIL - otherwise
int	zbx_dbsync_compare_item_preprocs(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_preproc_op_t	*preproc;
	char			**row;
	if (NULL == (result = DBselect(
			"select pp.item_preprocid,pp.itemid,pp.type,pp.params,pp.step,i.hostid,pp.error_handler,"
				"pp.error_handler_params,i.type,i.key_,h.proxy_hostid"
			" from item_preproc pp,items i,hosts h"
			" where pp.itemid=i.itemid"
				" and i.hostid=h.hostid"
				" and (h.proxy_hostid is null"
					" or i.type in (%d,%d,%d))"
				" and h.status in (%d,%d)"
				" and i.flags<>%d"
			" order by pp.itemid",
			ITEM_TYPE_INTERNAL, ITEM_TYPE_CALCULATED, ITEM_TYPE_DEPENDENT,
			HOST_STATUS_MONITORED, HOST_STATUS_NOT_MONITORED,
			ZBX_FLAG_DISCOVERY_PROTOTYPE)))
	{
		return FAIL;
	}
	dbsync_prepare(sync, 8, dbsync_item_pp_preproc_row);
	if (ZBX_DBSYNC_INIT == sync->mode)
	{
		sync->dbresult = result;
		return SUCCEED;
	}
	zbx_hashset_create(&ids, dbsync_env.cache->hostgroups.num_data, ZBX_DEFAULT_UINT64_HASH_FUNC,
			ZBX_DEFAULT_UINT64_COMPARE_FUNC);
	while (NULL != (dbrow = DBfetch(result)))
	{
		unsigned char	tag = ZBX_DBSYNC_ROW_NONE;
		unsigned char	type;
		ZBX_STR2UCHAR(type, dbrow[8]);
		if (type != ITEM_TYPE_DEPENDENT && SUCCEED != DBis_null(dbrow[10]) &&
				SUCCEED != is_item_processed_by_server(type, dbrow[9]))
		{
			continue;
		}
		ZBX_STR2UINT64(rowid, dbrow[0]);
		zbx_hashset_insert(&ids, &rowid, sizeof(rowid));
		row = dbsync_preproc_row(sync, dbrow);
		if (NULL == (preproc = (zbx_dc_preproc_op_t *)zbx_hashset_search(&dbsync_env.cache->preprocops,
				&rowid)))
		{
			tag = ZBX_DBSYNC_ROW_ADD;
		}
		else if (FAIL == dbsync_compare_item_preproc(preproc, row))
			tag = ZBX_DBSYNC_ROW_UPDATE;
		if (ZBX_DBSYNC_ROW_NONE != tag)
			dbsync_add_row(sync, rowid, tag, row);
	}
	zbx_hashset_iter_reset(&dbsync_env.cache->preprocops, &iter);
	while (NULL != (preproc = (zbx_dc_preproc_op_t *)zbx_hashset_iter_next(&iter)))
	{
		if (NULL == zbx_hashset_search(&ids, &preproc->item_preprocid))
			dbsync_add_row(sync, preproc->item_preprocid, ZBX_DBSYNC_ROW_REMOVE, NULL);
	}
	zbx_hashset_destroy(&ids);
	DBfree_result(result);
	return SUCCEED;
}
int zbx_dbsync_compare_item_preprocs ( 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_preproc_op_t * preproc ; char * * row ; if ( NULL == ( result = DBselect ( " " " " " " " " " " " " " " " " " " " " , ITEM_TYPE_INTERNAL , ITEM_TYPE_CALCULATED , ITEM_TYPE_DEPENDENT , HOST_STATUS_MONITORED , HOST_STATUS_NOT_MONITORED , ZBX_FLAG_DISCOVERY_PROTOTYPE ) ) ) { return FAIL ; } dbsync_prepare ( sync , 8 , dbsync_item_pp_preproc_row ) ; if ( ZBX_DBSYNC_INIT == sync -> mode ) { sync -> dbresult = result ; return SUCCEED ; } zbx_hashset_create ( & ids , dbsync_env . cache -> hostgroups . num_data , ZBX_DEFAULT_UINT64_HASH_FUNC , ZBX_DEFAULT_UINT64_COMPARE_FUNC ) ; while ( NULL != ( dbrow = DBfetch ( result ) ) ) { unsigned char tag = ZBX_DBSYNC_ROW_NONE ; unsigned char type ; ZBX_STR2UCHAR ( type , dbrow [ 8 ] ) ; if ( type != ITEM_TYPE_DEPENDENT && SUCCEED != DBis_null ( dbrow [ 10 ] ) && SUCCEED != is_item_processed_by_server ( type , dbrow [ 9 ] ) ) { continue ; } ZBX_STR2UINT64 ( rowid , dbrow [ 0 ] ) ; zbx_hashset_insert ( & ids , & rowid , sizeof ( rowid ) ) ; row = dbsync_preproc_row ( sync , dbrow ) ; if ( NULL == ( preproc = ( zbx_dc_preproc_op_t * ) zbx_hashset_search ( & dbsync_env . cache -> preprocops , & rowid ) ) ) { tag = ZBX_DBSYNC_ROW_ADD ; } else if ( FAIL == dbsync_compare_item_preproc ( preproc , row ) ) tag = ZBX_DBSYNC_ROW_UPDATE ; if ( ZBX_DBSYNC_ROW_NONE != tag ) dbsync_add_row ( sync , rowid , tag , row ) ; } zbx_hashset_iter_reset ( & dbsync_env . cache -> preprocops , & iter ) ; while ( NULL != ( preproc = ( zbx_dc_preproc_op_t * ) zbx_hashset_iter_next ( & iter ) ) ) { if ( NULL == zbx_hashset_search ( & ids , & preproc -> item_preprocid ) ) dbsync_add_row ( sync , preproc -> item_preprocid , ZBX_DBSYNC_ROW_REMOVE , NULL ) ; } zbx_hashset_destroy ( & ids ) ; DBfree_result ( result ) ; return SUCCEED ; }
Function: zbx_dbsync_compare_item_preprocessing                            
                                                                            
 Purpose: compares item preproc tables with cached configuration data       
                                                                            
 Parameter: sync - [OUT] the changeset                                      
                                                                            
 Return value: SUCCEED - the changeset was successfully calculated          
               FAIL    - otherwise
Function : zbx_dbsync_compare_item_preprocessing Purpose : compares item preproc tables with cached configuration data Parameter : sync - [ OUT ] the changeset Return value : SUCCEED - the changeset was successfully calculated FAIL - otherwise
/* Sync preproccessing for all dependent items as they can depend on item processed by Zabbx server, */ /* avoid syncing preprocessing for internal items monitored by Zabbix proxy                          */