[alerter,manage] 告警相关接口调整

This commit is contained in:
tomsun28
2021-12-13 01:16:56 +08:00
parent 441df8f3c2
commit fac7713bf2
8 changed files with 69 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
package com.usthe.alert.service;
import com.usthe.alert.pojo.entity.AlertDefine;
import com.usthe.alert.pojo.entity.AlertDefineBind;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
@@ -72,9 +73,9 @@ public interface AlertDefineService {
/**
* 应用告警定于与监控关联关系
* @param alertId 告警定义ID
* @param monitorMap 监控ID-名称 MAP
* @param alertDefineBinds 关联关系
*/
void applyBindAlertDefineMonitors(Long alertId, Map<Long, String> monitorMap);
void applyBindAlertDefineMonitors(Long alertId, List<AlertDefineBind> alertDefineBinds);
/**
* 查询与此监控ID关联的指定指标组匹配的告警定义
@@ -92,4 +93,11 @@ public interface AlertDefineService {
* @return 查询结果
*/
Page<AlertDefine> getAlertDefines(Specification<AlertDefine> specification, PageRequest pageRequest);
/**
* 根据告警定义ID查询其关联的监控列表关联信息
* @param alertDefineId 告警定义ID
* @return 监控列表关联信息
*/
List<AlertDefineBind> getBindAlertDefineMonitors(long alertDefineId);
}

View File

@@ -73,16 +73,12 @@ public class AlertDefineServiceImpl implements AlertDefineService {
}
@Override
public void applyBindAlertDefineMonitors(Long alertId, Map<Long, String> monitorMap) {
public void applyBindAlertDefineMonitors(Long alertId, List<AlertDefineBind> alertDefineBinds) {
// todo 校验此告警定义和监控是否存在
// 先删除此告警的所有关联
alertDefineBindDao.deleteAlertDefineBindsByAlertDefineIdEquals(alertId);
// 保存关联
List<AlertDefineBind> alertDefineBinds = monitorMap.entrySet().stream().map(entry ->
AlertDefineBind.builder().alertDefineId(alertId).monitorId(entry.getKey())
.monitorName(entry.getValue()).build())
.collect(Collectors.toList());
alertDefineBindDao.saveAll(alertDefineBinds);
}
@@ -101,4 +97,9 @@ public class AlertDefineServiceImpl implements AlertDefineService {
public Page<AlertDefine> getAlertDefines(Specification<AlertDefine> specification, PageRequest pageRequest) {
return alertDefineDao.findAll(specification, pageRequest);
}
@Override
public List<AlertDefineBind> getBindAlertDefineMonitors(long alertDefineId) {
return alertDefineBindDao.getAlertDefineBindsByAlertDefineIdEquals(alertDefineId);
}
}