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: 【产品功能】补充cmdb元数据 --story=121426827 #4672

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
26 changes: 26 additions & 0 deletions bklog/apps/log_databus/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@

DEFAULT_RETENTION = 14

# 节点管理支持的cmdb变量
CC_HOST_FIELDS = [
"bk_host_id",
"bk_agent_id",
"bk_cloud_id",
"bk_addressing",
"bk_host_innerip",
"bk_host_outerip",
"bk_host_innerip_v6",
"bk_host_outerip_v6",
"bk_host_name",
"bk_os_type",
"bk_os_name",
"bk_os_bit",
"bk_os_version",
"bk_cpu_module",
"operator",
"bk_bak_operator",
"bk_isp_name",
"bk_biz_id",
"bk_province_name",
"bk_state",
"bk_state_name",
"bk_supplier_account",
"bk_cpu_architecture",
]

class VisibleEnum(ChoicesEnum):
# 当前业务可见
Expand Down
9 changes: 9 additions & 0 deletions bklog/apps/log_databus/handlers/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
TargetNodeTypeEnum,
TopoType,
WorkLoadType,
CC_HOST_FIELDS,
)
from apps.log_databus.exceptions import (
AllNamespaceNotAllowedException,
Expand Down Expand Up @@ -841,6 +842,14 @@ def update_or_create(self, params: dict) -> dict:
is_display = params.get("is_display", True)
params["params"]["encoding"] = data_encoding
params["params"]["run_task"] = params.get("run_task", True)

# cmdb元数据补充
extra_labels = params["params"].get("extra_labels")
zzz833708 marked this conversation as resolved.
Show resolved Hide resolved
if extra_labels:
for item in extra_labels:
if item["key"] in CC_HOST_FIELDS:
zzz833708 marked this conversation as resolved.
Show resolved Hide resolved
item["value"] = "{{cmdb_instance.host." + item["key"] + "}}"

# 1. 创建CollectorConfig记录
model_fields = {
"collector_config_name": collector_config_name,
Expand Down