示例#1
0
def monitor_scene_fuzzy_search(data):
    if 'basic' == data['type']:
        base_unit = Monitor.objects.filter(
            Q(monitor_type=1) | Q(monitor_type=5)).filter(
                monitor_name__contains=data['condition']).order_by("-id")
        base_page_data, base_page_count = tools.page_paging(
            base_unit, data['limit'], data['page'])
        base_list = tools.obt_dic(base_page_data, base_page_count)
        res_dic = {
            'base_list': base_list,
        }
        result = tools.success_result(res_dic)
    return result
示例#2
0
def page_query_scene(request):
    """
    分页查询场景
    :param request:
    :return:
    """
    res = json.loads(request.body)
    res_content = res['data']
    #  个数
    limit = res['limit']
    #  当前页面号
    page = res['page']
    # 按id倒排序
    if res_content != "":
        unit = Scene.objects.filter(
            Q(scene_name__icontains=res_content)).order_by("-id")
    else:
        unit = Scene.objects.all().order_by('-id')
    # 进入分页函数进行分页,返回总页数和当前页数据
    page_data, base_page_count = tools.page_paging(unit, limit, page)
    res_list = []
    for scene_obj in page_data:
        starttime = tran_china_time_other(scene_obj.scene_startTime,
                                          scene_obj.scene_area)
        endtime = tran_china_time_other(scene_obj.scene_endTime,
                                        scene_obj.scene_area)

        dic = {
            'id': scene_obj.id,
            'scene_name': scene_obj.scene_name,
            'scene_startTime': str(starttime),
            'scene_endTime': str(endtime),
            'scene_creator': scene_obj.scene_creator,
            'scene_creator_time': str(scene_obj.scene_creator_time),
            'scene_editor': scene_obj.scene_editor,
            'scene_editor_time': str(scene_obj.scene_editor_time),
            'scene_area': scene_obj.scene_area,
            'scene_content': scene_obj.scene_content,
            'page_count': base_page_count,
        }
        res_list.append(dic)
    res_dic = {
        'scene_list': res_list,
    }
    return tools.success_result(res_dic)
示例#3
0
def select_unit(request):
    """
    查询监控项
    :param request:
    :return:
    """
    # try:
    res = json.loads(request.body)
    res1 = res['data']
    limit = res['limit']
    page = res['page']
    if res1 == "":
        unit = Monitor.objects.all().order_by("-id")
    else:
        # 模糊查询,根据id倒排序
        unit = Monitor.objects.filter(Q(monitor_name__icontains=res1) | Q(editor__icontains=res1)).order_by("-id")
    page_data, base_page_count = tools.page_paging(unit, limit, page)
    res_list = tools.obt_dic(page_data, base_page_count)
    res_data = tools.success_result(res_list)
    return res_data
示例#4
0
def unit_show(request):
    """
    显示函数
    :param request:
    :return:
    """
    # try:
    res = json.loads(request.body)
    #  个数
    limit = res['limit']
    #  当前页面号
    page = res['page']
    # 按id倒排序
    unit = Monitor.objects.all().order_by('-id')
    # 进入分页函数进行分页,返回总页数和当前页数据
    page_data, base_page_count = tools.page_paging(unit, limit, page)
    #  把返回的数据对象转为list
    res_list = tools.obt_dic(page_data, base_page_count)
    #注释开始------------------------张美庆,2019-5-16
    # param = {
    #     "bk_token": request.COOKIES['bk_token'],
    #     "bk_biz_id": 2
    # }
    # param1 = {
    #     "bk_token": request.COOKIES['bk_token'],
    #     "bk_biz_id": 2
    # }
    #  用user v2的方式调用接口
    # client = tools.user_interface_param()
    #  调用获取作业详情接口
    # res = client.job.get_job_list(param)
    #  调用获取标准运维模板详情接口
    #res1 = client.sops.get_template_list(param1)
    # if res.get('result'):
    #     job_list = res.get('data')
    # else:
    #     job_list = []
    #     logger.error(u"请求作业模板失败:%s" % res.get('message'))
    # if res1.get('result'):
    #     flow_list = res1.get('data')
    # else:
    #     flow_list = []
    #     logger.error(u"请求流程模板失败:%s" % res.get('message'))
    #job = []
    #flow = []
     #获取模板名称和ID
    # for flow_data in flow_list:
    #     dic2 = {
    #         'flow_name': flow_data['name'],
    #         'id': [{
    #             'name': flow_data['name'],
    #             'id': flow_data['id']
    #         }]
    #     }
    #     flow.append(dic2)
    # for job_data in job_list:
    #     dic1 = {
    #         'name': job_data['name'],
    #         'id': [{
    #             'name': job_data['name'],
    #             'id': job_data['bk_job_id']
    #         }]
    #     }
    #     job.append(dic1)
    # 注释开始------------------------张美庆,2019-5-16
    #接口在另一个方法中调用
    res_dic = {
        'res_list': res_list,
       # 'job': job,
       # 'flow': flow,
    }
    result = tools.success_result(res_dic)
    # except Exception as e:
    #     result = tools.error_result(e)
    return result
示例#5
0
def scene_show(res):
    """
    场景编排显示

    :param res:
    :return:
    """
    try:
        type = res['type']
        limit = res['limit']
        page = res['page']
        if type == 0:
            # 四类监控项全部按id倒排序(基本监控项与一体化基本监控项放一起)
            base_unit = Monitor.objects.filter(
                Q(monitor_type=1) | Q(monitor_type=5)).order_by("-id")
            base_page_data, base_page_count = tools.page_paging(
                base_unit, limit, page)
            # 四类监控项全部按id倒排序(图表监控项)
            chart_unit = Monitor.objects.filter(
                monitor_type='2').order_by("-id")
            chart_page_data, chart_page_count = tools.page_paging(
                chart_unit, limit, page)
            # 四类监控项全部按id倒排序(作业监控项)
            job_unit = Monitor.objects.filter(monitor_type='3').order_by("-id")
            job_page_data, job_page_count = tools.page_paging(
                job_unit, limit, page)
            # 四类监控项全部按id倒排序(流程监控项)
            flow_unit = Monitor.objects.filter(
                monitor_type='4').order_by("-id")
            flow_page_data, flow_page_count = tools.page_paging(
                flow_unit, limit, page)
            base_list = tools.obt_dic(base_page_data, base_page_count)
            chart_list = tools.obt_dic(chart_page_data, chart_page_count)
            job_list = tools.obt_dic(job_page_data, job_page_count)
            flow_list = tools.obt_dic(flow_page_data, flow_page_count)
            res_dic = {
                'base_list': base_list,
                'chart_list': chart_list,
                'job_list': job_list,
                'flow_list': flow_list,
            }
        # 基本监控项与一体化基本监控项
        elif type == 1:
            base_unit = Monitor.objects.filter(
                Q(monitor_type=1) | Q(monitor_type=5)).order_by("-id")
            base_page_data, base_page_count = tools.page_paging(
                base_unit, limit, page)
            base_list = tools.obt_dic(base_page_data, base_page_count)
            res_dic = {
                'base_list': base_list,
            }
        # 图表监控项
        elif type == 2:
            chart_unit = Monitor.objects.filter(
                monitor_type='2').order_by("-id")
            chart_page_data, chart_page_count = tools.page_paging(
                chart_unit, limit, page)
            chart_list = tools.obt_dic(chart_page_data, chart_page_count)
            res_dic = {
                'chart_list': chart_list,
            }
        # 作业监控项
        elif type == 3:
            job_unit = Monitor.objects.filter(monitor_type='3').order_by("-id")
            job_page_data, job_page_count = tools.page_paging(
                job_unit, limit, page)
            job_list = tools.obt_dic(job_page_data, job_page_count)
            job_status_list = []
            for i in job_list:
                try:
                    job_status = Job.objects.filter(
                        job_id=i['jion_id']).last().status
                except Exception as e:
                    job_status = 0
                job_status_list.append(job_status)
            for i in range(0, len(job_status_list)):
                job_list[i]['job_status'] = job_status_list[i]
            res_dic = {
                'job_list': job_list,
            }
        # 流程监控项
        elif type == 4:
            flow_unit = Monitor.objects.filter(
                monitor_type='4').order_by("-id")
            flow_page_data, flow_page_count = tools.page_paging(
                flow_unit, limit, page)
            flow_list = tools.obt_dic(flow_page_data, flow_page_count)
            res_dic = {
                'flow_list': flow_list,
            }
        result = tools.success_result(res_dic)
    except Exception as e:
        result = tools.error_result(e)
    return result