コード例 #1
0
ファイル: screen.py プロジェクト: modeyang/dashboard
def dash_graph_delete(gid):
    token = request.args.get("token", None)
    if token is None or token != config.AUTH_TOKEN:
        abort(403, "auth failed, can not be deleted")

    graph = DashboardGraph.get(gid)
    if not graph:
        abort(404, "no such graph")
    DashboardGraph.remove(gid)
    return redirect("/screen/" + graph.screen_id)
コード例 #2
0
ファイル: screen.py プロジェクト: Solertis/dashboard-5
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())
コード例 #3
0
ファイル: screen.py プロジェクト: 1329555958/dashboard
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())
コード例 #4
0
ファイル: screen.py プロジェクト: Solertis/dashboard-5
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)
コード例 #5
0
ファイル: screen.py プロジェクト: mia0x75/dashboard
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())
コード例 #6
0
ファイル: screen.py プロジェクト: ning1875/falcon-dashboard
def dash_graph_edit(gid):
    log.debug("dash_graph_edit:{}".format(gid))
    error = ""
    graph = DashboardGraph.get(gid)
    log.debug("dash_graph_1111--graph:{}".format(graph))
    if not graph:
        abort(404, "no graph")

    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(graph.screen_id)
    if not screen:
        abort(404, "no screen")
    pscreen = DashboardScreen.get(screen.pid)

    if request.method == "POST":
        log.debug("Postcalled")
        ajax = request.form.get("ajax", "")
        screen_id = request.form.get("screen_id")
        title = request.form.get("title", "").strip()

        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 = request.form.get("timespan", 3600)
        graph_type = request.form.get("graph_type", 'h')
        method = request.form.get("method", '').upper()
        position = request.form.get("position", 0)
        log.debug("Postcalledupdate %s %s %s %s %s %s %s %s " %
                  (title, hosts, counters, screen_id, timespan, graph_type,
                   method, position))
        graph = graph.update(title, hosts, counters, screen_id, timespan,
                             graph_type, method, position)
        log.debug("dash_graph_edit got graph.update {} {}".format(graph, ajax))
        error = gettext("edit successful")
        if not ajax:

            log.debug("render_template---")
            return render_template("screen/graph_edit.html",
                                   config=config,
                                   **locals())
        else:
            return "ok"

    else:
        ajax = request.args.get("ajax", "")
        return render_template("screen/graph_edit.html", **locals())
コード例 #7
0
ファイル: screen.py プロジェクト: 1329555958/dashboard
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())
コード例 #8
0
ファイル: screen.py プロジェクト: zimu312500/dashboard
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]

        relativeday = int(request.form.get("relativeday", 7))
        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,
                                   relativeday, graph_type, method, position)
        return redirect("/screen/%s" % sid)

    else:
        gid = request.args.get("gid")
        graph = gid and DashboardGraph.get(gid)
        return render_template("screen/graph_add.html",
                               config=config,
                               **locals())
コード例 #9
0
ファイル: screen.py プロジェクト: soliChen/dashboard
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())
コード例 #10
0
def dash_graph_edit(gid):
    error = ""
    graph = DashboardGraph.get(gid)
    if not graph:
        abort(404, "no graph")

    all_screens = DashboardScreen.gets()
    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(graph.screen_id)
    if not screen:
        abort(404, "no screen")
    pscreen = DashboardScreen.get(screen.pid)

    if request.method == "POST":
        ajax = request.form.get("ajax", "")
        screen_id = request.form.get("screen_id")
        title = request.form.get("title", "").strip()

        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 = request.form.get("timespan", 3600)
        graph_type = request.form.get("graph_type", 'h')
        method = request.form.get("method", '').upper()
        position = request.form.get("position", 0)

        graph = graph.update(title, hosts, counters, screen_id, timespan,
                             graph_type, method, position)

        error = u"修改成功了"
        if not ajax:
            return render_template("screen/graph_edit.html",
                                   config=config,
                                   **locals())
        else:
            return "ok"

    else:
        ajax = request.args.get("ajax", "")
        return render_template("screen/graph_edit.html",
                               config=config,
                               **locals())
コード例 #11
0
ファイル: screen.py プロジェクト: 1329555958/dashboard
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)
コード例 #12
0
ファイル: screen.py プロジェクト: 1329555958/dashboard
def dash_graph_add(sid):
    all_screens = DashboardScreen.gets()
    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 = request.form.get("timespan", 3600)
        graph_type = request.form.get("graph_type", 'h')
        method = request.form.get("method", '').upper()
        position = request.form.get("position", 0)

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

    else:
        gid = request.args.get("gid")
        graph = gid and DashboardGraph.get(gid)
        options = qryOptions()
        return render_template("screen/graph_add.html", config=config, **locals())
コード例 #13
0
ファイル: screen.py プロジェクト: open-falcon/dashboard
def dash_graph_edit(gid):
    error = ""
    graph = DashboardGraph.get(gid)
    if not graph:
        abort(404, "no graph")

    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(graph.screen_id)
    if not screen:
        abort(404, "no screen")
    pscreen = DashboardScreen.get(screen.pid)

    if request.method == "POST":
        ajax = request.form.get("ajax", "")
        screen_id = request.form.get("screen_id")
        title = request.form.get("title", "").strip()

        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 = request.form.get("timespan", 3600)
        graph_type = request.form.get("graph_type", 'h')
        method = request.form.get("method", '').upper()
        position = request.form.get("position", 0)

        graph = graph.update(title, hosts, counters, screen_id,
                timespan, graph_type, method, position)

        error = gettext("edit successful")
        if not ajax:
            return render_template("screen/graph_edit.html", config=config, **locals())
        else:
            return "ok"

    else:
        ajax = request.args.get("ajax", "")
        return render_template("screen/graph_edit.html", **locals())
コード例 #14
0
ファイル: screen.py プロジェクト: open-falcon/dashboard
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())
コード例 #15
0
ファイル: screen.py プロジェクト: mia0x75/dashboard
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())
コード例 #16
0
ファイル: screen.py プロジェクト: ning1875/falcon-dashboard
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())
コード例 #17
0
ファイル: screen.py プロジェクト: 1329555958/dashboard
def dash_graph_edit(gid):
    error = ""
    is_tmp_graph = False
    graph = DashboardGraph.get(gid)

    all_screens = DashboardScreen.gets()
    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])

    if not graph:
        # 编辑临时 graph
        graph = TmpGraph.get(gid)
        graph = DashboardGraph.add('graph', graph.endpoints, graph.counters, 0)

        if not graph:
            abort(404, "no graph")
        is_tmp_graph = True

    if not is_tmp_graph:
        screen = DashboardScreen.get(graph.screen_id)
        if not screen:
            abort(404, "no screen")
    # pscreen = DashboardScreen.get(screen.pid)

    if request.method == "POST":
        ajax = request.form.get("ajax", "")
        screen_id = request.form.get("screen_id")
        title = request.form.get("title", "").strip()

        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 = request.form.get("timespan", 3600)
        graph_type = request.form.get("graph_type", 'h')
        method = request.form.get("method", '').upper()
        position = request.form.get("position", 0)

        if is_tmp_graph:  # 如果是临时graph修改之后就添加进去
            graph = DashboardGraph.add(title, hosts, counters, screen_id,
                                       timespan, graph_type, method, position)
        else:
            graph = graph.update(title, hosts, counters, screen_id,
                                 timespan, graph_type, method, position)

        error = u"修改成功了"
        if not ajax:
            options = qryOptions()
            return redirect('/screen/' + graph.screen_id)  # 重定向到对应的screen
            # return render_template("screen/graph_edit.html", config=config, **locals())
        else:
            return "ok"

    else:
        ajax = request.args.get("ajax", "")
        options = qryOptions()
        return render_template("screen/graph_edit.html", **locals())
コード例 #18
0
ファイル: screen.py プロジェクト: Solertis/dashboard-5
def dash_graph_delete(gid):
    graph = DashboardGraph.get(gid)
    if not graph:
        abort(404, "no such graph")
    DashboardGraph.remove(gid)
    return redirect("/screen/" + graph.screen_id)
コード例 #19
0
ファイル: chart.py プロジェクト: zimu312500/dashboard
def multi_endpoints_chart_data():
    if not g.id:
        abort(400, "no graph id given")

    j = TmpGraph.get(g.id)
    if not j:
        abort(400, "no such tmp_graph where id=%s" % g.id)

    counters = j.counters
    if not counters:
        abort(400, "no counters of %s" % g.id)
    counters = sorted(set(counters))

    endpoints = j.endpoints
    if not endpoints:
        abort(400, "no endpoints of %s" % (g.id,))
    endpoints = sorted(set(endpoints))

    ret = {
        "units": "",
        "title": "",
        "series": []
    }

    c = counters[0]
    ret['title'] = c
    query_result = graph_history(endpoints, counters[:1], g.cf, g.start, g.end)

    series = []
    for i in range(0, len(query_result)):
        x = query_result[i]
        try:
            xv = [(v["timestamp"] * 1000, v["value"]) for v in x["Values"]]
            serie = {
                "data": xv,
                "name": query_result[i]["endpoint"],
                "cf": g.cf,
                "endpoint": query_result[i]["endpoint"],
                "counter": query_result[i]["counter"],
            }
            series.append(serie)
        except:
            pass

    # 通过查看dashboard_grap判断是否存在环比看图
    if g.dgid:
        dg = DashboardGraph.get(g.dgid)
        if dg.relativeday > 0:
            query_result = graph_history(endpoints[:1], counters, g.cf, g.start - dg.relativeday * 24 * 3600,
                                         g.end - dg.relativeday * 24 * 3600)
            for i in range(0, len(query_result)):
                x = query_result[i]
                try:
                    xv = [((v["timestamp"] + dg.relativeday * 24 * 3600)* 1000, v["value"]) for v in x["Values"]]
                    serie = {
                        "data": xv,
                        "name": u"[环比:" + str(dg.relativeday) + u"天]" + query_result[i]["endpoint"],
                        "cf": g.cf,
                        "endpoint": query_result[i]["endpoint"],
                        "counter": query_result[i]["counter"],
                    }
                    series.append(serie)
                except:
                    print(traceback.format_exc())
                    pass

    sum_serie = {
        "data": [],
        "name": "sum",
        "cf": g.cf,
        "endpoint": "sum",
        "counter": c,
    }
    if g.sum == "on" or g.sumonly == "on":
        sum = []
        tmp_ts = []
        max_size = 0
        for serie in series:
            serie_vs = [x[1] for x in serie["data"]]
            if len(serie_vs) > max_size:
                max_size = len(serie_vs)
                tmp_ts = [x[0] for x in serie["data"]]
            sum = merge_list(sum, serie_vs)
        sum_serie_data = []
        for i in range(0, max_size):
            sum_serie_data.append((tmp_ts[i], sum[i]))
        sum_serie['data'] = sum_serie_data

        series.append(sum_serie)

    if g.sumonly == "on":
        ret['series'] = [sum_serie, ]
    else:
        ret['series'] = series

    return json.dumps(ret)
コード例 #20
0
ファイル: screen.py プロジェクト: 1329555958/dashboard
def dash_graph_delete(gid):
    graph = DashboardGraph.get(gid)
    if not graph:
        abort(404, "no such graph")
    DashboardGraph.remove(gid)
    return redirect("/screen/" + graph.screen_id)
コード例 #21
0
ファイル: screen.py プロジェクト: soliChen/dashboard
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())