From dd38a22dc70a92dcc1ed086de8c8034ca33aba56 Mon Sep 17 00:00:00 2001 From: iSecloud <869820505@qq.com> Date: Tue, 19 Nov 2024 20:15:48 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(backend):=20itsm=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9=20#8049?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mysql/fixpoint_rollback/handlers.py | 2 +- .../dbm_init/json_files/itsm/itsm_dbm.json | 5 +++-- dbm-ui/backend/dbm_init/services.py | 16 +++++++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/dbm-ui/backend/db_services/mysql/fixpoint_rollback/handlers.py b/dbm-ui/backend/db_services/mysql/fixpoint_rollback/handlers.py index 1fbfaa1b85..11ca17de5a 100644 --- a/dbm-ui/backend/db_services/mysql/fixpoint_rollback/handlers.py +++ b/dbm-ui/backend/db_services/mysql/fixpoint_rollback/handlers.py @@ -341,7 +341,7 @@ def query_binlog_from_bklog( # 时间范围前后放大避免日志平台上传延迟 start_time=start_time - timedelta(minutes=minute_range), end_time=end_time + timedelta(minutes=minute_range), - query_string=f"host: {host_ip} AND port: {port}", + query_string=f"host: {host_ip} AND port: {port} AND cluster_id: {self.cluster.id}", ) if not binlogs: diff --git a/dbm-ui/backend/dbm_init/json_files/itsm/itsm_dbm.json b/dbm-ui/backend/dbm_init/json_files/itsm/itsm_dbm.json index 1060393861..c2b0a2a2b2 100644 --- a/dbm-ui/backend/dbm_init/json_files/itsm/itsm_dbm.json +++ b/dbm-ui/backend/dbm_init/json_files/itsm/itsm_dbm.json @@ -1,6 +1,6 @@ { "key": "request", - "name": "BK-DBM", + "name": "BK_DBM_V2", "desc": "bk-dbm\u5ba1\u6279\u5355\u636e", "workflow": { "is_deleted": false, @@ -1397,5 +1397,6 @@ "display_type": "OPEN", "display_role": "", "source": "custom", - "project_key": "bk_dbm_dev" + "project_key": "bk_dbm_dev", + "for_update": false } \ No newline at end of file diff --git a/dbm-ui/backend/dbm_init/services.py b/dbm-ui/backend/dbm_init/services.py index e64a6804a4..850f963b74 100644 --- a/dbm-ui/backend/dbm_init/services.py +++ b/dbm-ui/backend/dbm_init/services.py @@ -55,7 +55,6 @@ def auto_create_itsm_service() -> int: project_key = env.BK_ITSM_PROJECT_KEY dbm_catalog_name = "bk_dbm" - dbm_service_name = "BK_DBM" try: with open("backend/dbm_init/json_files/itsm/itsm_dbm.json", "r") as f: @@ -81,14 +80,16 @@ def auto_create_itsm_service() -> int: # 对服务进行创建/更新 dbm_service_json["project_key"] = project_key dbm_service_json["catalog_id"] = dbm_catalog_id - dbm_service_json["name"] = dbm_service_name + dbm_service_name = dbm_service_json["name"] + for_update = dbm_service_json.pop("for_update", False) + dbm_service_id = 0 try: if dbm_service_name not in children_services_map.keys(): # 服务不存在则创建服务 dbm_service_id = ItsmApi.import_service(params=dbm_service_json, use_admin=True)["id"] logger.info("itsm服务创建成功,服务id为: %s", dbm_service_id) - else: + elif for_update: # 服务存在则更新服务 dbm_service_id = children_services_map[dbm_service_name] dbm_service_json["id"] = dbm_service_id @@ -98,8 +99,13 @@ def auto_create_itsm_service() -> int: raise Exception("服务创建/更新失败,请联系管理员。错误信息: %s", e) # 更新到系统配置中 - SystemSettings.insert_setting_value(key=SystemSettingsEnum.BK_ITSM_SERVICE_ID.value, value=str(dbm_service_id)) - logger.info("服务创建/更新成功") + if dbm_service_id: + SystemSettings.insert_setting_value( + key=SystemSettingsEnum.BK_ITSM_SERVICE_ID.value, value=str(dbm_service_id) + ) + logger.info("服务创建/更新成功") + else: + logger.info("本次更新跳过...") return dbm_service_id @staticmethod From 13fbca379040445a7d86b00aa05a698730daff6e Mon Sep 17 00:00:00 2001 From: iSecloud <869820505@qq.com> Date: Tue, 19 Nov 2024 21:05:27 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(backend):=20=E4=BF=AE=E5=A4=8D=E4=BA=BA?= =?UTF-8?q?=E5=91=98=E7=AE=A1=E7=90=86=E8=BF=87=E6=BB=A4=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20#8053?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/db_services/dbpermission/db_authorize/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dbm-ui/backend/db_services/dbpermission/db_authorize/models.py b/dbm-ui/backend/db_services/dbpermission/db_authorize/models.py index 1cd2664ac6..96a83b477f 100644 --- a/dbm-ui/backend/db_services/dbpermission/db_authorize/models.py +++ b/dbm-ui/backend/db_services/dbpermission/db_authorize/models.py @@ -77,8 +77,12 @@ def create_log(cls, account_id, rule_id, operator, action): def get_notifiers(cls, rule_id): """获取通知人列表,目前只过滤有授权记录的人""" users = cls.objects.filter(rule_id=rule_id, action_type=RuleActionType.AUTH).values_list("operator", flat=True) + if not users: + return [] # 过滤离职的和虚拟账户 virtual_users = SystemSettings.get_setting_value(key=SystemSettingsEnum.VIRTUAL_USERS, default=[]) - real_users = UserManagerApi.list_users({"fields": "username", "exact_lookups": ",".join(users)})["results"] + real_users = UserManagerApi.list_users( + {"fields": "username", "exact_lookups": ",".join(users), "no_page": True} + ) real_users = [user["username"] for user in real_users] return list(set(real_users) - set(virtual_users))