zabbix-agent2/src/zabbix_server/service/service_manager.c
/******************************************************************************
 *                                                                            *
 * Function: db_manage_service_events                                         *
 *                                                                            *
 * Purpose: generate and process service events in response to service        *
 *          updates                                                           *
 *                                                                            *
 ******************************************************************************/
db_manage_service_events

Purpose: generate and process service events in response to service
updates
db_manage_service_events Purpose : generate and process service events in response to service updates
static void	db_manage_service_events(zbx_service_manager_t *manager, zbx_hashset_t *service_updates)
{
	zbx_hashset_iter_t	iter;
	zbx_service_update_t	*update;
	zbx_vector_ptr_t	events_create, events_resolve, events_update;
	zbx_vector_ptr_create(&events_create);
	zbx_vector_ptr_create(&events_resolve);
	zbx_vector_ptr_create(&events_update);
	zbx_hashset_iter_reset(service_updates, &iter);
	while (NULL != (update = (zbx_service_update_t *)zbx_hashset_iter_next(&iter)))
	{
		if (update->old_status == update->service->status)
			continue;
		if (ZBX_SERVICE_STATUS_OK != update->service->status)
		{
			if (ZBX_SERVICE_STATUS_OK == update->old_status)
				zbx_vector_ptr_append(&events_create, update);
			else
				zbx_vector_ptr_append(&events_update, update);
		}
		else
			zbx_vector_ptr_append(&events_resolve, update);
	}
	if (0 != events_create.values_num)
		db_create_service_events(manager, &events_create);
	if (0 != events_resolve.values_num)
		db_resolve_service_events(manager, &events_resolve);
	if (0 != events_update.values_num)
		db_update_service_events(manager, &events_update);
	zbx_vector_ptr_destroy(&events_update);
	zbx_vector_ptr_destroy(&events_resolve);
	zbx_vector_ptr_destroy(&events_create);
}
static void db_manage_service_events ( zbx_service_manager_t * manager , zbx_hashset_t * service_updates ) { zbx_hashset_iter_t iter ; zbx_service_update_t * update ; zbx_vector_ptr_t events_create , events_resolve , events_update ; zbx_vector_ptr_create ( & events_create ) ; zbx_vector_ptr_create ( & events_resolve ) ; zbx_vector_ptr_create ( & events_update ) ; zbx_hashset_iter_reset ( service_updates , & iter ) ; while ( NULL != ( update = ( zbx_service_update_t * ) zbx_hashset_iter_next ( & iter ) ) ) { if ( update -> old_status == update -> service -> status ) continue ; if ( ZBX_SERVICE_STATUS_OK != update -> service -> status ) { if ( ZBX_SERVICE_STATUS_OK == update -> old_status ) zbx_vector_ptr_append ( & events_create , update ) ; else zbx_vector_ptr_append ( & events_update , update ) ; } else zbx_vector_ptr_append ( & events_resolve , update ) ; } if ( 0 != events_create . values_num ) db_create_service_events ( manager , & events_create ) ; if ( 0 != events_resolve . values_num ) db_resolve_service_events ( manager , & events_resolve ) ; if ( 0 != events_update . values_num ) db_update_service_events ( manager , & events_update ) ; zbx_vector_ptr_destroy ( & events_update ) ; zbx_vector_ptr_destroy ( & events_resolve ) ; zbx_vector_ptr_destroy ( & events_create ) ; }
Function: db_manage_service_events                                         
                                                                            
 Purpose: generate and process service events in response to service        
          updates
Function : db_manage_service_events Purpose : generate and process service events in response to service updates