整理下初始化数据表

This commit is contained in:
dengqichen 2025-12-08 16:09:28 +08:00
parent 1a4d4edfca
commit e298dcf83c

View File

@ -61,19 +61,43 @@ public class ServerAlertServiceImpl implements IServerAlertService {
return;
}
// 过滤并检查适用于该服务器的规则
// 按照告警类型分组规则实现专属规则覆盖全局规则
Map<MonitorMetricEnum, ServerAlertRule> effectiveRules = new HashMap<>();
for (ServerAlertRule rule : allRules) {
// 过滤只检查全局规则或匹配的服务器规则
// 跳过其他服务器的专属规则
if (rule.getServerId() != null && !rule.getServerId().equals(serverId)) {
continue;
}
// 只检查启用的规则
// 跳过禁用的规则
if (!Boolean.TRUE.equals(rule.getEnabled())) {
continue;
}
// 根据告警类型检查
MonitorMetricEnum alertType = rule.getAlertType();
ServerAlertRule existingRule = effectiveRules.get(alertType);
if (existingRule == null) {
// 该类型还没有规则直接使用
effectiveRules.put(alertType, rule);
} else {
// 该类型已有规则专属规则优先覆盖全局规则
boolean isExistingGlobal = existingRule.getServerId() == null;
boolean isCurrentSpecific = rule.getServerId() != null;
if (isCurrentSpecific && isExistingGlobal) {
// 当前是专属规则已有是全局规则 用专属规则覆盖
effectiveRules.put(alertType, rule);
log.debug("服务器专属规则覆盖全局规则: serverId={}, alertType={}, ruleId={}",
serverId, alertType, rule.getId());
}
// 否则保持原有规则专属优先或者先到先得
}
}
// 使用筛选后的有效规则进行检查
for (ServerAlertRule rule : effectiveRules.values()) {
checkSingleRule(serverId, monitorData, rule, config);
}
}