Exemplo n.º 1
0
def updateAps():
    result = Auth.identify(Auth, request)
    if result['status'] and result['data']:
        fromData = request.json
        scheduling = Scheduling.query.get_or_404(fromData['scheduling_id'])
        schedulingJson = {}
        schedulingJson['scheduling_id'] = scheduling.scheduling_id
        schedulingJson['scheduling_title'] = scheduling.scheduling_title
        schedulingJson['scheduling_on'] = scheduling.scheduling_on
        schedulingJson['scheduling_cron'] = scheduling.scheduling_cron
        schedulingJson['email_address'] = scheduling.email_address
        taskCaseList = TaskCase.query.filter(
            TaskCase.scheduling_id == fromData["scheduling_id"]).all()
        task_jsonarray = []
        for task in taskCaseList:
            task_dict = {}
            task_dict['task_id'] = task.task_id
            task_dict['case_id'] = task.case_id
            user_case = UserCase.query.get_or_404(task.case_id)
            task_dict['scheduling_id'] = task.scheduling_id
            task_dict['case_name'] = user_case.case_name
            task_dict['request_address'] = user_case.request_address
            task_jsonarray.append(task_dict)
        schedulingJson['caseData'] = task_jsonarray

        return jsonify(common.trueReturn(schedulingJson, '任务查询成功'))
    else:
        return jsonify(result)
Exemplo n.º 2
0
def create_app(config_name=None):

    if config_name is None:
        config_name = os.getenv('FLASK_CONFIG', 'development')

    app = Flask('interface')
    app.config.from_object(config[config_name])
    CORS(app, supports_credentials=True, resources=r'/*')
    auth = Auth()
    JWT(app, auth.authenticate, auth.identify)
    # 注册日志处理
    register_logging(app)
    # 注册扩展(初始化)
    register_extensions(app)
    # 注册蓝本
    register_blueprints(app)
    # 注册自定义shell命令
    register_commands(app)
    # 注册错误处理函数
    register_errors(app)
    # 注册shell 上下文处理函数
    register_shell_context(app)
    # 注册模板上下文处理函数
    register_template_context(app)
    register_request_handlers(app)
    return app
Exemplo n.º 3
0
def update():
    result = Auth.identify(Auth, request)
    if result['status'] and result['data']:
        fromData = request.json
        scheduling = Scheduling.query.get_or_404(fromData['scheduling_id'])
        scheduling.scheduling_title = fromData['scheduling_title']
        scheduling.scheduling_cron = fromData['scheduling_cron']
        scheduling.email_address = fromData['email_address']
        db.session.commit()
        taskList = fromData['caseList']
        TaskCase.query.filter(
            TaskCase.scheduling_id == fromData["scheduling_id"]).delete(
                synchronize_session=False)
        db.session.commit()
        for task in taskList:
            taskCase = TaskCase(scheduling_id=fromData['scheduling_id'],
                                case_id=task['case_id'])
            db.session.add(taskCase)
            db.session.commit()
        # 删除任务
        remove_task(fromData['scheduling_id'])
        # 添加任务
        addtask(fromData, fromData['scheduling_id'])

        return jsonify(common.trueReturn('', '修改成功'))
    else:
        return jsonify(result)
Exemplo n.º 4
0
def addjob():
    """
    添加任务
    :return:
    """
    result = Auth.identify(Auth, request)
    if result['status'] and result['data']:

        fromData = request.json
        caseList = fromData['caseList']
        cronStr = fromData['scheduling_cron']
        scheduling_title = fromData['scheduling_title']
        email_address = fromData['email_address']
        cronStr = cronStr.replace("?", "*")
        cronStrValue = cronStr
        id = str(uuid.uuid1()).replace('-', '')
        scheduling = Scheduling(scheduling_id=id,
                                scheduling_title=scheduling_title,
                                scheduling_cron=str(cronStrValue),
                                scheduling_on='0',
                                email_address=email_address)
        db.session.add(scheduling)
        db.session.commit()
        for case in caseList:
            taskCase = TaskCase(scheduling_id=id, case_id=case['case_id'])
            db.session.add(taskCase)
            db.session.commit()
        addtask(fromData, id)
        return jsonify(common.trueReturn('', '任务新增成功'))
    else:
        return jsonify(result)
Exemplo n.º 5
0
def getReportCaseList():
    result = Auth.identify(Auth, request)
    if result['status'] and result['data']:
        fromData = request.json
        casePass = [
            Report.uc_id == fromData['case_id'],
            Report.scheduling_id == fromData['scheduling_id']
        ]
        reportList = Report.query.filter(*casePass).all()
        report_dict = []
        for report in reportList:
            report_json = {}
            report_json['report_id'] = report.report_id
            report_json['report_title'] = report.report_title
            report_json['report_url'] = report.report_url
            report_json['report_env_param'] = report.report_env_param
            report_json['report_env_status'] = report.report_env_status
            report_json['report_env_time'] = report.report_env_time
            report_json['report_env_response'] = report.report_env_response
            report_json['report_env_pass'] = report.report_env_pass
            report_dict.append(report_json)

        return jsonify(common.trueReturn(report_dict, '日志列表查询成功'))
    else:
        return jsonify(result)
Exemplo n.º 6
0
def getLogCaseList():
    """
    case列表
    :return:
    """
    result = Auth.identify(Auth, request)
    if result['status'] and result['data']:
        fromData = request.json
        param = [Report.scheduling_id == fromData['scheduling_id']]
        reporteList = Report.query.filter(*param).group_by(
            Report.uc_id).order_by(Report.report_create_time.desc()).all()
        caseList = []
        log_case_pass = 0
        for report in reporteList:
            case = {}
            user_case = UserCase.query.get_or_404(report.uc_id)
            case['log_case_name'] = user_case.case_name
            case['log_case_id'] = user_case.uc_id
            casePass = [
                Report.report_env_pass == '1', Report.uc_id == report.uc_id
            ]
            casePass = Report.query.filter(*casePass).all()
            if len(casePass) > 0:
                log_case_pass = 1
            else:
                log_case_pass = 0
            case['log_case_pass'] = log_case_pass
            caseList.append(case)
        # vueExecl 表格下载
        loadCaseList = getLoadCaseList(fromData['scheduling_id'])

        resBody = {}
        resBody['caseList'] = caseList
        resBody['loadCaseList'] = loadCaseList
        return jsonify(common.trueReturn(resBody, '日志列表查询成功'))
Exemplo n.º 7
0
def resume():
    result = Auth.identify(Auth, request)
    if result['status'] and result['data']:
        fromData = request.json
        resumetask(fromData["scheduling_id"])
        scheduling = Scheduling.query.get_or_404(fromData['scheduling_id'])
        scheduling.scheduling_on = '0'
        db.session.commit()
        return jsonify(common.trueReturn('', '恢复任务'))
    else:
        return jsonify(result)
Exemplo n.º 8
0
def index():
    """
    任务查询
    :param page: 页数
    :return:
    """
    result = Auth.identify(Auth, request)
    if result['status'] and result['data']:
        fromData = json.loads(request.args['0'])
        page = fromData['page']
        param = []
        # 拼接查询条件
        if fromData['scheduling_title'] != 'None' and len(
                fromData['scheduling_title']) > 0:
            param.append(
                Scheduling.scheduling_title.like("%" +
                                                 fromData['scheduling_title'] +
                                                 "%"))

        # 每页显示数
        per_page = current_app.config['INTERFACE_PER_PAGE']
        # 分页对象
        pagination = Scheduling.query.filter(*param).paginate(
            page, per_page=per_page)

        # 总条数
        count = Scheduling.query.filter(*param).count()
        # # 总页数
        page_count = math.ceil(count / per_page)
        # print('总页数 ', page_count)
        # 当前页数的记录列表
        schedulingList = pagination.items
        scheduling_list = []
        for item in schedulingList:
            scheduling_dic = {}
            scheduling_dic['scheduling_id'] = item.scheduling_id
            scheduling_dic['scheduling_title'] = item.scheduling_title
            scheduling_dic['scheduling_cron'] = item.scheduling_cron
            scheduling_dic['scheduling_on'] = item.scheduling_on
            scheduling_dic['email_address'] = item.email_address
            scheduling_list.append(scheduling_dic)
        list_dic = {}
        list_dic['list'] = scheduling_list
        list_dic['count'] = count
        list_dic['page_count'] = page_count
        list_dic['per_page'] = per_page
        get_task()
        return jsonify(common.trueReturn(list_dic, '任务查询成功'))
    else:
        return jsonify(result)
Exemplo n.º 9
0
def deleteType():
    """
    删除case
    :return:
    """
    result = Auth.identify(Auth, request)
    if result['status'] and result['data']:
        report_case_type = request.json.get('report_case_type')
        Report.query.filter_by(report_case_type=report_case_type).delete(
            synchronize_session=False)
        db.session.commit()
        return jsonify(common.trueReturn('', '日志删除成功'))
    else:
        return jsonify(result)
Exemplo n.º 10
0
def getReportList():
    """
    查询case报告列表
    :return:
    """
    result = Auth.identify(Auth, request)
    if result['status'] and result['data']:
        fromData = json.loads(request.args['0'])
        case_id = fromData['case_id']
        # page = fromData['page']
        param = [Report.uc_id == case_id]
        # 拼接查询条件
        # 每页显示数
        # per_page = 5
        # 分页对象
        # pagination = Report.query.filter(*param).group_by(Report.report_case_type).order_by(
        #     Report.report_create_time).paginate(page, per_page=per_page)
        # # 总条数
        # count = Report.query.filter(*param).group_by(Report.report_case_type).count()
        # # # 总页数
        # page_count = math.ceil(count / per_page)
        # # print('总页数 ', page_count)
        # # 当前页数的记录列表
        # reportList = pagination.items
        reportList = Report.query.filter(*param).group_by(
            Report.report_case_type).order_by(
                Report.report_create_time.desc()).all()
        report_dict = []
        for report in reportList:
            report_json = {}
            report_json['report_id'] = report.report_id
            report_json['report_title'] = report.report_title
            report_json['report_case_type'] = report.report_case_type
            report_json['report_create_time'] = report.report_create_time
            report_json['case_id'] = report.uc_id
            report_dict.append(report_json)
        list_dic = {}
        list_dic['list'] = report_dict
        # list_dic['count'] = count
        # list_dic['page_count'] = page_count
        # list_dic['per_page'] = per_page

        return jsonify(common.trueReturn(list_dic, '日志列表查询成功'))
    else:
        return jsonify(result)
Exemplo n.º 11
0
def delete():
    """
    删除任务
    :return:
    """
    result = Auth.identify(Auth, request)
    if result['status'] and result['data']:
        fromData = request.json
        Scheduling.query.filter_by(
            scheduling_id=fromData["scheduling_id"]).delete(
                synchronize_session=False)
        db.session.commit()
        TaskCase.query.filter(
            TaskCase.scheduling_id == fromData["scheduling_id"]).delete(
                synchronize_session=False)
        db.session.commit()
        get_task()
        print(fromData["scheduling_id"])
        remove_task(fromData["scheduling_id"])
        return jsonify(common.trueReturn('', '删除成功'))
    else:
        return jsonify(result)
Exemplo n.º 12
0
def startExecution():
    result = Auth.identify(Auth, request)
    if result['status'] and result['data']:
        fromData = request.json
        taskCaseList = TaskCase.query.filter(
            TaskCase.scheduling_id == fromData["scheduling_id"]).all()
        task_jsonarray = []
        for task in taskCaseList:
            task_dict = {}
            task_dict['task_id'] = task.task_id
            task_dict['case_id'] = task.case_id
            user_case = UserCase.query.get_or_404(task.case_id)
            task_dict['scheduling_id'] = task.scheduling_id
            task_dict['case_name'] = user_case.case_name
            task_dict['request_address'] = user_case.request_address
            task_jsonarray.append(task_dict)
            # 删除该调度日志
        test_caseList(task_jsonarray,
                      fromData["scheduling_id"],
                      email_address=fromData["email_address"])
        return jsonify(common.trueReturn('', '执行完成'))
    else:
        return jsonify(result)
Exemplo n.º 13
0
def getReport():
    """
    查询case报告
    :return:
    """
    result = Auth.identify(Auth, request)
    if result['status'] and result['data']:
        fromData = json.loads(request.args['0'])
        case_id = fromData['case_id']
        page = fromData['page']
        param = [Report.uc_id == case_id]
        try:
            param.append(
                Report.report_case_type == fromData['report_case_type'])
        except Exception as e:
            report = Report.query.with_entities(
                Report.report_create_time, Report.report_case_type).filter(
                    Report.uc_id == case_id).order_by(
                        Report.report_create_time.desc()).first()
            param.append(Report.report_case_type == report.report_case_type)
            # param.append(Report.report_create_time == report.report_create_time)
        # 拼接查询条件
        if fromData['report_url'] != 'None' and len(
                fromData['report_url']) > 0:
            param.append(
                Report.report_url.like("%" + fromData['report_url'] + "%"))
        if fromData['report_env_pass'] != 'None' and len(
                fromData['report_env_pass']) > 0:
            param.append(Report.report_env_pass == fromData['report_env_pass'])
        # 每页显示数
        per_page = 5
        # 分页对象
        pagination = Report.query.filter(*param).paginate(page,
                                                          per_page=per_page)

        # 总条数
        count = Report.query.filter(*param).count()
        # # 总页数
        page_count = math.ceil(count / per_page)
        # print('总页数 ', page_count)
        # 当前页数的记录列表
        reportList = pagination.items
        report_dict = []
        for report in reportList:
            report_json = {}
            report_json['report_id'] = report.report_id
            report_json['report_title'] = report.report_title
            report_json['report_url'] = report.report_url
            report_json['report_env_param'] = report.report_env_param
            report_json['report_env_status'] = report.report_env_status
            report_json['report_env_time'] = report.report_env_time
            report_json['report_env_response'] = report.report_env_response
            report_json['report_env_pass'] = report.report_env_pass
            report_dict.append(report_json)
        list_dic = {}
        list_dic['list'] = report_dict
        list_dic['count'] = count
        list_dic['page_count'] = page_count
        list_dic['per_page'] = per_page
        return jsonify(common.trueReturn(list_dic, '日志查询成功'))
    else:
        return jsonify(result)