zabbix-agent2/src/libs/zbxdbcache/dbconfig.c
/*********************************************************************************
 *                                                                               *
 * Function: DCreset_interfaces_availability                                     *
 *                                                                               *
 * Purpose: resets interfaces availability for disabled hosts and hosts          *
 *          without enabled items for the corresponding interface                *
 *                                                                               *
 * Parameters: interfaces - [OUT] changed interface availability data            *
 *                                                                               *
 * Return value: SUCCEED - interface availability was reset for at least one     *
 *                         interface                                             *
 *               FAIL    - no interfaces required availability reset             *
 *                                                                               *
 * Comments: This function resets interface availability in configuration cache. *
 *           The caller must perform corresponding database updates based on     *
 *           returned interface availability reset data. On server the function  *
 *           skips hosts handled by proxies.                                     *
 *                                                                               *
 ********************************************************************************/
DCreset_interfaces_availability

Purpose: resets interfaces availability for disabled hosts and hosts
without enabled items for the corresponding interface

Parameters: interfaces - [OUT] changed interface availability data

Return value: SUCCEED - interface availability was reset for at least one
interface
FAIL    - no interfaces required availability reset

Comments: This function resets interface availability in configuration cache.
The caller must perform corresponding database updates based on
returned interface availability reset data. On server the function
skips hosts handled by proxies.
DCreset_interfaces_availability Purpose : resets interfaces availability for disabled hosts and hosts without enabled items for the corresponding interface Parameters : interfaces - [ OUT ] changed interface availability data Return value : SUCCEED - interface availability was reset for at least one interface FAIL - no interfaces required availability reset Comments : This function resets interface availability in configuration cache . The caller must perform corresponding database updates based on returned interface availability reset data . On server the function skips hosts handled by proxies .
int	DCreset_interfaces_availability(zbx_vector_availability_ptr_t *interfaces)
{
	ZBX_DC_HOST			*host;
	ZBX_DC_INTERFACE		*interface;
	zbx_hashset_iter_t		iter;
	zbx_interface_availability_t	*ia = NULL;
	int				now;
	zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
	now = time(NULL);
	WRLOCK_CACHE;
	zbx_hashset_iter_reset(&config->interfaces, &iter);
	while (NULL != (interface = (ZBX_DC_INTERFACE *)zbx_hashset_iter_next(&iter)))
	{
		int	items_num = 0;
		if (NULL == (host = (ZBX_DC_HOST *)zbx_hashset_search(&config->hosts, &interface->hostid)))
			continue;
		if (0 == interface->reset_availability &&
				0 != (program_type & ZBX_PROGRAM_TYPE_SERVER) && 0 != host->proxy_hostid)
		{
			ZBX_DC_PROXY	*proxy;
			if (NULL != (proxy = (ZBX_DC_PROXY *)zbx_hashset_search(&config->proxies, &host->proxy_hostid)))
			{
				if (ZBX_PROXY_HEARTBEAT_FREQUENCY_MAX + SEC_PER_MIN >= now - proxy->lastaccess)
					continue;
			}
			interface->reset_availability = 1;
		}
		if (NULL == ia)
			ia = (zbx_interface_availability_t *)zbx_malloc(NULL, sizeof(zbx_interface_availability_t));
		zbx_interface_availability_init(ia, interface->interfaceid);
		if (0 == interface->reset_availability)
			items_num = interface->items_num;
		if (0 == items_num && INTERFACE_AVAILABLE_UNKNOWN != interface->available)
			zbx_agent_availability_init(&ia->agent, INTERFACE_AVAILABLE_UNKNOWN, "", 0, 0);
		if (SUCCEED == zbx_interface_availability_is_set(ia))
		{
			if (SUCCEED == DCinterface_set_availability(interface, now, ia))
			{
				zbx_vector_availability_ptr_append(interfaces, ia);
				ia = NULL;
			}
			else
				zbx_interface_availability_clean(ia);
		}
		interface->reset_availability = 0;
	}
	UNLOCK_CACHE;
	zbx_free(ia);
	zbx_vector_availability_ptr_sort(interfaces, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
	zabbix_log(LOG_LEVEL_DEBUG, "End of %s() interfaces:%d", __func__, interfaces->values_num);
	return 0 == interfaces->values_num ? FAIL : SUCCEED;
}
int DCreset_interfaces_availability ( zbx_vector_availability_ptr_t * interfaces ) { ZBX_DC_HOST * host ; ZBX_DC_INTERFACE * interface ; zbx_hashset_iter_t iter ; zbx_interface_availability_t * ia = NULL ; int now ; zabbix_log ( LOG_LEVEL_DEBUG , " " , __func__ ) ; now = time ( NULL ) ; WRLOCK_CACHE ; zbx_hashset_iter_reset ( & config -> interfaces , & iter ) ; while ( NULL != ( interface = ( ZBX_DC_INTERFACE * ) zbx_hashset_iter_next ( & iter ) ) ) { int items_num = 0 ; if ( NULL == ( host = ( ZBX_DC_HOST * ) zbx_hashset_search ( & config -> hosts , & interface -> hostid ) ) ) continue ; if ( 0 == interface -> reset_availability && 0 != ( program_type & ZBX_PROGRAM_TYPE_SERVER ) && 0 != host -> proxy_hostid ) { ZBX_DC_PROXY * proxy ; if ( NULL != ( proxy = ( ZBX_DC_PROXY * ) zbx_hashset_search ( & config -> proxies , & host -> proxy_hostid ) ) ) { if ( ZBX_PROXY_HEARTBEAT_FREQUENCY_MAX + SEC_PER_MIN >= now - proxy -> lastaccess ) continue ; } interface -> reset_availability = 1 ; } if ( NULL == ia ) ia = ( zbx_interface_availability_t * ) zbx_malloc ( NULL , sizeof ( zbx_interface_availability_t ) ) ; zbx_interface_availability_init ( ia , interface -> interfaceid ) ; if ( 0 == interface -> reset_availability ) items_num = interface -> items_num ; if ( 0 == items_num && INTERFACE_AVAILABLE_UNKNOWN != interface -> available ) zbx_agent_availability_init ( & ia -> agent , INTERFACE_AVAILABLE_UNKNOWN , " " , 0 , 0 ) ; if ( SUCCEED == zbx_interface_availability_is_set ( ia ) ) { if ( SUCCEED == DCinterface_set_availability ( interface , now , ia ) ) { zbx_vector_availability_ptr_append ( interfaces , ia ) ; ia = NULL ; } else zbx_interface_availability_clean ( ia ) ; } interface -> reset_availability = 0 ; } UNLOCK_CACHE ; zbx_free ( ia ) ; zbx_vector_availability_ptr_sort ( interfaces , ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC ) ; zabbix_log ( LOG_LEVEL_DEBUG , " " , __func__ , interfaces -> values_num ) ; return 0 == interfaces -> values_num ? FAIL : SUCCEED ; }
Function: DCreset_interfaces_availability                                     
                                                                               
 Purpose: resets interfaces availability for disabled hosts and hosts          
          without enabled items for the corresponding interface                
                                                                               
 Parameters: interfaces - [OUT] changed interface availability data            
                                                                               
 Return value: SUCCEED - interface availability was reset for at least one     
                         interface                                             
               FAIL    - no interfaces required availability reset             
                                                                               
 Comments: This function resets interface availability in configuration cache.
Function : DCreset_interfaces_availability Purpose : resets interfaces availability for disabled hosts and hosts without enabled items for the corresponding interface Parameters : interfaces - [ OUT ] changed interface availability data Return value : SUCCEED - interface availability was reset for at least one interface FAIL - no interfaces required availability reset Comments : This function resets interface availability in configuration cache .
/* On server skip hosts handled by proxies. They are handled directly */ /* when receiving hosts' availability data from proxies.              */ /* Unless a host was just (re)assigned to a proxy or the proxy has    */ /* not updated its status during the maximum proxy heartbeat period.  */ /* In this case reset all interfaces to unknown status.               */ /* SEC_PER_MIN is a tolerance interval, it was chosen arbitrarily */