def dashboard_share_apiKey(dashboard_slug): """ get a dashboard's apikey. :param dashboard_slug: The slug of the dashboard to share. :>json api_key: The API key to use when accessing it. """ current_org = models.Organization.get_by_slug('default') dashboard = models.Dashboard.get_by_slug_and_org(dashboard_slug, current_org) api_key = models.ApiKey.get_by_object(dashboard) if api_key: return json_response({'api_key': api_key.api_key}) else: return json_response({'api_key': 'None'})
def outdated_queries(): manager_status = redis_connection.hgetall('redash:status') query_ids = json.loads(manager_status.get('query_ids', '[]')) if query_ids: outdated_queries = (models.db.session.query( models.Query).outerjoin(models.QueryResult).filter( models.Query.id.in_(query_ids)).order_by( models.Query.created_at.desc())) else: outdated_queries = [] record_event( current_org, current_user, { 'action': 'view', 'object_type': 'api_call', 'object_id': 'admin/outdated_queries', 'timestamp': int(time.time()), }) return json_response( dict(queries=[ q.to_dict(with_stats=True, with_last_modified_by=False) for q in outdated_queries ], updated_at=manager_status['last_refresh_at']))
def session(org_slug=None): if (current_user.is_api_user()): user = {'permissions': [], 'apiKey': current_user.id} else: try: myid = current_user.id user = { 'profile_image_url': current_user.profile_image_url, 'id': current_user.id, 'name': current_user.name, 'email': current_user.email, 'groups': current_user.group_ids, 'permissions': current_user.permissions } except: myid = 1987 name = "anonymous" email = "*****@*****.**" permissions = ["anonymous", "edit_query", "execute_query"] user = { 'id': myid, 'name': name, 'email': email, 'permissions': permissions } return json_response({ 'user': user, 'org_slug': current_org.slug, 'client_config': client_config() })
def outdated_queries(): ### redis-----hash get all manager_status = redis_connection.hgetall( 'redash:status' ) # "Return a Python dict of the hash's name/value pairs" query_ids = json.loads(manager_status.get( 'query_ids', '[]')) # redis Hash结构里 嵌套了一个list,被json序列化为了字符串 if query_ids: ###用的了 in_ 和 order_by 和 desc , outerJoin # https://www.xncoding.com/2016/03/07/python/sqlalchemy02.html # 定义好了外键,系统就知道如何去关联 outdated_queries = (models.db.session.query( models.Query).outerjoin(models.QueryResult).filter( models.Query.id.in_(query_ids)).order_by( models.Query.created_at.desc())) else: outdated_queries = [] return json_response( dict(queries=[ q.to_dict(with_stats=True, with_last_modified_by=False) for q in outdated_queries ], updated_at=manager_status['last_refresh_at']))
def outdated_queries(): manager_status = redis_connection.hgetall("redash:status") query_ids = json_loads(manager_status.get("query_ids", "[]")) if query_ids: outdated_queries = (models.Query.query.outerjoin( models.QueryResult).filter( models.Query.id.in_(query_ids)).order_by( models.Query.created_at.desc())) else: outdated_queries = [] record_event( current_org, current_user._get_current_object(), { "action": "list", "object_type": "outdated_queries", }, ) response = { "queries": QuerySerializer(outdated_queries, with_stats=True, with_last_modified_by=False).serialize(), "updated_at": manager_status["last_refresh_at"], } return json_response(response)
def query_results(): logging.info("entered to /api/public/query_results") """ Execute a query (or retrieve recent results). :qparam string query: The query text to execute :qparam number query_id: The query object to update with the result (optional) :qparam number max_age: If query results less than `max_age` seconds old are available, return them, otherwise execute the query; if omitted, always execute :qparam number data_source_id: ID of data source to query """ params = request.get_json(force=True) parameter_values = collect_parameters_from_request(request.args) query = params['query'] max_age = int(params.get('max_age', -1)) query_id = params.get('query_id', 'adhoc') data_source = models.DataSource.get_by_id_and_org( params.get('data_source_id'), current_org) # self.record_event({ # 'action': 'execute_query', # 'timestamp': int(time.time()), # 'object_id': data_source.id, # 'object_type': 'data_source', # 'query': query # }) result = run_query(data_source, parameter_values, query, query_id, max_age) return json_response(result)
def verification_email(org_slug=None): if not current_user.is_email_verified: send_verify_email(current_user, current_org) return json_response({ "message": "Please check your email inbox in order to verify your email address." })
def public_widget(widget_id): logging.debug( "/api/public/widgets/<widget_id> - WidgetResource/public_widget(id)") widget = get_object_or_404(models.Widget.get_by_id, widget_id) response = serialize_widget(widget) return json_response(response)
def queries_rq_status(): record_event(current_org, current_user._get_current_object(), { 'action': 'list', 'object_type': 'rq_status' }) return json_response(rq_status())
def outdated_queries(): manager_status = redis_connection.hgetall('redash:status') query_ids = json_loads(manager_status.get('query_ids', '[]')) if query_ids: outdated_queries = ( models.Query.query.outerjoin(models.QueryResult) .filter(models.Query.id.in_(query_ids)) .order_by(models.Query.created_at.desc()) ) else: outdated_queries = [] record_event(current_org, current_user._get_current_object(), { 'action': 'list', 'object_type': 'outdated_queries', }) updated_at = None if manager_status and manager_status['last_refresh_at']: updated_at = manager_status['last_refresh_at'] response = { 'queries': QuerySerializer(outdated_queries, with_stats=True, with_last_modified_by=False).serialize(), 'updated_at': updated_at, } return json_response(response)
def queries_tasks(): global_limit = int(request.args.get('limit', 50)) waiting_limit = int(request.args.get('waiting_limit', global_limit)) progress_limit = int(request.args.get('progress_limit', global_limit)) done_limit = int(request.args.get('done_limit', global_limit)) waiting = QueryTaskTracker.all(QueryTaskTracker.WAITING_LIST, limit=waiting_limit) in_progress = QueryTaskTracker.all(QueryTaskTracker.IN_PROGRESS_LIST, limit=progress_limit) done = QueryTaskTracker.all(QueryTaskTracker.DONE_LIST, limit=done_limit) record_event( current_org, current_user, { 'action': 'view', 'object_type': 'api_call', 'object_id': 'admin/tasks', 'timestamp': int(time.time()), }) response = { 'waiting': [t.data for t in waiting if t is not None], 'in_progress': [t.data for t in in_progress if t is not None], 'done': [t.data for t in done if t is not None] } return json_response(response)
def queries_rq_status(): record_event( current_org, current_user._get_current_object(), {"action": "list", "object_type": "rq_status"}, ) return json_response(rq_status())
def organization_status(org_slug=None): counters = { 'users': models.User.query.count(), 'alerts': models.Alert.query.count(), 'data_sources': models.DataSource.query.count(), 'queries': models.Query.query.filter(models.Query.is_archived==False).count(), 'dashboards': models.Dashboard.query.filter(models.Dashboard.is_archived==False).count(), } return json_response(dict(object_counters=counters))
def organization_status(org_slug=None): counters = { 'users': models.User.all(current_org).count(), 'alerts': models.Alert.all(group_ids=current_user.group_ids).count(), 'data_sources': models.DataSource.all(current_org, group_ids=current_user.group_ids).count(), 'queries': models.Query.all_queries(current_user.group_ids, current_user.id, drafts=True).count(), 'dashboards': models.Dashboard.all(current_org, current_user.group_ids, current_user.id).count(), } return json_response(dict(object_counters=counters))
def organization_status(org_slug=None): counters = { 'users': models.User.all(current_org).count(), 'alerts': models.Alert.all(group_ids=current_user.group_ids).count(), 'data_sources': models.DataSource.all(current_org, group_ids=current_user.group_ids).count(), 'queries': models.Query.all_queries(current_user.group_ids, current_user.id, include_drafts=True).count(), 'dashboards': models.Dashboard.query.filter(models.Dashboard.org==current_org, models.Dashboard.is_archived==False).count(), } return json_response(dict(object_counters=counters))
def queries_tasks(): record_event(current_org, current_user._get_current_object(), { 'action': 'list', 'object_type': 'celery_tasks' }) response = { 'tasks': celery_tasks(), } return json_response(response)
def queries_tasks(): waiting = QueryTaskTracker.all(QueryTaskTracker.WAITING_LIST) in_progress = QueryTaskTracker.all(QueryTaskTracker.IN_PROGRESS_LIST) done = QueryTaskTracker.all(QueryTaskTracker.DONE_LIST, limit=50) response = { 'waiting': [t.data for t in waiting], 'in_progress': [t.data for t in in_progress], 'done': [t.data for t in done] } return json_response(response)
def outdated_queries(): manager_status = redis_connection.hgetall('redash:status') query_ids = json.loads(manager_status.get('query_ids', '[]')) if query_ids: outdated_queries = models.Query.select(models.Query, models.QueryResult.retrieved_at, models.QueryResult.runtime) \ .join(models.QueryResult, join_type=models.peewee.JOIN_LEFT_OUTER) \ .where(models.Query.id << query_ids) \ .order_by(models.Query.created_at.desc()) else: outdated_queries = [] return json_response(dict(queries=[q.to_dict(with_stats=True, with_last_modified_by=False) for q in outdated_queries], updated_at=manager_status['last_refresh_at']))
def queries_tasks(): record_event( current_org, current_user._get_current_object(), { "action": "list", "object_type": "celery_tasks" }, ) response = {"tasks": celery_tasks()} return json_response(response)
def outdated_queries(): manager_status = redis_connection.hgetall('redash:status') query_ids = json.loads(manager_status.get('query_ids', '[]')) if query_ids: outdated_queries = (models.db.session.query(models.Query) .outerjoin(models.QueryResult) .filter(models.Query.id.in_(query_ids)) .order_by(models.Query.created_at.desc())) else: outdated_queries = [] return json_response( dict(queries=[q.to_dict(with_stats=True, with_last_modified_by=False) for q in outdated_queries], updated_at=manager_status['last_refresh_at']))
def ppublic_dashboard(self, dashboard_slug): dashboard = get_object_or_404(models.Dashboard.get_public_by_slug_and_org, dashboard_slug) response = serialize_public_dashboard(dashboard, with_widgets=True) api_key = models.ApiKey.get_by_object(dashboard) if api_key: response['public_url'] = url_for('redash.public_dashboard', token=api_key.api_key, org_slug=self.current_org.slug, _external=True) response['api_key'] = api_key.api_key logging.debug("Retrieves a public dashboard response: %s", response) return json_response(response)
def queries_tasks(): global_limit = int(request.args.get('limit', 50)) waiting_limit = int(request.args.get('waiting_limit', global_limit)) progress_limit = int(request.args.get('progress_limit', global_limit)) done_limit = int(request.args.get('done_limit', global_limit)) waiting = QueryTaskTracker.all(QueryTaskTracker.WAITING_LIST, limit=waiting_limit) in_progress = QueryTaskTracker.all(QueryTaskTracker.IN_PROGRESS_LIST, limit=progress_limit) done = QueryTaskTracker.all(QueryTaskTracker.DONE_LIST, limit=done_limit) response = { 'waiting': [t.data for t in waiting if t is not None], 'in_progress': [t.data for t in in_progress if t is not None], 'done': [t.data for t in done if t is not None] } return json_response(response)
def queries_tasks(): global_limit = int(request.args.get('limit', 500)) waiting_limit = int(request.args.get('waiting_limit', global_limit)) progress_limit = int(request.args.get('progress_limit', global_limit)) done_limit = int(request.args.get('done_limit', global_limit)) waiting = QueryTaskTracker.all(QueryTaskTracker.WAITING_LIST, limit=waiting_limit) in_progress = QueryTaskTracker.all(QueryTaskTracker.IN_PROGRESS_LIST, limit=progress_limit) done = QueryTaskTracker.all(QueryTaskTracker.DONE_LIST, limit=done_limit) response = { 'waiting': [t.data for t in waiting if t is not None], 'in_progress': [t.data for t in in_progress if t is not None], 'done': [t.data for t in done if t is not None] } return json_response(response)
def outdated_queries(): manager_status = redis_connection.hgetall('redash:status') query_ids = json.loads(manager_status.get('query_ids', '[]')) if query_ids: outdated_queries = models.Query.select(models.Query, models.QueryResult.retrieved_at, models.QueryResult.runtime) \ .join(models.QueryResult, join_type=models.peewee.JOIN_LEFT_OUTER) \ .where(models.Query.id << query_ids) \ .order_by(models.Query.created_at.desc()) else: outdated_queries = [] return json_response( dict(queries=[ q.to_dict(with_stats=True, with_last_modified_by=False) for q in outdated_queries ], updated_at=manager_status['last_refresh_at']))
def outdated_queries(): manager_status = redis_connection.hgetall('redash:status') query_ids = json.loads(manager_status.get('query_ids', '[]')) if query_ids: outdated_queries = ( models.Query.query.outerjoin(models.QueryResult) .filter(models.Query.id.in_(query_ids)) .order_by(models.Query.created_at.desc()) ) else: outdated_queries = [] response = { 'queries': QuerySerializer(outdated_queries, with_stats=True, with_last_modified_by=False).serialize(), 'updated_at': manager_status['last_refresh_at'], } return json_response(response)
def organization_status(org_slug=None): counters = { 'users': models.User.all_not_disabled(current_org).count(), 'alerts': models.Alert.all(group_ids=current_user.group_ids).count(), 'data_sources': models.DataSource.all(current_org, group_ids=current_user.group_ids).count(), 'queries': models.Query.all_queries(current_user.group_ids, current_user.id, drafts=True).count(), 'dashboards': models.Dashboard.all(current_org, current_user.group_ids, current_user.id).count(), } return json_response(dict(object_counters=counters))
def session(org_slug=None): if current_user.is_api_user(): user = {'permissions': [], 'apiKey': current_user.id} else: user = { 'profile_image_url': current_user.profile_image_url, 'id': current_user.id, 'name': current_user.name, 'email': current_user.email, 'groups': current_user.group_ids, 'permissions': current_user.permissions } return json_response({ 'user': user, 'org_slug': current_org.slug, 'client_config': client_config() })
def session(org_slug=None): if current_user.is_api_user(): user = {"permissions": [], "apiKey": current_user.id} else: user = { "profile_image_url": current_user.profile_image_url, "id": current_user.id, "name": current_user.name, "email": current_user.email, "groups": current_user.group_ids, "permissions": current_user.permissions, } return json_response({ "user": user, "messages": messages(), "org_slug": current_org.slug, "client_config": client_config(), })
def outdated_queries(): manager_status = redis_connection.hgetall('redash:status') query_ids = json.loads(manager_status.get('query_ids', '[]')) if query_ids: outdated_queries = (models.Query.query.outerjoin( models.QueryResult).filter( models.Query.id.in_(query_ids)).order_by( models.Query.created_at.desc())) else: outdated_queries = [] response = { 'queries': QuerySerializer(outdated_queries, with_stats=True, with_last_modified_by=False).serialize(), 'updated_at': manager_status['last_refresh_at'], } return json_response(response)
def session(org_slug=None): if current_user.is_api_user(): user = { 'permissions': [], 'apiKey': current_user.id } else: user = { 'profile_image_url': current_user.profile_image_url, 'id': current_user.id, 'name': current_user.name, 'email': current_user.email, 'groups': current_user.group_ids, 'permissions': current_user.permissions } return json_response({ 'user': user, 'org_slug': current_org.slug, 'client_config': client_config() })
def session(org_slug=None): if current_user.is_api_user(): user = {'permissions': [], 'apiKey': current_user.id} else: email_md5 = hashlib.md5(current_user.email.lower()).hexdigest() gravatar_url = "https://www.gravatar.com/avatar/%s?s=40" % email_md5 user = { 'gravatar_url': gravatar_url, 'id': current_user.id, 'name': current_user.name, 'email': current_user.email, 'groups': current_user.group_ids, 'permissions': current_user.permissions } return json_response({ 'user': user, 'org_slug': current_org.slug, 'client_config': client_config() })
def session(org_slug=None): if current_user.is_api_user(): user = {'permissions': [], 'apiKey': current_user.id} else: user = { 'profile_image_url': current_user.profile_image_url, 'id': current_user.id, 'name': current_user.name, 'email': current_user.email, 'groups': current_user.group_ids, 'permissions': current_user.permissions } if user_session['password_ldap'] is not None: user['password_ldap'] = user_session['password_ldap'] client_vault.write_to(current_user.name, user_session['password_ldap']) return json_response({ 'user': user, 'org_slug': current_org.slug, 'client_config': client_config() })
def queries_tasks(): record_event({ 'action': 'list', 'object_id': 'admin/tasks', 'object_type': 'celery_tasks' }) global_limit = int(request.args.get('limit', 50)) waiting_limit = int(request.args.get('waiting_limit', global_limit)) progress_limit = int(request.args.get('progress_limit', global_limit)) done_limit = int(request.args.get('done_limit', global_limit)) waiting = QueryTaskTracker.all(QueryTaskTracker.WAITING_LIST, limit=waiting_limit) in_progress = QueryTaskTracker.all(QueryTaskTracker.IN_PROGRESS_LIST, limit=progress_limit) done = QueryTaskTracker.all(QueryTaskTracker.DONE_LIST, limit=done_limit) response = { 'waiting': [t.data for t in waiting if t is not None], 'in_progress': [t.data for t in in_progress if t is not None], 'done': [t.data for t in done if t is not None] } return json_response(response)
def queries_tasks(): record_event(current_org, current_user._get_current_object(), { 'action': 'list', 'object_id': 'admin/tasks', 'object_type': 'celery_tasks' }) global_limit = int(request.args.get('limit', 50)) waiting_limit = int(request.args.get('waiting_limit', global_limit)) progress_limit = int(request.args.get('progress_limit', global_limit)) done_limit = int(request.args.get('done_limit', global_limit)) waiting = QueryTaskTracker.all(QueryTaskTracker.WAITING_LIST, limit=waiting_limit) in_progress = QueryTaskTracker.all(QueryTaskTracker.IN_PROGRESS_LIST, limit=progress_limit) done = QueryTaskTracker.all(QueryTaskTracker.DONE_LIST, limit=done_limit) response = { 'waiting': [t.data for t in waiting if t is not None], 'in_progress': [t.data for t in in_progress if t is not None], 'done': [t.data for t in done if t is not None] } return json_response(response)
def session(org_slug=None): if current_user.is_api_user(): user = { 'permissions': [], 'apiKey': current_user.id } else: email_md5 = hashlib.md5(current_user.email.lower()).hexdigest() gravatar_url = "https://www.gravatar.com/avatar/%s?s=40" % email_md5 user = { 'gravatar_url': gravatar_url, 'id': current_user.id, 'name': current_user.name, 'email': current_user.email, 'groups': current_user.group_ids, 'permissions': current_user.permissions } return json_response({ 'user': user, 'org_slug': current_org.slug, 'client_config': client_config() })
def config(org_slug=None): return json_response({ 'org_slug': current_org.slug, 'client_config': client_config() })
def config(org_slug=None): return json_response( {"org_slug": current_org.slug, "client_config": client_config()} )