From 0f9785632635ce4ffb6fecb184a6fa66f306d18c Mon Sep 17 00:00:00 2001 From: durant <826035498@qq.com> Date: Wed, 25 Sep 2024 19:24:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(backend):=20=E7=8B=AC=E7=AB=8B=E6=89=98?= =?UTF-8?q?=E7=AE=A1=E4=B8=9A=E5=8A=A1=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=9B=91=E6=8E=A7=E7=AD=96=E7=95=A5=E7=9B=AE=E6=A0=87=E8=8C=83?= =?UTF-8?q?=E5=9B=B4=20#7128?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/db_periodic_task/local_tasks/db_monitor.py | 9 +++++++-- dbm-ui/backend/flow/utils/cc_manage.py | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/dbm-ui/backend/db_periodic_task/local_tasks/db_monitor.py b/dbm-ui/backend/db_periodic_task/local_tasks/db_monitor.py index dd0d02f78b..6d75995fda 100644 --- a/dbm-ui/backend/db_periodic_task/local_tasks/db_monitor.py +++ b/dbm-ui/backend/db_periodic_task/local_tasks/db_monitor.py @@ -73,7 +73,7 @@ def update_dba_notice_group(dba_id: int): @register_periodic_task(run_every=crontab(minute="*/5")) -def sync_plat_monitor_policy(action_id=None): +def sync_plat_monitor_policy(action_id=None, db_type=None, force=False): """同步平台告警策略""" if action_id is None: action_id = get_dbm_autofix_action_id() @@ -88,6 +88,7 @@ def sync_plat_monitor_policy(action_id=None): dirs.remove(skip_dir) for alarm_tpl in files: + with open(os.path.join(root, alarm_tpl), "r", encoding="utf-8") as f: logger.info("[sync_plat_monitor_policy] start sync bkm alarm tpl: %s " % alarm_tpl) try: @@ -99,6 +100,10 @@ def sync_plat_monitor_policy(action_id=None): logger.error("[sync_plat_monitor_policy] load template failed: %s", alarm_tpl) continue + # 如指定db_type,只同步指定db_type的策略(跳过非指定db_type的策略) + if db_type is not None and template_dict["db_type"] != db_type: + continue + deleted = template_dict.pop("deleted", False) if not template_dict.get("details"): @@ -142,7 +147,7 @@ def sync_plat_monitor_policy(action_id=None): synced_policy.delete() continue - if synced_policy.version >= policy.version: + if synced_policy.version >= policy.version and not force: logger.info("[sync_plat_monitor_policy] skip same version alarm: %s " % policy_name) continue diff --git a/dbm-ui/backend/flow/utils/cc_manage.py b/dbm-ui/backend/flow/utils/cc_manage.py index ec080d29a1..6e6503fac4 100644 --- a/dbm-ui/backend/flow/utils/cc_manage.py +++ b/dbm-ui/backend/flow/utils/cc_manage.py @@ -22,6 +22,7 @@ from backend.db_meta.models import AppMonitorTopo, Cluster, ClusterMonitorTopo, Machine, StorageInstance from backend.db_meta.models.cluster_monitor import INSTANCE_MONITOR_PLUGINS, SET_NAME_TEMPLATE from backend.db_monitor.models import CollectInstance +from backend.db_periodic_task.local_tasks import sync_plat_monitor_policy from backend.db_services.cmdb.biz import get_or_create_cmdb_module_with_name, get_or_create_set_with_name from backend.db_services.ipchooser.constants import IDLE_HOST_MODULE from backend.db_services.ipchooser.query.resource import ResourceQueryHelper @@ -111,6 +112,7 @@ def get_or_create_set_module( if sync_collector_flag: CollectInstance.sync_collect_strategy(db_type=db_type, force=True) Services.auto_create_bklog_service(startswith=db_type) + sync_plat_monitor_policy(db_type=db_type, force=True) logger.info("get_or_create_set_module machine_topo: {}".format(machine_topo)) return machine_topo