示例#1
0
def zabbixdraw(request):
    dir = "/data1/rrd"
    pngdir = r"/var/www/html/oms-master/static/images/rrdpng/"
    hostid = request.GET["hostid"]
    type = request.GET["type"]
    sql = (
        "select hostid, graphid, graphname, hostname from asset_drawtree where hostid="
        + hostid
        + " and type="
        + type
        + " and draw='1'"
    )
    graphs = DrawTree.objects.getclass(sql)
    pngs = []
    gdatas = []
    strtime = str(int(time.time() - 86400))
    for graph in graphs:
        hostid = graph[0]
        graphid = graph[1]
        graphname = graph[2]
        hostname = graph[3]
        rpath = dir + r"/" + hostid + r"/" + graphid + r".rrd"
        if not os.path.exists(pngdir + hostid + r"/"):
            os.makedirs(pngdir + hostid + r"/")
        pngname = pngdir + hostid + r"/" + graphid + r".png"
        sql = "select itemid,itemname,units from asset_drawgraphs where graphid=" + graphid
        pitem = DrawGraphs.objects.getdata(sql)
        sql = "select cols from asset_drawdef where graphid=" + graphid
        cols = DrawDef.objects.getdata(sql)
        if cols:
            cols = (cols[0][0].split(":"),)
        sql = "select types from asset_drawdef where graphid=" + graphid
        itypes = DrawDef.objects.getdata(sql)
        if itypes:
            itypes = (itypes[0][0].split(":"),)
        gdata = {
            "pname": pngname,
            "gname": graphname,
            "rrdpath": rpath,
            "pitem": pitem,
            "graphid": graphid,
            "cols": cols,
            "itypes": itypes,
            "host": hostname,
            "stime": strtime,
            "flag": "Daily",
        }

        gdatas.append(gdata)
        pngs.append({"pngpath": str(pngname).replace(r"/var/www/html/oms-master", ""), "graphid": graphid})
    drawrrd.drawmain(gdatas)
    return render_to_response("zabbixdraw.html", {"pngs": pngs})
示例#2
0
def drawall(request):
    gdatas = []
    pngs = []
    dir = r"/data1/rrd/"
    graphid = request.GET["graphid"]
    sql = "select hostid, graphname, hostname from asset_drawtree where graphid=" + graphid
    graph = DrawTree.objects.getclass(sql)
    hostid = graph[0][0]
    graphname = graph[0][1]
    hostname = graph[0][2]
    rpath = dir + hostid + r"/" + graphid + r".rrd"
    pngdir = r"/var/www/html/oms-master/static/images/rrdpng/cache"
    if not os.path.exists(pngdir + graphid):
        os.makedirs(pngdir + graphid + r"/")

    png2d = pngdir + graphid + r"/" + r"2d.png"
    pngs.append(str(png2d).replace(r"/var/www/html/oms-master", ""))
    png1w = pngdir + graphid + r"/" + r"1w.png"
    pngs.append(str(png1w).replace(r"/var/www/html/oms-master", ""))
    png1m = pngdir + graphid + r"/" + r"1m.png"
    pngs.append(str(png1m).replace(r"/var/www/html/oms-master", ""))
    png1y = pngdir + graphid + r"/" + r"1y.png"
    pngs.append(str(png1y).replace(r"/var/www/html/oms-master", ""))
    sql = "select itemid,itemname,units from asset_drawgraphs where graphid=" + graphid
    pitem = DrawGraphs.objects.getdata(sql)
    sql = "select cols from asset_drawdef where graphid=" + graphid
    cols = DrawDef.objects.getdata(sql)
    if cols:
        cols = (cols[0][0].split(":"),)
    sql = "select types from asset_drawdef where graphid=" + graphid
    itypes = DrawDef.objects.getdata(sql)
    if itypes:
        itypes = (itypes[0][0].split(":"),)
    sql = "select itemid,itemname,units from asset_drawgraphs where graphid=" + graphid
    pitem = DrawGraphs.objects.getdata(sql)
    strtime = str(int(time.time() - 86400))
    gdata = {
        "pname": png2d,
        "gname": graphname,
        "rrdpath": rpath,
        "pitem": pitem,
        "graphid": graphid,
        "cols": cols,
        "itypes": itypes,
        "host": hostname,
        "stime": strtime,
        "flag": "Daily",
    }
    gdatas.append(gdata)
    strtime = str(int(time.time() - 604800))
    gdata = {
        "pname": png1w,
        "gname": graphname,
        "rrdpath": rpath,
        "pitem": pitem,
        "graphid": graphid,
        "cols": cols,
        "itypes": itypes,
        "host": hostname,
        "stime": strtime,
        "flag": "Weekly",
    }
    gdatas.append(gdata)
    strtime = str(int(time.time() - 2592000))
    gdata = {
        "pname": png1m,
        "gname": graphname,
        "rrdpath": rpath,
        "pitem": pitem,
        "graphid": graphid,
        "cols": cols,
        "itypes": itypes,
        "host": hostname,
        "stime": strtime,
        "flag": "Monthly",
    }
    gdatas.append(gdata)
    strtime = str(int(time.time() - 31536000))
    gdata = {
        "pname": png1y,
        "gname": graphname,
        "rrdpath": rpath,
        "pitem": pitem,
        "graphid": graphid,
        "cols": cols,
        "itypes": itypes,
        "host": hostname,
        "stime": strtime,
        "flag": "Yearly",
    }
    gdatas.append(gdata)
    drawrrd.drawmain(gdatas)
    return render_to_response("drawall.html", {"pngs": pngs})