Example #1
0
def api_endpoints():
    ret = {
        "ok": False,
        "msg": "",
        "data": [],
    }

    q = request.args.get("q") or ""
    raw_tag = request.args.get("tags") or ""
    tags = raw_tag and [x.strip() for x in raw_tag.split(",")] or []
    limit = int(request.args.get("limit") or 100)

    if not q and not tags:
        ret["msg"] = "no query params given"
        return json.dumps(ret)

    endpoints = []

    if tags and q:
        endpoint_ids = TagEndpoint.get_endpoint_ids(tags, limit=limit) or []
        endpoints = Endpoint.search_in_ids(q.split(), endpoint_ids)
    elif tags:
        endpoint_ids = TagEndpoint.get_endpoint_ids(tags, limit=limit) or []
        endpoints = Endpoint.gets(endpoint_ids)
    elif q == 'all':
        endpoints = Endpoint.search([], limit=limit)
    else:
        endpoints = Endpoint.search(q.split(), limit=limit)

    endpoints_str = [x.endpoint for x in endpoints]
    endpoints_str.sort()
    ret['data'] = endpoints_str
    ret['ok'] = True

    return json.dumps(ret)
Example #2
0
def api_ztree():
    ret = {
        "ok":False,
        "msg":"",
        "dara":[],
    }
    if request.method == "POST":
    	pid = request.form.get("id")
	ztree = Ztree.get_name_by_id(pid)
	grp = list()
	for x in ztree:
		grp.append(x.name)
        filter = [(".").join(grp)]
        hosts = Endpoint.search(filter,limit=1000000)
        data = []
        id = int(pid + "100000")
        for x in hosts:
            data.append({"id":str(id),"pid":pid,"name":x.endpoint,"isparent":"true"})
            id += 1
        return json.dumps(data)
    ztrees = Ztree.gets()
    ztrees_str = []
    for x in ztrees:
        ztree_one = [x.id,x.pid,x.name,x.isparent]
        ztrees_str.append(ztree_one)
    ret['data'] = ztrees_str
    ret['ok'] = True
    return json.dumps(ret)
Example #3
0
def qryOptions():
    options = {}
    options['hosts'] = Endpoint.search([], limit=limit)
    ids = []
    for ep in options['hosts']:
        ids.append(ep.id)
    options['counters'] = EndpointCounter.gets_by_endpoint_ids(ids[0:1], limit=limit)
    return options
Example #4
0
def dash_graph_add(sid):
    all_screens = DashboardScreen.gets_all()
    top_screens = [x for x in all_screens if x.pid == '0']
    children = []
    for t in top_screens:
        children.append([x for x in all_screens if x.pid == t.id])

    screen = DashboardScreen.get(sid)
    if not screen:
        abort(404, "no screen")
    pscreen = DashboardScreen.get(screen.pid)

    if request.method == "POST":
        title = request.form.get("title")

        hosts = request.form.get("hosts", "").strip()
        hosts = hosts and hosts.split("\n") or []
        hosts = [x.strip() for x in hosts]

        counters = request.form.get("counters", "").strip()
        counters = counters and counters.split("\n") or []
        counters = [x.strip() for x in counters]

        timespan = int(request.form.get("timespan", 3600))
        graph_type = request.form.get("graph_type", 'h')
        method = request.form.get("method", '').upper()
        position = int(request.form.get("position", 0))

        graph = DashboardGraph.add(title, hosts, counters, sid, timespan,
                                   graph_type, method, position)
        return redirect("/screen/%s" % sid)

    else:
        limit = 10000
        gid = request.args.get("gid")
        graph = gid and DashboardGraph.get(gid)
        options = {}
        options['hosts'] = Endpoint.search(''.split(), limit=limit)
        ids = []
        for ep in options['hosts']:
            ids.append(ep.id)
        options['counters'] = EndpointCounter.gets_by_endpoint_ids(ids[0:1],
                                                                   limit=limit)
        return render_template("screen/graph_add.html",
                               config=config,
                               **locals())
Example #5
0
def index():
    raw_endpoints = Endpoint.search("");
    endpoints = [e.endpoint for e in raw_endpoints]
    endpoints.sort()

    return render_template("index.html", **locals())