Exemplo n.º 1
0
def chart():
    endpoints = request.form.getlist("endpoints[]") or []
    counters = request.form.getlist("counters[]") or []
    graph_type = request.form.get("graph_type") or GRAPH_TYPE_HOST
    endpoints = sorted(set(endpoints))

    group_objs = Group.gets_by_group(endpoints)
    if len(group_objs) > 0:
        group_ids = [x.id for x in group_objs]
        grouphost_objs = GroupHost.search(group_ids)
        host_ids = [x.hostId for x in grouphost_objs]
        host_objs = Host.search(host_ids)
        endpoint_names = [x.name for x in host_objs]
        id_ = TmpGraph.add(endpoint_names, counters)
    else:
        id_ = TmpGraph.add(endpoints, counters)

    ret = {
            "ok": False,
            "id": id_,
            "params": {
                "graph_type": graph_type,
            },
    }
    if id_:
        ret['ok'] = True

    return json.dumps(ret)
Exemplo n.º 2
0
def chart():
    endpoints = request.form.getlist("endpoints[]") or []
    counters = request.form.getlist("counters[]") or []
    graph_type = request.form.get("graph_type") or GRAPH_TYPE_HOST
    endpoints = sorted(set(endpoints))

    group_objs = Group.gets_by_group(endpoints)
    if len(group_objs) > 0:
        group_ids = [x.id for x in group_objs]
        grouphost_objs = GroupHost.search(group_ids)
        host_ids = [x.hostId for x in grouphost_objs]
        host_objs = Host.search(host_ids)
        endpoint_names = [x.name for x in host_objs]
        id_ = TmpGraph.add(endpoint_names, counters)
    else:
        id_ = TmpGraph.add(endpoints, counters)

    ret = {
        "ok": False,
        "id": id_,
        "params": {
            "graph_type": graph_type,
        },
    }
    if id_:
        ret['ok'] = True

    return json.dumps(ret)
Exemplo n.º 3
0
def api_get_counters():
    ret = {
        "ok": False,
        "msg": "",
        "data": [],
    }
    endpoints = request.form.get("endpoints") or ""
    endpoints = endpoints and json.loads(endpoints)
    q = request.form.get("q") or ""
    limit = int(request.form.get("limit") or 100)

    nethelp = request.form.get("nethelp") or ""
    if not (endpoints or q):
        ret['msg'] = "no endpoints or counter given"
        return json.dumps(ret)

    endpoint_objs = Endpoint.gets_by_endpoint(endpoints)
    endpoint_ids = [x.id for x in endpoint_objs]
    group_ids = []
    if not endpoint_ids:
        group_objs = Group.gets_by_group(endpoints)
        group_ids = [x.id for x in group_objs]
        grouphost_objs = GroupHost.search(group_ids)
        host_ids = [x.hostId for x in grouphost_objs]
        host_objs = Host.search(host_ids)
        host_names = [x.name for x in host_objs]
        endpoint_objs = Endpoint.gets_by_endpoint(host_names)
        endpoint_ids = [x.id for x in endpoint_objs]

        if not endpoint_ids:
            ret['msg'] = "no endpoints in graph"
            return json.dumps(ret)

    qs = q.split()
    if nethelp == "true":
        ecs = EndpointCounter.search_in_endpoint_ids(qs, endpoint_ids, limit=100)
    elif len(group_ids) > 0:
        limit = 5000
    if len(qs) > 0:
        ecs = EndpointCounter.search_in_endpoint_ids(qs, endpoint_ids, limit=limit)
    else:
        ecs = EndpointCounter.gets_by_endpoint_ids(endpoint_ids, limit=limit)

    if not ecs:
        ret["msg"] = "no counters in graph"
        return json.dumps(ret)
    
    counters_map = {}
    for x in ecs:
        counters_map[x.counter] = [x.counter, x.type_, x.step]
    sorted_counters = sorted(counters_map.keys())
    sorted_values = [counters_map[x] for x in sorted_counters]

    ret['data'] = sorted_values
    ret['ok'] = True

    return json.dumps(ret)
Exemplo n.º 4
0
def api_groups():
    ret = {"ok": False, "msg": "", "data": []}

    q = request.args.get("q") or ""
    if not q:
        ret["msg"] = "no query params given"
        return json.dumps(ret)

    groups = Group.search(q.split())
    groups_str = [x.name for x in groups]
    groups_str.sort()
    ret["data"] = groups_str
    ret["ok"] = True

    return json.dumps(ret)
Exemplo n.º 5
0
def api_groups():
    ret = {
        "ok": False,
        "msg": "",
        "data": [],
    }

    q = request.args.get("q") or ""
    if not q:
        ret["msg"] = "no query params given"
        return json.dumps(ret)

    groups = Group.search(q.split())
    groups_str = [x.name for x in groups]
    groups_str.sort()
    ret['data'] = groups_str
    ret['ok'] = True

    return json.dumps(ret)