diff --git a/alerter/src/main/java/com/usthe/alert/dao/AlertDefineDao.java b/alerter/src/main/java/com/usthe/alert/dao/AlertDefineDao.java index f515fa538d5..6e5fca4a6a6 100644 --- a/alerter/src/main/java/com/usthe/alert/dao/AlertDefineDao.java +++ b/alerter/src/main/java/com/usthe/alert/dao/AlertDefineDao.java @@ -39,14 +39,24 @@ public interface AlertDefineDao extends JpaRepository, JpaSpe */ void deleteAlertDefinesByIdIn(Set alertDefineIds); + /** + * 根据监控指标类型查询对应默认告警定义阈值 + * @param app 监控类型 + * @param metric 指标集合类型 + * @return 告警定义 + */ + List queryAlertDefinesByAppAndMetricAndPresetTrueAndEnableTrue(String app, String metric); + /** * 根据监控ID查询与之关联的告警定义列表 * @param monitorId 监控ID + * @param app 监控类型 * @param metrics 指标组 * @return 告警定义列表 */ @Query("select define from AlertDefine define join AlertDefineMonitorBind bind on bind.alertDefineId = define.id " + - "where bind.monitorId = :monitorId and define.metric = :metrics and define.enable = true") + "where bind.monitorId = :monitorId and define.app = :app and define.metric = :metrics and define.enable = true and define.preset = false") List queryAlertDefinesByMonitor(@Param(value = "monitorId") Long monitorId, + @Param(value = "app") String app, @Param(value = "metrics") String metrics); } diff --git a/alerter/src/main/java/com/usthe/alert/service/impl/AlertDefineServiceImpl.java b/alerter/src/main/java/com/usthe/alert/service/impl/AlertDefineServiceImpl.java index effd08d6837..ff9fbcc353d 100644 --- a/alerter/src/main/java/com/usthe/alert/service/impl/AlertDefineServiceImpl.java +++ b/alerter/src/main/java/com/usthe/alert/service/impl/AlertDefineServiceImpl.java @@ -101,8 +101,10 @@ public void applyBindAlertDefineMonitors(Long alertId, List> getMonitorBindAlertDefines(long monitorId, String app, String metrics) { - List defines = alertDefineDao.queryAlertDefinesByMonitor(monitorId, metrics); - if (defines == null || defines.isEmpty()) { + List defines = alertDefineDao.queryAlertDefinesByMonitor(monitorId, app, metrics); + List defaultDefines = alertDefineDao.queryAlertDefinesByAppAndMetricAndPresetTrueAndEnableTrue(app, metrics); + defines.addAll(defaultDefines); + if (defines.isEmpty()) { return null; } // 将告警阈值定义从告警级别0-3数字升序排序,数字越小告警基本越高,即从最高的告警阈值开始匹配计算