Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backend): itsm模型更新逻辑修改 #8049 #8050

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions dbm-ui/backend/dbm_init/json_files/itsm/itsm_dbm.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"key": "request",
"name": "BK-DBM",
"name": "BK_DBM_V2",
"desc": "bk-dbm\u5ba1\u6279\u5355\u636e",
"workflow": {
"is_deleted": false,
Expand Down Expand Up @@ -1397,5 +1397,6 @@
"display_type": "OPEN",
"display_role": "",
"source": "custom",
"project_key": "bk_dbm_dev"
"project_key": "bk_dbm_dev",
"for_update": false
}
16 changes: 11 additions & 5 deletions dbm-ui/backend/dbm_init/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading