Ejemplo n.º 1
0
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,
            })
Ejemplo n.º 2
0
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,
        })
Ejemplo n.º 3
0
def get_alerts():

    try:
        query, sort, limit, query_time = parse_fields(request)
    except Exception, e:
        return jsonify(response={"status": "error", "message": str(e)})
Ejemplo n.º 4
0
def get_alerts():

    try:
        query, sort, limit, query_time = parse_fields(request)
    except Exception, e:
        return jsonify(response={"status": "error", "message": str(e)})