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

feat: 【告警】告警通知里,针对集群信息补充环境类型字段 --story=121108605 #4401

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions bkmonitor/packages/fta_web/alert/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,8 @@ def get_cmdb_related_info(alerts: List[AlertDocument]) -> Dict[str, Dict]:

set_template = _("集群({}) ")
module_template = _("模块({})")
environment_template = _(" 环境类型({})")
environment_mapping = {"1": _("测试"), "2": _("体验"), "3": _("正式")}

def enrich_related_infos(bk_biz_id, instances):
ips = instances["ips"]
Expand Down Expand Up @@ -976,6 +978,7 @@ def enrich_related_infos(bk_biz_id, instances):
sets = api.cmdb.get_set(bk_biz_id=bk_biz_id, bk_set_ids=list(module_to_set.values()))
module_names = {module.bk_module_id: module.bk_module_name for module in modules}
set_names = {s.bk_set_id: s.bk_set_name for s in sets}
environment_types = {s.bk_set_id: s.bk_set_env for s in sets}

# 事件对应到模块ID
alert_to_module_ids = {}
Expand Down Expand Up @@ -1012,6 +1015,18 @@ def enrich_related_infos(bk_biz_id, instances):
[module_names[bk_module_id] for bk_module_id in bk_module_ids if bk_module_id in module_names]
)
)

if environment_types and bk_set_ids:
environments = []
for bk_set_id in bk_set_ids:
environment_type_id = environment_types.get(bk_set_id)
if environment_type_id is not None:
environment = environment_mapping.get(environment_type_id, str(environment_type_id))
environments.append(environment)

if environments:
topo_info += environment_template.format(",".join(environments))

related_infos[alert_id]["topo_info"] = topo_info

# 多线程处理每个业务的主机和服务实例信息
Expand Down