[alerter,manage] 告警相关接口调整
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.usthe.alert.controller;
|
package com.usthe.alert.controller;
|
||||||
|
|
||||||
import com.usthe.alert.pojo.entity.AlertDefine;
|
import com.usthe.alert.pojo.entity.AlertDefine;
|
||||||
|
import com.usthe.alert.pojo.entity.AlertDefineBind;
|
||||||
import com.usthe.alert.service.AlertDefineService;
|
import com.usthe.alert.service.AlertDefineService;
|
||||||
import com.usthe.common.entity.dto.Message;
|
import com.usthe.common.entity.dto.Message;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@@ -19,6 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static com.usthe.common.util.CommonConstants.MONITOR_NOT_EXIST_CODE;
|
import static com.usthe.common.util.CommonConstants.MONITOR_NOT_EXIST_CODE;
|
||||||
@@ -79,13 +81,21 @@ public class AlertDefineController {
|
|||||||
return ResponseEntity.ok(new Message<>("Delete success"));
|
return ResponseEntity.ok(new Message<>("Delete success"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(path = "/{alertId}/monitors")
|
@PostMapping(path = "/{alertDefineId}/monitors")
|
||||||
@ApiOperation(value = "应用告警定义与监控关联", notes = "应用指定告警定义与监控关联关系")
|
@ApiOperation(value = "应用告警定义与监控关联", notes = "应用指定告警定义与监控关联关系")
|
||||||
public ResponseEntity<Message<Void>> applyAlertDefineMonitorsBind(
|
public ResponseEntity<Message<Void>> applyAlertDefineMonitorsBind(
|
||||||
@ApiParam(value = "告警定义ID", example = "6565463543") @PathVariable("alertId") long alertId,
|
@ApiParam(value = "告警定义ID", example = "6565463543") @PathVariable("alertDefineId") long alertDefineId,
|
||||||
@RequestBody Map<Long, String> monitorMap) {
|
@RequestBody List<AlertDefineBind> alertDefineBinds) {
|
||||||
alertDefineService.applyBindAlertDefineMonitors(alertId, monitorMap);
|
alertDefineService.applyBindAlertDefineMonitors(alertDefineId, alertDefineBinds);
|
||||||
return ResponseEntity.ok(new Message<>("Apply success"));
|
return ResponseEntity.ok(new Message<>("Apply success"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping(path = "/{alertDefineId}/monitors")
|
||||||
|
@ApiOperation(value = "应用告警定义与监控关联", notes = "应用指定告警定义与监控关联关系")
|
||||||
|
public ResponseEntity<Message<List<AlertDefineBind>>> getAlertDefineMonitorsBind(
|
||||||
|
@ApiParam(value = "告警定义ID", example = "6565463543") @PathVariable("alertDefineId") long alertDefineId) {
|
||||||
|
List<AlertDefineBind> defineBinds = alertDefineService.getBindAlertDefineMonitors(alertDefineId);
|
||||||
|
return ResponseEntity.ok(new Message<>(defineBinds));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import com.usthe.alert.pojo.entity.AlertDefineBind;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AlertDefineBind 数据库操作
|
* AlertDefineBind 数据库操作
|
||||||
* @author tom
|
* @author tom
|
||||||
@@ -16,4 +18,11 @@ public interface AlertDefineBindDao extends JpaRepository<AlertDefineBind, Long>
|
|||||||
* @param alertDefineId 告警定义ID
|
* @param alertDefineId 告警定义ID
|
||||||
*/
|
*/
|
||||||
void deleteAlertDefineBindsByAlertDefineIdEquals(Long alertDefineId);
|
void deleteAlertDefineBindsByAlertDefineIdEquals(Long alertDefineId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据告警定义ID查询监控关联信息
|
||||||
|
* @param alertDefineId 告警定义ID
|
||||||
|
* @return 关联监控信息
|
||||||
|
*/
|
||||||
|
List<AlertDefineBind> getAlertDefineBindsByAlertDefineIdEquals(Long alertDefineId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.usthe.alert.service;
|
package com.usthe.alert.service;
|
||||||
|
|
||||||
import com.usthe.alert.pojo.entity.AlertDefine;
|
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.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
@@ -72,9 +73,9 @@ public interface AlertDefineService {
|
|||||||
/**
|
/**
|
||||||
* 应用告警定于与监控关联关系
|
* 应用告警定于与监控关联关系
|
||||||
* @param alertId 告警定义ID
|
* @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关联的指定指标组匹配的告警定义
|
* 查询与此监控ID关联的指定指标组匹配的告警定义
|
||||||
@@ -92,4 +93,11 @@ public interface AlertDefineService {
|
|||||||
* @return 查询结果
|
* @return 查询结果
|
||||||
*/
|
*/
|
||||||
Page<AlertDefine> getAlertDefines(Specification<AlertDefine> specification, PageRequest pageRequest);
|
Page<AlertDefine> getAlertDefines(Specification<AlertDefine> specification, PageRequest pageRequest);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据告警定义ID查询其关联的监控列表关联信息
|
||||||
|
* @param alertDefineId 告警定义ID
|
||||||
|
* @return 监控列表关联信息
|
||||||
|
*/
|
||||||
|
List<AlertDefineBind> getBindAlertDefineMonitors(long alertDefineId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,16 +73,12 @@ public class AlertDefineServiceImpl implements AlertDefineService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyBindAlertDefineMonitors(Long alertId, Map<Long, String> monitorMap) {
|
public void applyBindAlertDefineMonitors(Long alertId, List<AlertDefineBind> alertDefineBinds) {
|
||||||
// todo 校验此告警定义和监控是否存在
|
// todo 校验此告警定义和监控是否存在
|
||||||
|
|
||||||
// 先删除此告警的所有关联
|
// 先删除此告警的所有关联
|
||||||
alertDefineBindDao.deleteAlertDefineBindsByAlertDefineIdEquals(alertId);
|
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);
|
alertDefineBindDao.saveAll(alertDefineBinds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,4 +97,9 @@ public class AlertDefineServiceImpl implements AlertDefineService {
|
|||||||
public Page<AlertDefine> getAlertDefines(Specification<AlertDefine> specification, PageRequest pageRequest) {
|
public Page<AlertDefine> getAlertDefines(Specification<AlertDefine> specification, PageRequest pageRequest) {
|
||||||
return alertDefineDao.findAll(specification, pageRequest);
|
return alertDefineDao.findAll(specification, pageRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AlertDefineBind> getBindAlertDefineMonitors(long alertDefineId) {
|
||||||
|
return alertDefineBindDao.getAlertDefineBindsByAlertDefineIdEquals(alertDefineId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import org.springframework.data.jpa.domain.Specification;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
@@ -82,6 +83,15 @@ public class MonitorsController {
|
|||||||
return ResponseEntity.ok(message);
|
return ResponseEntity.ok(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping(path = "/{app}")
|
||||||
|
@ApiOperation(value = "查询指定监控类型的监控列表", notes = "根据查询过滤指定监控类型的所有获取监控信息列表")
|
||||||
|
public ResponseEntity<Message<List<Monitor>>> getAppMonitors(
|
||||||
|
@ApiParam(value = "监控类型", example = "linux") @PathVariable(required = false) String app) {
|
||||||
|
List<Monitor> monitors = monitorService.getAppMonitors(app);
|
||||||
|
Message<List<Monitor>> message = new Message<>(monitors);
|
||||||
|
return ResponseEntity.ok(message);
|
||||||
|
}
|
||||||
|
|
||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
@ApiOperation(value = "批量删除监控", notes = "根据监控ID列表批量删除监控项")
|
@ApiOperation(value = "批量删除监控", notes = "根据监控ID列表批量删除监控项")
|
||||||
public ResponseEntity<Message<Void>> deleteMonitors(
|
public ResponseEntity<Message<Void>> deleteMonitors(
|
||||||
|
|||||||
@@ -25,12 +25,19 @@ public interface MonitorDao extends JpaRepository<Monitor, Long>, JpaSpecificati
|
|||||||
void deleteAllByIdIn(Set<Long> monitorIds);
|
void deleteAllByIdIn(Set<Long> monitorIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据监控ID列表查询监控
|
* 根据监控ID列表查询监控
|
||||||
* @param monitorIds 监控ID列表
|
* @param monitorIds 监控ID列表
|
||||||
* @return 监控列表
|
* @return 监控列表
|
||||||
*/
|
*/
|
||||||
List<Monitor> findMonitorsByIdIn(Set<Long> monitorIds);
|
List<Monitor> findMonitorsByIdIn(Set<Long> monitorIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据监控类型查询监控
|
||||||
|
* @param app 监控类型
|
||||||
|
* @return 监控列表
|
||||||
|
*/
|
||||||
|
List<Monitor> findMonitorsByAppEquals(String app);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询监控类别及其对应的监控数量
|
* 查询监控类别及其对应的监控数量
|
||||||
* @return 监控类别与监控数量映射
|
* @return 监控类别与监控数量映射
|
||||||
|
|||||||
@@ -114,4 +114,11 @@ public interface MonitorService {
|
|||||||
* @param status 监控状态
|
* @param status 监控状态
|
||||||
*/
|
*/
|
||||||
void updateMonitorStatus(Long monitorId, byte status);
|
void updateMonitorStatus(Long monitorId, byte status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询指定监控类型下的所有监控信息列表
|
||||||
|
* @param app 监控类型
|
||||||
|
* @return 监控列表
|
||||||
|
*/
|
||||||
|
List<Monitor> getAppMonitors(String app);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -345,4 +345,9 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
public void updateMonitorStatus(Long monitorId, byte status) {
|
public void updateMonitorStatus(Long monitorId, byte status) {
|
||||||
monitorDao.updateMonitorStatus(monitorId, status);
|
monitorDao.updateMonitorStatus(monitorId, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Monitor> getAppMonitors(String app) {
|
||||||
|
return monitorDao.findMonitorsByAppEquals(app);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user