Esempio n. 1
0
def dash_screen(sid):
    start = request.args.get("start")
    end = request.args.get("end")

    top_screens = DashboardScreen.gets(pid=0)
    top_screens = sorted(top_screens, key=lambda x: x.name)

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

    if str(screen.pid) == '0':
        sub_screens = DashboardScreen.gets(pid=sid)
        sub_screens = sorted(sub_screens, key=lambda x: x.name)
        return render_template("screen/top_screen.html", **locals())

    pscreen = DashboardScreen.get(screen.pid)
    sub_screens = DashboardScreen.gets(pid=screen.pid)
    sub_screens = sorted(sub_screens, key=lambda x: x.name)
    graphs = DashboardGraph.gets_by_screen_id(screen.id)

    all_graphs = []

    for graph in graphs:
        all_graphs.extend(generate_graph_urls(graph, start, end) or [])

    all_graphs = sorted(all_graphs, key=lambda x: x.position)

    return render_template("screen/screen.html", **locals())
Esempio n. 2
0
def dash_screen(sid):
    start = request.args.get("start")
    end = request.args.get("end")

    top_screens = DashboardScreen.gets(pid=0)
    top_screens = sorted(top_screens, key=lambda x: x.name)

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

    if str(screen.pid) == '0':
        sub_screens = DashboardScreen.gets(pid=sid)
        sub_screens = sorted(sub_screens, key=lambda x: x.name)
        return render_template("screen/top_screen.html", **locals())

    pscreen = DashboardScreen.get(screen.pid)
    sub_screens = DashboardScreen.gets(pid=screen.pid)
    sub_screens = sorted(sub_screens, key=lambda x: x.name)
    graphs = DashboardGraph.gets_by_screen_id(screen.id)

    all_graphs = []

    for graph in graphs:
        all_graphs.extend(generate_graph_urls(graph, start, end) or [])

    all_graphs = sorted(all_graphs, key=lambda x: x.position)

    return render_template("screen/screen.html", **locals())
Esempio n. 3
0
def dash_graph_multi_edit():
    ret = {
        "ok": False,
        "msg": "",
        "data": [],
    }
    if request.method == "POST":
        d = request.data
        try:
            jdata = json.loads(d)
        except ValueError:
            jdata = None

        if not jdata:
            return json.dumps({
                "ok": False,
                "msg": "no_data_post",
            })
        rows = []
        for x in jdata:
            rows.append({
                "id": x["id"],
                "hosts": x["endpoints"],
                "counters": x["counters"]
            })
        DashboardGraph.update_multi(rows)

        return json.dumps({
            "ok": True,
            "msg": "",
        })

    elif request.method == "GET":
        sid = request.args.get("sid")
        if not sid or not DashboardScreen.get(sid):
            ret["msg"] = "no_screen"
            return json.dumps(ret)

        ret["ok"] = True
        graphs = DashboardGraph.gets_by_screen_id(sid)
        ret['data'] = [{
            "id": x.id,
            "title": x.title,
            "endpoints": x.hosts,
            "counters": x.counters
        } for x in graphs]
        return json.dumps(ret)
Esempio n. 4
0
def dash_screen_embed(sid):
    start = request.args.get("start")
    end = request.args.get("end")

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

    if screen.pid == '0':
        abort(404, "top screen")

    graphs = DashboardGraph.gets_by_screen_id(screen.id)
    all_graphs = []

    for graph in graphs:
        all_graphs.extend(generate_graph_urls(graph, start, end) or [])

    all_graphs = sorted(all_graphs, key=lambda x: (x.position, x.id))

    return render_template("screen/screen_embed.html", **locals())
Esempio n. 5
0
def dash_screen_embed(sid):
    start = request.args.get("start")
    end = request.args.get("end")

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

    if screen.pid == '0':
        abort(404, "top screen")

    graphs = DashboardGraph.gets_by_screen_id(screen.id)
    all_graphs = []

    for graph in graphs:
        all_graphs.extend(generate_graph_urls(graph, start, end) or [])

    all_graphs = sorted(all_graphs, key=lambda x: (x.position, x.id))

    return render_template("screen/screen_embed.html", **locals())
Esempio n. 6
0
def dash_screen_clone(sid):
    screen = DashboardScreen.get(sid)
    if not screen:
        abort(404, "no such screen")

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

        new_s = DashboardScreen.add(screen.pid, screen_name)
        if not new_s:
            abort(404, "创建screen失败了")

        if with_graph:
            old_graphs = DashboardGraph.gets_by_screen_id(sid)
            for o in old_graphs:
                DashboardGraph.add(o.title, o.hosts, o.counters, new_s.id,
                                   o.timespan, o.graph_type, o.method, o.position)

        return redirect("/screen/%s" % new_s.id)
    else:
        return render_template("screen/clone.html", **locals())
Esempio n. 7
0
def dash_screen_clone(sid):
    screen = DashboardScreen.get(sid)
    if not screen:
        abort(404, "no such screen")

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

        new_s = DashboardScreen.add(screen.pid, screen_name)
        if not new_s:
            abort(404, gettext("screen create fail"))

        if with_graph:
            old_graphs = DashboardGraph.gets_by_screen_id(sid)
            for o in old_graphs:
                DashboardGraph.add(o.title, o.hosts, o.counters, new_s.id,
                        o.timespan, o.graph_type, o.method, o.position)

        return redirect("/screen/%s" %new_s.id)
    else:
        return render_template("screen/clone.html", **locals())
Esempio n. 8
0
def dash_graph_multi_edit():
    ret = {
        "ok": False,
        "msg": "",
        "data": [],
    }
    if request.method == "POST":
        d = request.data
        try:
            jdata = json.loads(d)
        except ValueError:
            jdata = None

        if not jdata:
            return json.dumps({
                "ok": False,
                "msg": "no_data_post",
            })
        rows = []
        for x in jdata:
            rows.append({"id": x["id"], "hosts": x["endpoints"], "counters": x["counters"]})
        DashboardGraph.update_multi(rows)

        return json.dumps({
            "ok": True,
            "msg": "",
        })

    elif request.method == "GET":
        sid = request.args.get("sid")
        if not sid or not DashboardScreen.get(sid):
            ret["msg"] = "no_screen"
            return json.dumps(ret)

        ret["ok"] = True
        graphs = DashboardGraph.gets_by_screen_id(sid)
        ret['data'] = [{"id": x.id, "title": x.title, "endpoints": x.hosts, "counters": x.counters} for x in graphs]
        return json.dumps(ret)
Esempio n. 9
0
def dash_screen(sid):
    print today_date_str(), "req_for dash_screen"
    start = request.args.get("start")
    end = request.args.get("end")

    top_screens = DashboardScreen.gets_by_pid(pid=0)
    print today_date_str(), "top_screens"
    # top_screens = sorted(top_screens, key=lambda x:x.name)
    # 只显示非sys_base_screen_的前100条
    top_screens = filter(lambda x: 'sys_base_screen_' not in x.name,
                         top_screens)[:100]
    top_screens = sorted(top_screens, key=lambda x: x.name)

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

    if str(screen.pid) == '0':
        sub_screens = DashboardScreen.gets_by_pid(pid=sid)
        sub_screens = sorted(sub_screens, key=lambda x: x.name)
        return render_template("screen/top_screen.html", **locals())

    pscreen = DashboardScreen.get(screen.pid)
    print today_date_str(), "pscreen"
    sub_screens = DashboardScreen.gets_by_pid(pid=screen.pid)
    sub_screens = sorted(sub_screens, key=lambda x: x.name)
    graphs = DashboardGraph.gets_by_screen_id(screen.id)
    print today_date_str(), "graphs"
    all_graphs = []

    for graph in graphs:
        all_graphs.extend(generate_graph_urls(graph, start, end) or [])

    all_graphs = sorted(all_graphs, key=lambda x: x.position)
    print today_date_str(), "all_graphs"
    return render_template("screen/screen.html", **locals())
Esempio n. 10
0
def dash_screen(sid):
    start = request.args.get("start")
    end = request.args.get("end")

    top_screens = DashboardScreen.gets_by_pid(pid=0)
    top_screens = sorted(top_screens, key=lambda x:x.name)

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

    if str(screen.pid) == '0':
        sub_screens = DashboardScreen.gets_by_pid(pid=sid)
        sub_screens = sorted(sub_screens, key=lambda x:x.name)
        return render_template("screen/top_screen.html", **locals())

    pscreen = DashboardScreen.get(screen.pid)
    sub_screens = DashboardScreen.gets_by_pid(pid=screen.pid)
    sub_screens = sorted(sub_screens, key=lambda x:x.name)
    graphs = DashboardGraph.gets_by_screen_id(screen.id)

    all_graphs = []

    for graph in graphs:
        all_graphs.extend(generate_graph_urls(graph, start, end) or [])

    all_graphs = sorted(all_graphs, key=lambda x:x.position)

#    return render_template("screen/screen.html", **locals())
    # refresh every n seconds
    metabc='''
	<script>
		function geturl(tim){
			var url = window.location.href;
			var url_tmp=[];
			var url_ori="";
			var fuhao="";
			if(url.indexOf("fresh=") != -1){     // have "fresh" canshu
                               if(url.indexOf("?fresh=") != -1){     // "?fresh" canshu
					url_tmp=url.split("?fresh=");
					url_ori=url_tmp[0];
					fuhao="?";
	                        }else{                               // "&fresh" canshu
                                	url_tmp=url.split("&fresh=");
                                        url_ori=url_tmp[0];
					fuhao="&";
                        	}  //alert(url_ori);

                        }else{                         	     // dont have "fresh" canshu
                                //alert("No fresh Command!");
				url_ori=url;
                        }
			if(tim=="close"){	//close
				//alert("Close");
				window.location.href=url_ori;
			}else{
				if(url_ori.indexOf("?") == -1){	fuhao="?"; }
				url_ori=url_ori.replace("#","");
				url_new=url_ori+fuhao+"fresh="+tim; // idelete # after sid
			}
			window.location.href=url_new;
			//alert(url_new);
		}
	</script>	'''

    sec=request.args.get("fresh")
    metajj=""
    if sec!=None:
    	metajj=metabc+''' <META HTTP-EQUIV='Refresh' CONTENT='%s'> ''' % (sec)
    else:
        metajj=metabc 
    return render_template("screen/screen.html", metab=metajj, fresh="FreshButton", **locals())