Пример #1
0
def gethistory_monitor():
    '''
    获取监控历史
    :return:
    '''
    result = {}
    dm_obj = dmonitor.DMonitor()

    monitor_id = request.values.get("monitor_id","")
    hours = request.values.get("hours","")

    status,data = dm_obj.get_history(monitor_id=monitor_id,hours=hours) # 默认获取24小时

    if status:
        result = {"code": 0, "message": data['status']['message']}
        dashs = data.get("monitor_history",[])
        record_name = data['record']['sub_domain'] + '.' + data['domain']['domain']
    else:
        result = {"code": 1, "message": data}
        dashs = []
        record_name = ""
    # return jsonify(dashs)

    return render_template('dnspod_monitor_history.html',result=result,dashs=dashs,
                           monitor_id=monitor_id,hours=hours,record_name = record_name)
Пример #2
0
def create_monitor():
    '''
    创建监控
    :return:
    '''
    dm_obj = dmonitor.DMonitor()
    result = {}
    if request.method == "POST":
        domain_id = request.form.get("domain_id","")
        record_id = request.form.get("record_id","")
        monitor_interval = int(request.form.get("monitor_interval",""))
        host = request.form.get("host","")
        port = request.form.get("port", "")
        monitor_path = request.form.get("monitor_path","")
        monitor_type = request.form.get("monitor_type","")
        points = request.form.get("points","")
        bak_ip = request.form.get("bak_ip","")

        # print domain_id,record_id,monitor_interval,host,port,monitor_path, monitor_type,points,bak_ip
        try:
            status,data = dm_obj.create(domain_id=domain_id,record_id=record_id,monitor_interval=monitor_interval,
                                        host=host,port=port,monitor_path=monitor_path,
                                        monitor_type=monitor_type,points=points,bak_ip=bak_ip)
            if status:
                result = {"code": 0, "message": data['status']['message']}
            else:
                result = {"code": 1, "message": data}
        except Exception as e:
            result = {"code": 1, "message": e}

    return redirect(url_for("b_dnspod.dnspod_d",
                            status=result.get("code", ""),
                            message=result.get("message", "")))
Пример #3
0
def getdowns_monitor():
    '''
    获取监控警告
    :return:
    '''
    result = {}
    dm_obj = dmonitor.DMonitor()

    if request.method == "GET":
        status,data = dm_obj.get_downs()
        return jsonify(data)
Пример #4
0
def monitor_info():
    '''
    获取监控信息
    :return:
    '''
    dm_obj = dmonitor.DMonitor()
    monitor_id = request.values.get("monitor_id","")
    status,data = dm_obj.info(monitor_id=monitor_id)
    if status:
        res = data.get("info")
        return jsonify(res)
    else:
        return jsonify(data)
Пример #5
0
def list_subvalue():
    '''
    列出子域名的A记录
    :return:
    '''
    dm_obj = dmonitor.DMonitor()

    domain_id = request.values.get("domain_id","")

    status, data = dm_obj.list_subdomain(domain_id=domain_id)
    sub_domains = []

    dic = {}
    st = time.time()
    if status:
        r_name = data.get("subdomain",[])
        for r in r_name:
            t = MyThread(dm_obj.list_sub_value,args=(None,domain_id,r))
            dic[r] = t
            t.start()
        for k,v in dic.items():
            v.join()  # 一定要join,不然主线程比子线程跑的快,会拿不到结果
            status, data = v.get_result()
            if status:
                s = dict(record_name=k,domain_name= data.get("domain").get("name"),
                         id=data.get("records")[0].get("id"),points=data.get("points").get("list"))
                sub_domains.append(s)
    et = time.time()
    # print et - st

    # st = time.time()
    # if status:
    #     r_name = data.get("subdomain",[])
    #     for r in r_name:
    #         status, data = dm_obj.list_sub_value(domain_id=domain_id,subdomain=r)
    #         if status:
    #             s = dict(record_name=r,domain_name= data.get("domain").get("name"),
    #                      id=data.get("records")[0].get("id"),points=data.get("points").get("list"))
    #             sub_domains.append(s)
    # et = time.time()
    # print et - st

    if request.method == "GET":
        return jsonify(sub_domains)
    else:
        record_id = request.values.get("record_id","")
        for s in sub_domains:
            if s['id'] == record_id:
                # print s
                return jsonify(s)
Пример #6
0
def remove_monitor():
    '''
    删除监控
    :return:
    '''
    dm_obj = dmonitor.DMonitor()
    monitor_id = request.values.get("monitor_id","")
    status,data = dm_obj.remove(monitor_id=monitor_id)
    if status:
        result = {"code": 0, "message": data['status']['message']}
    else:
        result = {"code": 1, "message": data}

    return redirect(url_for("b_dnspod.dnspod_d",
                            status=result.get("code", ""),
                            message=result.get("message", "")))
Пример #7
0
def list_subdomain():
    '''
    列出包含A记录的所有子域名
    :return:
    '''
    d_obj = Domain()
    dm_obj = dmonitor.DMonitor()

    domain_list = d_obj.list()

    id_list = [d.get("id") for d in domain_list]

    d2r_names = {}

    # st = time.time()
    li = []
    for did in id_list:
        t = MyThread(dm_obj.list_subdomain,args=(None,did))
        li.append(t)
        t.start()

    for t in li:
        t.join()  # 一定要join,不然主线程比子线程跑的快,会拿不到结果
        status, data = t.get_result()
        if status:
            d_name = data.get("domain",{}).get("name","")
            d_id = data.get("domain",{}).get("id","")
            r_name = data.get("subdomain",[])
            if r_name:
                d2r_names[d_name] = dict(id=d_id,rnames=r_name)
    # et = time.time()
    # print et - st

    # st = time.time()
    # for did in id_list:
    #     status,data = dm_obj.list_subdomain(domain_id=did)
    #     if status:
    #         d_name = data.get("domain",{}).get("name","")
    #         d_id = data.get("domain",{}).get("id","")
    #         r_name = data.get("subdomain",[])
    #         if r_name:
    #             d2r_names[d_name] = dict(id=d_id,rnames=r_name)
    # et = time.time()
    # print et - st

    # print d2r_names
    return jsonify(d2r_names)
Пример #8
0
def dnspod_d():
    result = {}
    monitors = []
    status = request.values.get("status", "")
    message = request.values.get("message", "")

    if status.isdigit():
        result = {"code":int(status),"message":message}

    if request.method == "GET":
        dm_obj = dmonitor.DMonitor()
        status_val, data = dm_obj.list()
        if status_val:
            monitors = data.get("monitors",[])
        else:
            result = {"code": 1, "message": data}

        return render_template("dnspod_monitors.html", monitors=monitors,
                               result=result)
Пример #9
0
def setstatus_monitor():
    '''
    设置监控状态
    :return:
    '''
    result = {}
    dm_obj = dmonitor.DMonitor()
    if request.method == "GET":
        status =  request.values.get("status","")
        monitor_id = request.values.get("monitor_id","")
        status_val,data = dm_obj.set_status(monitor_id=monitor_id,status=status)

        if status_val:
            result = {"code": 0, "message": data['status']['message']}
        else:
            result = {"code": 1, "message": data}

    return redirect(url_for("b_dnspod.dnspod_d",
                            status=result.get("code", ""),
                            message=result.get("message", "")))
Пример #10
0
def modify_monitor():
    '''
    修改监控
    :return:
    '''
    #必选参数
    result = {}
    dm_obj = dmonitor.DMonitor()
    if request.method == "POST":
        monitor_id = request.form.get("monitor_id","")
        host = request.form.get("host","")
        monitor_path = request.form.get("monitor_path","")
        port = request.form.get("port","")
        monitor_interval = int(request.form.get("monitor_interval",""))
        monitor_type = request.form.get("monitor_type","")
        points = request.form.getlist("points")
        bak_ip = request.form.get("bak_ip","")
        #可选参数
        keep_ttl = request.form.get("keep_ttl","")
        sms_notice = request.form.get("sms_notice","")
        email_notice = request.form.get("email_notice","")
        less_notice = request.form.get("less_notice", "")
        callback_url = request.form.get("callback_url","")
        callback_key = request.form.get("callback_key","")

        # print monitor_id,monitor_interval,host,port,monitor_path, monitor_type,points,bak_ip,keep_ttl,\
        #     sms_notice,email_notice,less_notice,callback_url,callback_key

        status,data = dm_obj.modify(monitor_id=monitor_id,host=host,monitor_path=monitor_path,
                                    port=port,monitor_interval=monitor_interval,monitor_type=monitor_type,
                                    points=points,bak_ip=bak_ip,
                                    keep_ttl=keep_ttl,sms_notice=sms_notice,email_notice=email_notice,
                                    less_notice=less_notice,callback_url=callback_url,callback_key=callback_key)
        if status:
            result = {"code": 0, "message": data['status']['message']}
        else:
            result = {"code": 1, "message": data}

    return redirect(url_for("b_dnspod.dnspod_d",
                            status=result.get("code", ""),
                            message=result.get("message", "")))