Skip to content

Commit

Permalink
feat(backend): 独立托管业务自动更新监控策略目标范围 TencentBlueKing#7128
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzhw8 committed Sep 25, 2024
1 parent dbf9a54 commit 0f97856
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 7 additions & 2 deletions dbm-ui/backend/db_periodic_task/local_tasks/db_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:
Expand All @@ -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"):
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions dbm-ui/backend/flow/utils/cc_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0f97856

Please sign in to comment.