def update_sql_work(obj): sql_info = get_sql_info_by_id(obj.sql_id) if (obj.current_user_id != sql_info.create_user_id): return "你不能编辑此工单,你不是工单创建者!" audit_result = inception_util.sql_audit(get_use_db_sql(obj.sql_value, obj.db_name), cache.MyCache().get_mysql_host_info(obj.host_id)) if (get_sql_execute_status(audit_result) == False): return "提交的SQL有错误,请仔细检查!" sql = """update `mysql_audit`.`sql_work` set `title` = '{0}', `jira_url` = '{1}', `execute_user_id` = {2}, `is_backup` = {3}, sleep = {4}, `execute_user_name` = '{5}', audit_user_id = {6}, audit_user_name = '{7}', `sql_value` = '{8}', audit_result_value = '{9}' where id = {10};""".format(db_util.DBUtil().escape(str(obj.title)), db_util.DBUtil().escape(str(obj.jira_url)), obj.dba_user_id, obj.is_backup, obj.sleep_time, cache.MyCache().get_user_chinese_name(obj.dba_user_id), obj.audit_user_tmp, cache.MyCache().get_user_chinese_name(obj.audit_user_tmp), db_util.DBUtil().escape(obj.sql_value), db_util.DBUtil().escape(json.dumps(audit_result, default=lambda o: o.__dict__)), obj.sql_id) db_util.DBUtil().execute(settings.MySQL_HOST, sql) return "更新成功!"
def audit_sql(obj): obj.sql = get_use_db_sql(obj.sql, obj.db_name) return render_template("audit_view.html", audit_infos=inception_util.sql_audit( obj.sql, cache.MyCache().get_mysql_host_info( obj.host_id)))
def audit_sql_by_sql_id(sql_id): sql_info = get_sql_info_by_id(sql_id) sql_info.sql_value = get_use_db_sql(sql_info.sql_value, sql_info.execute_db_name) return render_template("audit_view.html", audit_infos=inception_util.sql_audit( sql_info.sql_value, cache.MyCache().get_mysql_host_info( sql_info.mysql_host_id)))
def add_sql_work(obj): try: audit_result = inception_util.sql_audit( get_use_db_sql(obj.sql_value, obj.db_name), cache.MyCache().get_mysql_host_info(obj.host_id)) if (get_sql_execute_status(audit_result) == False): return "提交的SQL有错误,请审核之后在提交!" user_info = cache.MyCache().get_user_info(obj.current_user_id) sql = """INSERT INTO `mysql_audit`.`sql_work` (`create_user_id`, `audit_user_id`, `audit_date_time`, `execute_date_time`, `mysql_host_id`, `jira_url`, `is_backup`, `sql_value`, `return_value`, `status`, `title`, `audit_result_value`, `execute_db_name`, `create_user_group_id`, sleep, `create_user_name`, `audit_user_name`, `execute_user_name`, `execute_user_id`) VALUES ({0}, {1}, NOW(), NULL, {2}, '{3}', {4}, '{5}', '', {6}, '{7}', '{8}', '{9}', {10}, {11}, '{12}', '{13}', '{14}', {15});""" \ .format(obj.current_user_id, obj.audit_user_id, obj.host_id, db_util.DBUtil().escape(str(obj.jira_url)), obj.is_backup, db_util.DBUtil().escape(obj.sql_value), settings.SQL_NO_AUDIT, db_util.DBUtil().escape(str(obj.title)), db_util.DBUtil().escape(json.dumps(audit_result, default=lambda o: o.__dict__)), obj.db_name, user_info.group_id, obj.sleep_time, user_info.chinese_name, cache.MyCache().get_user_chinese_name(obj.audit_user_id), cache.MyCache().get_user_chinese_name(obj.dba_user_id), obj.dba_user_id) db_util.DBUtil().execute(settings.MySQL_HOST, sql) send_mail_for_create(0) return "创建SQL工单成功" except Exception, e: traceback.print_exc() return e.message