zabbix-agent2/src/libs/zbxdbupgrade/dbupgrade_4050.c
/******************************************************************************
 *                                                                            *
 * Function: DBpatch_load_data                                                *
 *                                                                            *
 * Purpose: loading a set of unique combination of snmp data within a single  *
 *          interface and associated interface data                           *
 *                                                                            *
 * Parameters: snmp_ifs     - [OUT] snmp data linked with existing interfaces *
 *             new_ifs      - [OUT] new interfaces for snmp data              *
 *             snmp_new_ifs - [OUT] snmp data associated with new interfaces  *
 *                                                                            *
 ******************************************************************************/
DBpatch_load_data

Purpose: loading a set of unique combination of snmp data within a single
interface and associated interface data

Parameters: snmp_ifs     - [OUT] snmp data linked with existing interfaces
new_ifs      - [OUT] new interfaces for snmp data
snmp_new_ifs - [OUT] snmp data associated with new interfaces
DBpatch_load_data Purpose : loading a set of unique combination of snmp data within a single interface and associated interface data Parameters : snmp_ifs - [ OUT ] snmp data linked with existing interfaces new_ifs - [ OUT ] new interfaces for snmp data snmp_new_ifs - [ OUT ] snmp data associated with new interfaces
static void	DBpatch_load_data(zbx_vector_dbu_snmp_if_t *snmp_ifs, zbx_vector_dbu_interface_t *new_ifs,
		zbx_vector_dbu_snmp_if_t *snmp_new_ifs)
{
#define ITEM_TYPE_SNMPv1	1
#define ITEM_TYPE_SNMPv2c	4
#define ITEM_TYPE_SNMPv3	6
	DB_RESULT	result;
	DB_ROW		row;
	int		index;
	result = DBselect(
			"select distinct "
				"i.interfaceid,"
				"i.type,"
				"f.bulk,"
				"i.snmp_community,"
				"i.snmpv3_securityname,"
				"i.snmpv3_securitylevel,"
				"i.snmpv3_authpassphrase,"
				"i.snmpv3_privpassphrase,"
				"i.snmpv3_authprotocol,"
				"i.snmpv3_privprotocol,"
				"i.snmpv3_contextname,"
				"i.port,"
				"i.hostid,"
				"f.type,"
				"f.useip,"
				"f.ip,"
				"f.dns,"
				"f.port"
			" from items i"
				" join hosts h on i.hostid=h.hostid"
				" join interface f on i.interfaceid=f.interfaceid"
			" where i.type in (%d,%d,%d)"
				" and h.status in (0,1)"
			" order by i.interfaceid asc,i.type asc,i.port asc,i.snmp_community asc",
			ITEM_TYPE_SNMPv1, ITEM_TYPE_SNMPv2c, ITEM_TYPE_SNMPv3);
	while (NULL != (row = DBfetch(result)))
	{
		dbu_interface_t	interface;
		dbu_snmp_if_t	snmp;
		unsigned char	item_type;
		const char 	*if_port;
		ZBX_DBROW2UINT64(snmp.item_interfaceid, row[0]);
		ZBX_STR2UCHAR(item_type, row[1]);
		ZBX_STR2UCHAR(snmp.bulk, row[2]);
		snmp.community = zbx_strdup(NULL, row[3]);
		snmp.securityname = zbx_strdup(NULL, row[4]);
		ZBX_STR2UCHAR(snmp.securitylevel, row[5]);
		snmp.authpassphrase = zbx_strdup(NULL, row[6]);
		snmp.privpassphrase = zbx_strdup(NULL, row[7]);
		ZBX_STR2UCHAR(snmp.authprotocol, row[8]);
		ZBX_STR2UCHAR(snmp.privprotocol, row[9]);
		snmp.contextname = zbx_strdup(NULL, row[10]);
		snmp.item_port = zbx_strdup(NULL, row[11]);
		snmp.skip = 0;
		if_port = row[17];
		if (ITEM_TYPE_SNMPv1 == item_type)
			snmp.version = ZBX_IF_SNMP_VERSION_1;
		else if (ITEM_TYPE_SNMPv2c == item_type)
			snmp.version = ZBX_IF_SNMP_VERSION_2;
		else
			snmp.version = ZBX_IF_SNMP_VERSION_3;
		snmp.interfaceid = snmp.item_interfaceid;
		index = FAIL;
		if (('\0' == *snmp.item_port || 0 == strcmp(snmp.item_port, if_port)) &&
				FAIL == (index = zbx_vector_dbu_snmp_if_bsearch(snmp_ifs, snmp,
						ZBX_DEFAULT_UINT64_COMPARE_FUNC)))
		{
			zbx_vector_dbu_snmp_if_append(snmp_ifs, snmp);
			continue;
		}
		else if (FAIL != index && 0 == db_snmp_if_newid_cmp(&snmp_ifs->values[index], &snmp))
		{
			db_snmpinterface_free(snmp);
			continue;
		}
		else if (0 < snmp_new_ifs->values_num &&
				FAIL != (index = db_snmp_new_if_find(&snmp, snmp_new_ifs, new_ifs, if_port)))
		{
			snmp.skip = 1;
			snmp.interfaceid = snmp_new_ifs->values[index].interfaceid;
			zbx_vector_dbu_snmp_if_append(snmp_new_ifs, snmp);
			continue;
		}
		snmp.interfaceid = DBget_maxid("interface");
		zbx_vector_dbu_snmp_if_append(snmp_new_ifs, snmp);
		interface.interfaceid = snmp.interfaceid;
		ZBX_DBROW2UINT64(interface.hostid, row[12]);
		interface.main = 0;
		ZBX_STR2UCHAR(interface.type, row[13]);
		ZBX_STR2UCHAR(interface.useip, row[14]);
		interface.ip = zbx_strdup(NULL, row[15]);
		interface.dns = zbx_strdup(NULL, row[16]);
		if ('\0' != *snmp.item_port)
			interface.port = zbx_strdup(NULL, snmp.item_port);
		else
			interface.port = zbx_strdup(NULL, if_port);
		zbx_vector_dbu_interface_append(new_ifs, interface);
	}
	DBfree_result(result);
#undef ITEM_TYPE_SNMPv1
#undef ITEM_TYPE_SNMPv2c
#undef ITEM_TYPE_SNMPv3
}
static void DBpatch_load_data ( zbx_vector_dbu_snmp_if_t * snmp_ifs , zbx_vector_dbu_interface_t * new_ifs , zbx_vector_dbu_snmp_if_t * snmp_new_ifs ) { #define ITEM_TYPE_SNMPv1 	1
 #define ITEM_TYPE_SNMPv2c 	4
 #define ITEM_TYPE_SNMPv3 	6
 DB_RESULT result ; DB_ROW row ; int index ; result = DBselect ( " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " , ITEM_TYPE_SNMPv1 , ITEM_TYPE_SNMPv2c , ITEM_TYPE_SNMPv3 ) ; while ( NULL != ( row = DBfetch ( result ) ) ) { dbu_interface_t interface ; dbu_snmp_if_t snmp ; unsigned char item_type ; const char * if_port ; ZBX_DBROW2UINT64 ( snmp . item_interfaceid , row [ 0 ] ) ; ZBX_STR2UCHAR ( item_type , row [ 1 ] ) ; ZBX_STR2UCHAR ( snmp . bulk , row [ 2 ] ) ; snmp . community = zbx_strdup ( NULL , row [ 3 ] ) ; snmp . securityname = zbx_strdup ( NULL , row [ 4 ] ) ; ZBX_STR2UCHAR ( snmp . securitylevel , row [ 5 ] ) ; snmp . authpassphrase = zbx_strdup ( NULL , row [ 6 ] ) ; snmp . privpassphrase = zbx_strdup ( NULL , row [ 7 ] ) ; ZBX_STR2UCHAR ( snmp . authprotocol , row [ 8 ] ) ; ZBX_STR2UCHAR ( snmp . privprotocol , row [ 9 ] ) ; snmp . contextname = zbx_strdup ( NULL , row [ 10 ] ) ; snmp . item_port = zbx_strdup ( NULL , row [ 11 ] ) ; snmp . skip = 0 ; if_port = row [ 17 ] ; if ( ITEM_TYPE_SNMPv1 == item_type ) snmp . version = ZBX_IF_SNMP_VERSION_1 ; else if ( ITEM_TYPE_SNMPv2c == item_type ) snmp . version = ZBX_IF_SNMP_VERSION_2 ; else snmp . version = ZBX_IF_SNMP_VERSION_3 ; snmp . interfaceid = snmp . item_interfaceid ; index = FAIL ; if ( ( ' \0 ' == * snmp . item_port || 0 == strcmp ( snmp . item_port , if_port ) ) && FAIL == ( index = zbx_vector_dbu_snmp_if_bsearch ( snmp_ifs , snmp , ZBX_DEFAULT_UINT64_COMPARE_FUNC ) ) ) { zbx_vector_dbu_snmp_if_append ( snmp_ifs , snmp ) ; continue ; } else if ( FAIL != index && 0 == db_snmp_if_newid_cmp ( & snmp_ifs -> values [ index ] , & snmp ) ) { db_snmpinterface_free ( snmp ) ; continue ; } else if ( 0 < snmp_new_ifs -> values_num && FAIL != ( index = db_snmp_new_if_find ( & snmp , snmp_new_ifs , new_ifs , if_port ) ) ) { snmp . skip = 1 ; snmp . interfaceid = snmp_new_ifs -> values [ index ] . interfaceid ; zbx_vector_dbu_snmp_if_append ( snmp_new_ifs , snmp ) ; continue ; } snmp . interfaceid = DBget_maxid ( " " ) ; zbx_vector_dbu_snmp_if_append ( snmp_new_ifs , snmp ) ; interface . interfaceid = snmp . interfaceid ; ZBX_DBROW2UINT64 ( interface . hostid , row [ 12 ] ) ; interface . main = 0 ; ZBX_STR2UCHAR ( interface . type , row [ 13 ] ) ; ZBX_STR2UCHAR ( interface . useip , row [ 14 ] ) ; interface . ip = zbx_strdup ( NULL , row [ 15 ] ) ; interface . dns = zbx_strdup ( NULL , row [ 16 ] ) ; if ( ' \0 ' != * snmp . item_port ) interface . port = zbx_strdup ( NULL , snmp . item_port ) ; else interface . port = zbx_strdup ( NULL , if_port ) ; zbx_vector_dbu_interface_append ( new_ifs , interface ) ; } DBfree_result ( result ) ; #undef  ITEM_TYPE_SNMPv1
 #undef  ITEM_TYPE_SNMPv2c
 #undef  ITEM_TYPE_SNMPv3
 }
Function: DBpatch_load_data                                                
                                                                            
 Purpose: loading a set of unique combination of snmp data within a single  
          interface and associated interface data                           
                                                                            
 Parameters: snmp_ifs     - [OUT] snmp data linked with existing interfaces 
             new_ifs      - [OUT] new interfaces for snmp data              
             snmp_new_ifs - [OUT] snmp data associated with new interfaces
Function : DBpatch_load_data Purpose : loading a set of unique combination of snmp data within a single interface and associated interface data Parameters : snmp_ifs - [ OUT ] snmp data linked with existing interfaces new_ifs - [ OUT ] new interfaces for snmp data snmp_new_ifs - [ OUT ] snmp data associated with new interfaces