def db_sqlorder_osc(request,id): if request.method == "POST" and request.POST.get('model') == 'query': order = SQL_Audit_Order.objects.get(id=id) inceptRbt = Inception() sqlResultList = SQL_Order_Execute_Result.objects.filter(order=order) for ds in sqlResultList: if ds.backup_db.find('None') == -1: if ds.sqlsha: result = inceptRbt.getOscStatus(sqlSHA1=ds.sqlsha) if result.get('status') == 'success': return JsonResponse({"code":200,"data":result.get('data')}) else:return JsonResponse({"code":500,"data":result.get('data')}) elif request.method == "POST" and request.POST.get('model') == 'stop': order = SQL_Audit_Order.objects.get(id=id) inceptRbt = Inception() sqlResultList = SQL_Order_Execute_Result.objects.filter(order=order) for ds in sqlResultList: if ds.backup_db.find('None') == -1: if ds.sqlsha: result = inceptRbt.stopOsc(sqlSHA1=ds.sqlsha) if result.get('status') == 'success': return JsonResponse({"code":200,"data":result.get('data')}) else: return JsonResponse({"code":500,"data":result.get('errinfo')})
def db_sqlorder_osc(request, id): if request.method == "POST" and request.POST.get('model') == 'query': order = SQL_Audit_Order.objects.get(id=id) inceptRbt = Inception() sqlResultList = SQL_Order_Execute_Result.objects.filter(order=order) for ds in sqlResultList: if ds.backup_db.find('None') == -1: if ds.sqlsha: result = inceptRbt.getOscStatus(sqlSHA1=ds.sqlsha) if result.get('status') == 'success': return JsonResponse({ "code": 200, "data": result.get('data') }) else: return JsonResponse({ "code": 500, "data": result.get('data') }) elif request.method == "POST" and request.POST.get('model') == 'stop': order = SQL_Audit_Order.objects.get(id=id) inceptRbt = Inception() sqlResultList = SQL_Order_Execute_Result.objects.filter(order=order) for ds in sqlResultList: if ds.backup_db.find('None') == -1: if ds.sqlsha: result = inceptRbt.stopOsc(sqlSHA1=ds.sqlsha) if result.get('status') == 'success': return JsonResponse({ "code": 200, "data": result.get('data') }) else: return JsonResponse({ "code": 500, "data": result.get('errinfo') })
"审核失败,工单({desc})已经存在".format( desc=request.POST.get('order_desc')), "code": 500, 'data': [] }) try: db = DataBase_Server_Config.objects.get(id=int(dbId)) except Exception, ex: logger.error(msg="获取数据库配置信息失败: {ex}".format(ex=str(ex))) return JsonResponse({'msg': str(ex), "code": 500, 'data': []}) if request.POST.get('order_type') == 'online': try: incept = Inception(host=db.db_host, name=db.db_name, user=db.db_user, passwd=db.db_passwd, port=db.db_port) result = incept.checkSql(request.POST.get('order_sql')) if result.get('status') == 'success': count = 0 sList = [] for ds in result.get('data'): if ds.get('errlevel') > 0 and ds.get('errmsg'): count = count + 1 sList.append({ 'sql': ds.get('sql'), 'row': ds.get('affected_rows'), 'errmsg': ds.get('errmsg') }) if count > 0:
@permission_required('OpsManage.can_read_sql_audit_order',login_url='/noperm/') def db_sqlorder_run(request,id): try: if request.user.is_superuser:order = Order_System.objects.get(id=id) else:order = Order_System.objects.filter(Q(order_user=request.user.id,id=id) | Q(order_executor=request.user.id,id=id))[0] incept = Inception_Server_Config.objects.get(id=1) if request.user.id != order.order_executor:order.prem = 0 else:order.prem = 1 except Exception,ex: logger.error(msg="执行SQL[{id}]错误: {ex}".format(id=id,ex=str(ex))) return render(request,'database/db_sqlorder_run.html',{"user":request.user,"errinfo":"工单不存在,或者您没有权限处理这个工单"}) try: inceptRbt = Inception( host=incept.db_backup_host, name=order.sql_audit_order.order_db.db_name, user=order.sql_audit_order.order_db.db_user, passwd=order.sql_audit_order.order_db.db_passwd, port=order.sql_audit_order.order_db.db_port ) except Exception,ex: return render(request,'database/db_sqlorder_run.html',{"user":request.user,"errinfo":"Inception配置错误"}) if request.method == "GET": oscStatus = None sqlResultList = [] rollBackSql = [] order.order_user = User.objects.get(id=order.order_user).username order.order_executor = User.objects.get(id=order.order_executor).username try: order.sql_audit_order.order_db.db_service = Service_Assets.objects.get(id=order.sql_audit_order.order_db.db_service) except Exception, ex: order.sql_audit_order.order_db.db_service = '未知'
dbId = request.POST.get('order_db') if SQL_Audit_Order.objects.filter( order_desc=request.POST.get('order_desc')).count() > 0: return JsonResponse({ 'msg': "审核失败,工单({desc})已经存在".format( desc=request.POST.get('order_desc')), "code": 500, 'data': [] }) try: db = DataBase_Server_Config.objects.get(id=int(dbId)) incept = Inception(host=db.db_host, name=db.db_name, user=db.db_user, passwd=db.db_passwd, port=db.db_port) result = incept.checkSql(request.POST.get('order_sql')) if result.get('status') == 'success': count = 0 sList = [] for ds in result.get('data'): if ds.get('errlevel') > 0 and ds.get('errmsg'): count = count + 1 sList.append({ 'sql': ds.get('sql'), 'row': ds.get('affected_rows'), 'errmsg': ds.get('errmsg') }) if count > 0:
"serviceList":serviceList,"projectList":projectList}) elif request.method == "POST": if request.POST.get('type') == 'audit': dbId = request.POST.get('order_db') if Order_System.objects.filter(order_subject=request.POST.get('order_desc'),order_type=0).count() > 0: return JsonResponse({'msg':"审核失败,工单({desc})已经存在".format(desc=request.POST.get('order_desc')),"code":500,'data':[]}) try: db = DataBase_Server_Config.objects.get(id=int(dbId)) except Exception,ex: logger.error(msg="获取数据库配置信息失败: {ex}".format(ex=str(ex))) return JsonResponse({'msg':str(ex),"code":500,'data':[]}) if request.POST.get('order_type') == 'online': try: incept = Inception( host=db.db_host,name=db.db_name, user=db.db_user,passwd=db.db_passwd, port=db.db_port ) result = incept.checkSql(request.POST.get('order_sql')) if result.get('status') == 'success': count = 0 sList = [] for ds in result.get('data'): if ds.get('errlevel') > 0 and ds.get('errmsg'):count = count + 1 sList.append({'sql':ds.get('sql'),'row':ds.get('affected_rows'),'errmsg':ds.get('errmsg')}) if count > 0:return JsonResponse({'msg':"审核失败,请检查SQL语句","code":500,'data':sList}) else: mask='【已自动授权】' if config.t_auto_audit == 1 and db.db_env == 'test':order_status = 8 elif config.p_auto_audit == 1 and db.db_env == 'prod':order_status = 8 else: