def get_resources(): query, sort, limit, query_time = parse_fields(request) resources = db.get_resources(query=query, sort=sort, limit=limit) total = db.get_count( query=query) # TODO(nsatterl): possible race condition? found = 0 resource_details = list() if len(resources) > 0: last_time = None for resource in resources: resource_details.append(resource) found += 1 if not last_time: last_time = resource['lastReceiveTime'] elif resource['lastReceiveTime'] > last_time: last_time = resource['lastReceiveTime'] return jsonify( response={ "resources": { "resourceDetails": resource_details, "lastTime": last_time, }, "status": "ok", "total": found, "more": total > limit }) else: return jsonify( response={ "resources": { "resourceDetails": list(), "lastTime": query_time, }, "status": "ok", "message": "not found", "total": 0, "more": False, })
def get_resources(): query, sort, limit, query_time = parse_fields(request) resources = db.get_resources(query=query, sort=sort, limit=limit) total = db.get_count(query=query) # TODO(nsatterl): possible race condition? found = 0 resource_details = list() if len(resources) > 0: last_time = None for resource in resources: resource_details.append(resource) found += 1 if not last_time: last_time = resource['lastReceiveTime'] elif resource['lastReceiveTime'] > last_time: last_time = resource['lastReceiveTime'] return jsonify(response={ "resources": { "resourceDetails": resource_details, "lastTime": last_time, }, "status": "ok", "total": found, "more": total > limit }) else: return jsonify(response={ "resources": { "resourceDetails": list(), "lastTime": query_time, }, "status": "ok", "message": "not found", "total": 0, "more": False, })
# Returns a list of alerts @app.route('/alerta/api/v2/alerts', methods=['GET']) @jsonp def get_alerts(): try: query, sort, limit, query_time = parse_fields(request) except Exception, e: return jsonify(response={"status": "error", "message": str(e)}) fields = dict() fields['history'] = {'$slice': CONF.history_limit} alerts = db.get_alerts(query=query, fields=fields, sort=sort, limit=limit) total = db.get_count(query=query) # TODO(nsatterl): possible race condition? found = 0 severity_count = dict.fromkeys(severity_code.ALL, 0) status_count = dict.fromkeys(status_code.ALL, 0) alert_details = list() if len(alerts) > 0: last_time = None for alert in alerts: body = alert.get_body() if body['severity'] in request.args.getlist('hide-alert-repeats') and body['repeat']: continue
@app.route('/alerta/api/v2/alerts', methods=['GET']) @jsonp def get_alerts(): try: query, sort, limit, query_time = parse_fields(request) except Exception, e: return jsonify(response={"status": "error", "message": str(e)}) fields = dict() fields['history'] = {'$slice': CONF.history_limit} alerts = db.get_alerts(query=query, fields=fields, sort=sort, limit=limit) total = db.get_count( query=query) # TODO(nsatterl): possible race condition? found = 0 severity_count = dict.fromkeys(severity_code.ALL, 0) status_count = dict.fromkeys(status_code.ALL, 0) alert_details = list() if len(alerts) > 0: last_time = None for alert in alerts: body = alert.get_body() if body['severity'] in request.args.getlist( 'hide-alert-repeats') and body['repeat']: