修改告警规则是否启用功能

This commit is contained in:
duwenyuan 2026-05-14 16:38:20 +08:00
parent 3500a691a4
commit 0ea4f730ed
2 changed files with 9 additions and 6 deletions

View File

@ -389,6 +389,8 @@ public class PrometheusAlertManager {
// 6. 重载 Prometheus
reloadPrometheus();
// 删除备份文件
deleteFile(fullPath+ ".backup");
log.info("告警规则 [{}] 已成功同步至 Prometheus", alarmRule.getName());
return true;
}
@ -671,11 +673,6 @@ public class PrometheusAlertManager {
// 删除规则文件
deleteFile(rulePath);
// 验证配置
if (!validatePrometheusConfig()) {
throw new Exception("删除告警规则后配置验证失败");
}
// 重新加载Prometheus
reloadPrometheus();

View File

@ -127,7 +127,7 @@ public class AlarmRuleServiceImpl extends ServiceImpl<AlarmRuleMapper, AlarmRule
prometheusAlertManager.saveOrUpdateAlarmRule(alarmRule);
} catch (Exception e) {
log.error("规则同步到 Prometheus 错误:"+e.getMessage());
return Result.error(Prompt.ADD_ERR);
return Result.error(Prompt.UPDATE_ERR);
}
return Result.OK(Prompt.UPDATE_SUCC);
}
@ -263,10 +263,16 @@ public class AlarmRuleServiceImpl extends ServiceImpl<AlarmRuleMapper, AlarmRule
switch (enabledE){
case ENABLED:
redisUtil.set(ruleKey, alarmRule);
try {
prometheusAlertManager.saveOrUpdateAlarmRule(alarmRule);
} catch (Exception e) {
log.error("将新增的规则同步到 Prometheus 错误:"+e.getMessage());
}
break;
case DISENABLED:
if (redisUtil.hasKey(ruleKey))
redisUtil.del(ruleKey);
prometheusAlertManager.deleteAlertRule(alarmRule.getId() + ".yml");
break;
default:
break;