[alter,webapp]fix 告警定义关联监控问题
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package com.usthe.alert.controller;
|
||||
|
||||
import com.usthe.common.entity.alerter.AlertDefine;
|
||||
import com.usthe.common.entity.alerter.AlertDefineBind;
|
||||
import com.usthe.common.entity.alerter.AlertDefineMonitorBind;
|
||||
import com.usthe.alert.service.AlertDefineService;
|
||||
import com.usthe.common.entity.dto.Message;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -84,16 +84,16 @@ public class AlertDefineController {
|
||||
@ApiOperation(value = "应用告警定义与监控关联", notes = "应用指定告警定义与监控关联关系")
|
||||
public ResponseEntity<Message<Void>> applyAlertDefineMonitorsBind(
|
||||
@ApiParam(value = "告警定义ID", example = "6565463543") @PathVariable("alertDefineId") long alertDefineId,
|
||||
@RequestBody List<AlertDefineBind> alertDefineBinds) {
|
||||
alertDefineService.applyBindAlertDefineMonitors(alertDefineId, alertDefineBinds);
|
||||
@RequestBody List<AlertDefineMonitorBind> alertDefineMonitorBinds) {
|
||||
alertDefineService.applyBindAlertDefineMonitors(alertDefineId, alertDefineMonitorBinds);
|
||||
return ResponseEntity.ok(new Message<>("Apply success"));
|
||||
}
|
||||
|
||||
@GetMapping(path = "/{alertDefineId}/monitors")
|
||||
@ApiOperation(value = "应用告警定义与监控关联", notes = "应用指定告警定义与监控关联关系")
|
||||
public ResponseEntity<Message<List<AlertDefineBind>>> getAlertDefineMonitorsBind(
|
||||
public ResponseEntity<Message<List<AlertDefineMonitorBind>>> getAlertDefineMonitorsBind(
|
||||
@ApiParam(value = "告警定义ID", example = "6565463543") @PathVariable("alertDefineId") long alertDefineId) {
|
||||
List<AlertDefineBind> defineBinds = alertDefineService.getBindAlertDefineMonitors(alertDefineId);
|
||||
List<AlertDefineMonitorBind> defineBinds = alertDefineService.getBindAlertDefineMonitors(alertDefineId);
|
||||
return ResponseEntity.ok(new Message<>(defineBinds));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.usthe.alert.dao;
|
||||
|
||||
import com.usthe.common.entity.alerter.AlertDefineBind;
|
||||
import com.usthe.common.entity.alerter.AlertDefineMonitorBind;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
* @author tom
|
||||
* @date 2021/12/9 10:03
|
||||
*/
|
||||
public interface AlertDefineBindDao extends JpaRepository<AlertDefineBind, Long>, JpaSpecificationExecutor<AlertDefineBind> {
|
||||
public interface AlertDefineBindDao extends JpaRepository<AlertDefineMonitorBind, Long>, JpaSpecificationExecutor<AlertDefineMonitorBind> {
|
||||
|
||||
/**
|
||||
* 根据告警定义ID删除告警定义与监控关联
|
||||
@@ -24,5 +24,5 @@ public interface AlertDefineBindDao extends JpaRepository<AlertDefineBind, Long>
|
||||
* @param alertDefineId 告警定义ID
|
||||
* @return 关联监控信息
|
||||
*/
|
||||
List<AlertDefineBind> getAlertDefineBindsByAlertDefineIdEquals(Long alertDefineId);
|
||||
List<AlertDefineMonitorBind> getAlertDefineBindsByAlertDefineIdEquals(Long alertDefineId);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public interface AlertDefineDao extends JpaRepository<AlertDefine, Long>, JpaSpe
|
||||
* @param metrics 指标组
|
||||
* @return 告警定义列表
|
||||
*/
|
||||
@Query("select define from AlertDefine define join AlertDefineBind bind on bind.alertDefineId = define.id " +
|
||||
@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")
|
||||
List<AlertDefine> queryAlertDefinesByMonitor(@Param(value = "monitorId") Long monitorId,
|
||||
@Param(value = "metrics") String metrics);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.usthe.alert.service;
|
||||
|
||||
import com.usthe.common.entity.alerter.AlertDefine;
|
||||
import com.usthe.common.entity.alerter.AlertDefineBind;
|
||||
import com.usthe.common.entity.alerter.AlertDefineMonitorBind;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
@@ -75,7 +75,7 @@ public interface AlertDefineService {
|
||||
* @param alertId 告警定义ID
|
||||
* @param alertDefineBinds 关联关系
|
||||
*/
|
||||
void applyBindAlertDefineMonitors(Long alertId, List<AlertDefineBind> alertDefineBinds);
|
||||
void applyBindAlertDefineMonitors(Long alertId, List<AlertDefineMonitorBind> alertDefineBinds);
|
||||
|
||||
/**
|
||||
* 查询与此监控ID关联的指定指标组匹配的告警定义
|
||||
@@ -99,5 +99,5 @@ public interface AlertDefineService {
|
||||
* @param alertDefineId 告警定义ID
|
||||
* @return 监控列表关联信息
|
||||
*/
|
||||
List<AlertDefineBind> getBindAlertDefineMonitors(long alertDefineId);
|
||||
List<AlertDefineMonitorBind> getBindAlertDefineMonitors(long alertDefineId);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.usthe.alert.service.impl;
|
||||
import com.usthe.alert.dao.AlertDefineBindDao;
|
||||
import com.usthe.alert.dao.AlertDefineDao;
|
||||
import com.usthe.common.entity.alerter.AlertDefine;
|
||||
import com.usthe.common.entity.alerter.AlertDefineBind;
|
||||
import com.usthe.common.entity.alerter.AlertDefineMonitorBind;
|
||||
import com.usthe.alert.service.AlertDefineService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -73,7 +73,7 @@ public class AlertDefineServiceImpl implements AlertDefineService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyBindAlertDefineMonitors(Long alertId, List<AlertDefineBind> alertDefineBinds) {
|
||||
public void applyBindAlertDefineMonitors(Long alertId, List<AlertDefineMonitorBind> alertDefineBinds) {
|
||||
// todo 校验此告警定义和监控是否存在
|
||||
|
||||
// 先删除此告警的所有关联
|
||||
@@ -99,7 +99,7 @@ public class AlertDefineServiceImpl implements AlertDefineService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AlertDefineBind> getBindAlertDefineMonitors(long alertDefineId) {
|
||||
public List<AlertDefineMonitorBind> getBindAlertDefineMonitors(long alertDefineId) {
|
||||
return alertDefineBindDao.getAlertDefineBindsByAlertDefineIdEquals(alertDefineId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user