[monitor]feature: Alarm and receiving Chinese and English support (#82)
* fix: 代码名称优化 #huacheng * fix: msgtype更正名称 #huacheng * fix: 企业微信更正名称 #huacheng * feat: Alarm and receiving Chinese and English support #huacheng Co-authored-by: tomsun28 <tomsun28@outlook.com>
This commit is contained in:
@@ -30,6 +30,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Alarm information storage and distribution
|
||||
* 告警信息入库分发
|
||||
*
|
||||
* @author tom
|
||||
@@ -71,7 +72,7 @@ public class DispatchAlarm {
|
||||
try {
|
||||
Alert alert = dataQueue.pollAlertData();
|
||||
if (alert != null) {
|
||||
// 判断告警类型入库
|
||||
// Determining alarm type storage 判断告警类型入库
|
||||
storeAlertData(alert);
|
||||
// 通知分发
|
||||
sendAlertDataListener(alert);
|
||||
@@ -87,7 +88,7 @@ public class DispatchAlarm {
|
||||
}
|
||||
|
||||
private void storeAlertData(Alert alert) {
|
||||
// todo 使用缓存不直接操作库
|
||||
// todo Using the cache does not directly manipulate the library 使用缓存不直接操作库
|
||||
Monitor monitor = monitorService.getMonitor(alert.getMonitorId());
|
||||
if (monitor == null) {
|
||||
log.warn("Dispatch alarm the monitorId: {} not existed, ignored.", alert.getMonitorId());
|
||||
@@ -95,34 +96,38 @@ public class DispatchAlarm {
|
||||
}
|
||||
alert.setMonitorName(monitor.getName());
|
||||
if (monitor.getStatus() == CommonConstants.UN_MANAGE_CODE) {
|
||||
// When monitoring is not managed, ignore and silence its alarm messages
|
||||
// 当监控未管理时 忽略静默其告警信息
|
||||
return;
|
||||
}
|
||||
if (monitor.getStatus() == CommonConstants.AVAILABLE_CODE) {
|
||||
if (CommonConstants.AVAILABLE.equals(alert.getTarget())) {
|
||||
// Availability Alarm Need to change the monitoring status to unavailable
|
||||
// 可用性告警 需变更监控状态为不可用
|
||||
monitorService.updateMonitorStatus(monitor.getId(), CommonConstants.UN_AVAILABLE_CODE);
|
||||
} else if (CommonConstants.REACHABLE.equals(alert.getTarget())) {
|
||||
// Reachability alarm The monitoring status needs to be changed to unreachable
|
||||
// 可达性告警 需变更监控状态为不可达
|
||||
monitorService.updateMonitorStatus(monitor.getId(), CommonConstants.UN_REACHABLE_CODE);
|
||||
}
|
||||
} else {
|
||||
// If the alarm is restored, the monitoring state needs to be restored
|
||||
// 若是恢复告警 需对监控状态进行恢复
|
||||
if (alert.getStatus() == CommonConstants.ALERT_STATUS_CODE_RESTORED) {
|
||||
monitorService.updateMonitorStatus(alert.getMonitorId(), CommonConstants.AVAILABLE_CODE);
|
||||
}
|
||||
}
|
||||
// 告警落库
|
||||
// Alarm drop library 告警落库
|
||||
alertService.addAlert(alert);
|
||||
}
|
||||
|
||||
private void sendAlertDataListener(Alert alert) {
|
||||
// todo 转发配置的邮件 微信 webhook
|
||||
// todo Forward configured email WeChat webhook 转发配置的邮件 微信 webhook
|
||||
List<NoticeReceiver> receivers = matchReceiverByNoticeRules(alert);
|
||||
// todo 发送通知这里暂时单线程
|
||||
// todo Send notification here temporarily single thread 发送通知这里暂时单线程
|
||||
for (NoticeReceiver receiver : receivers) {
|
||||
switch (receiver.getType()) {
|
||||
// todo 短信通知
|
||||
// todo SMS notification 短信通知
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
@@ -150,10 +155,11 @@ public class DispatchAlarm {
|
||||
}
|
||||
|
||||
/**
|
||||
* Send alert information through FeiShu
|
||||
* 通过飞书发送告警信息
|
||||
*
|
||||
* @param receiver 接收人
|
||||
* @param alert 告警信息
|
||||
* @param receiver Notification configuration information 通知配置信息
|
||||
* @param alert Alarm information 告警信息
|
||||
*/
|
||||
private void sendFlyBookAlert(NoticeReceiver receiver, Alert alert) {
|
||||
FlyBookWebHookDto flyBookWebHookDto = new FlyBookWebHookDto();
|
||||
@@ -199,10 +205,11 @@ public class DispatchAlarm {
|
||||
}
|
||||
|
||||
/**
|
||||
* Send alarm information through DingTalk robot
|
||||
* 通过钉钉机器人发送告警信息
|
||||
*
|
||||
* @param receiver 通知配置信息
|
||||
* @param alert 告警信息
|
||||
* @param receiver Notification configuration information 通知配置信息
|
||||
* @param alert Alarm information 告警信息
|
||||
*/
|
||||
private void sendDingTalkRobotAlert(NoticeReceiver receiver, Alert alert) {
|
||||
DingTalkWebHookDto dingTalkWebHookDto = new DingTalkWebHookDto();
|
||||
@@ -233,10 +240,11 @@ public class DispatchAlarm {
|
||||
}
|
||||
|
||||
/**
|
||||
* Send alarm information through enterprise WeChat
|
||||
* 通过企业微信发送告警信息
|
||||
*
|
||||
* @param receiver 通知配置信息
|
||||
* @param alert 告警信息
|
||||
* @param receiver Notification configuration information 通知配置信息
|
||||
* @param alert Alarm information 告警信息
|
||||
*/
|
||||
private void sendWeWorkRobotAlert(NoticeReceiver receiver, Alert alert) {
|
||||
WeWorkWebHookDto weWorkWebHookDTO = new WeWorkWebHookDto();
|
||||
@@ -296,23 +304,23 @@ public class DispatchAlarm {
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
|
||||
messageHelper.setSubject("TanCloud探云-监控告警");
|
||||
//设置发件人Email
|
||||
//Set sender Email 设置发件人Email
|
||||
messageHelper.setFrom(emailFromUser);
|
||||
//设定收件人Email
|
||||
//Set recipient Email 设定收件人Email
|
||||
messageHelper.setTo(receiver.getEmail());
|
||||
messageHelper.setSentDate(new Date());
|
||||
//构建邮件模版
|
||||
//Build email templates 构建邮件模版
|
||||
String process = mailService.buildAlertHtmlTemplate(alert);
|
||||
//设置邮件内容模版
|
||||
//Set Email Content Template 设置邮件内容模版
|
||||
messageHelper.setText(process, true);
|
||||
javaMailSender.send(mimeMessage);
|
||||
} catch (Exception e) {
|
||||
log.error("[邮箱告警] error,Exception information={}", e.getMessage());
|
||||
log.error("[Email Alert] Exception,Exception information={}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private List<NoticeReceiver> matchReceiverByNoticeRules(Alert alert) {
|
||||
// todo 使用缓存
|
||||
// todo use cache 使用缓存
|
||||
return noticeConfigService.getReceiverFilterRule(alert);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,11 +28,13 @@ import java.util.List;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
|
||||
/**
|
||||
* Message Notification Configuration API
|
||||
* 消息通知配置API
|
||||
*
|
||||
* @author tom
|
||||
* @date 2021/12/16 16:18
|
||||
*/
|
||||
@Api(tags = "消息通知配置API")
|
||||
@Api(tags = "en: Message Notification Configuration API,zh: 消息通知配置API")
|
||||
@RestController()
|
||||
@RequestMapping(value = "/notice", produces = {APPLICATION_JSON_VALUE})
|
||||
public class NoticeConfigController {
|
||||
@@ -41,33 +43,36 @@ public class NoticeConfigController {
|
||||
private NoticeConfigService noticeConfigService;
|
||||
|
||||
@PostMapping(path = "/receiver")
|
||||
@ApiOperation(value = "新增接收人", notes = "新增一个接收人")
|
||||
@ApiOperation(value = "Add a recipient", notes = "新增一个接收人")
|
||||
public ResponseEntity<Message<Void>> addNewNoticeReceiver(@Valid @RequestBody NoticeReceiver noticeReceiver) {
|
||||
noticeConfigService.addReceiver(noticeReceiver);
|
||||
return ResponseEntity.ok(new Message<>("Add success"));
|
||||
}
|
||||
|
||||
@PutMapping(path = "/receiver")
|
||||
@ApiOperation(value = "修改接收人", notes = "修改已存在的接收人信息")
|
||||
@ApiOperation(value = "Modify existing recipient information", notes = "修改已存在的接收人信息")
|
||||
public ResponseEntity<Message<Void>> editNoticeReceiver(@Valid @RequestBody NoticeReceiver noticeReceiver) {
|
||||
noticeConfigService.editReceiver(noticeReceiver);
|
||||
return ResponseEntity.ok(new Message<>("Edit success"));
|
||||
}
|
||||
|
||||
@DeleteMapping(path = "/receiver/{id}")
|
||||
@ApiOperation(value = "删除指定接收人", notes = "删除已存在的接收人信息")
|
||||
@ApiOperation(value = "Delete existing recipient information", notes = "删除已存在的接收人信息")
|
||||
public ResponseEntity<Message<Void>> deleteNoticeReceiver(
|
||||
@ApiParam(value = "接收人ID", example = "6565463543") @PathVariable("id") final Long receiverId) {
|
||||
// 不存在或删除成功都返回成功
|
||||
@ApiParam(value = "en: Recipient ID,zh: 接收人ID", example = "6565463543") @PathVariable("id") final Long receiverId) {
|
||||
// Returns success if it does not exist or if the deletion is successful
|
||||
// todo 不存在或删除成功都返回成功
|
||||
noticeConfigService.deleteReceiver(receiverId);
|
||||
return ResponseEntity.ok(new Message<>("Delete success"));
|
||||
}
|
||||
|
||||
@GetMapping(path = "/receivers")
|
||||
@ApiOperation(value = "查询消息通知接收人", notes = "根据查询过滤项获取消息通知接收人列表")
|
||||
@ApiOperation(value = "Get a list of message notification recipients based on query filter items",
|
||||
notes = "根据查询过滤项获取消息通知接收人列表")
|
||||
public ResponseEntity<Message<List<NoticeReceiver>>> getReceivers(
|
||||
@ApiParam(value = "接收人名称,模糊查询", example = "tom") @RequestParam(required = false) final String name) {
|
||||
@ApiParam(value = "en: Recipient name,zh: 接收人名称,模糊查询", example = "tom") @RequestParam(required = false) final String name) {
|
||||
|
||||
//todo Writing can be optimized 写法可优化
|
||||
Specification<NoticeReceiver> specification = (root, query, criteriaBuilder) -> {
|
||||
Predicate predicate = criteriaBuilder.conjunction();
|
||||
if (name != null && !"".equals(name)) {
|
||||
@@ -83,32 +88,34 @@ public class NoticeConfigController {
|
||||
|
||||
|
||||
@PostMapping(path = "/rule")
|
||||
@ApiOperation(value = "新增通知策略", notes = "新增一个通知策略")
|
||||
@ApiOperation(value = "Add a notification policy", notes = "新增一个通知策略")
|
||||
public ResponseEntity<Message<Void>> addNewNoticeRule(@Valid @RequestBody NoticeRule noticeRule) {
|
||||
noticeConfigService.addNoticeRule(noticeRule);
|
||||
return ResponseEntity.ok(new Message<>("Add success"));
|
||||
}
|
||||
|
||||
@PutMapping(path = "/rule")
|
||||
@ApiOperation(value = "修改通知策略", notes = "修改已存在的通知策略信息")
|
||||
@ApiOperation(value = "Modify existing notification policy information", notes = "修改已存在的通知策略信息")
|
||||
public ResponseEntity<Message<Void>> editNoticeRule(@Valid @RequestBody NoticeRule noticeRule) {
|
||||
noticeConfigService.editNoticeRule(noticeRule);
|
||||
return ResponseEntity.ok(new Message<>("Edit success"));
|
||||
}
|
||||
|
||||
@DeleteMapping(path = "/rule/{id}")
|
||||
@ApiOperation(value = "删除指定通知策略", notes = "删除已存在的通知策略信息")
|
||||
@ApiOperation(value = "Delete existing notification policy information", notes = "删除已存在的通知策略信息")
|
||||
public ResponseEntity<Message<Void>> deleteNoticeRule(
|
||||
@ApiParam(value = "通知策略ID", example = "6565463543") @PathVariable("id") final Long ruleId) {
|
||||
// 不存在或删除成功都返回成功
|
||||
@ApiParam(value = "en: Notification Policy ID,zh: 通知策略ID", example = "6565463543") @PathVariable("id") final Long ruleId) {
|
||||
// Returns success if it does not exist or if the deletion is successful
|
||||
// todo 不存在或删除成功都返回成功
|
||||
noticeConfigService.deleteNoticeRule(ruleId);
|
||||
return ResponseEntity.ok(new Message<>("Delete success"));
|
||||
}
|
||||
|
||||
@GetMapping(path = "/rules")
|
||||
@ApiOperation(value = "查询消息通知策略", notes = "根据查询过滤项获取消息通知策略列表")
|
||||
@ApiOperation(value = "Get a list of message notification policies based on query filter items",
|
||||
notes = "根据查询过滤项获取消息通知策略列表")
|
||||
public ResponseEntity<Message<List<NoticeRule>>> getRules(
|
||||
@ApiParam(value = "接收人名称,模糊查询", example = "rule1") @RequestParam(required = false) final String name) {
|
||||
@ApiParam(value = "en: Recipient name,zh: 接收人名称,模糊查询", example = "rule1") @RequestParam(required = false) final String name) {
|
||||
|
||||
Specification<NoticeRule> specification = (root, query, criteriaBuilder) -> {
|
||||
Predicate predicate = criteriaBuilder.conjunction();
|
||||
|
||||
@@ -18,11 +18,13 @@ import java.util.List;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
|
||||
/**
|
||||
* System Summary Statistics API
|
||||
* 系统摘要统计API
|
||||
*
|
||||
* @author tom
|
||||
* @date 2021/12/7 15:57
|
||||
*/
|
||||
@Api(tags = "系统摘要统计API")
|
||||
@Api(tags = "en: System Summary Statistics API,zh: 系统摘要统计API")
|
||||
@RestController
|
||||
@RequestMapping(path = "/summary", produces = {APPLICATION_JSON_VALUE})
|
||||
public class SummaryController {
|
||||
@@ -31,7 +33,7 @@ public class SummaryController {
|
||||
private MonitorService monitorService;
|
||||
|
||||
@GetMapping
|
||||
@ApiOperation(value = "查询应用类别监控统计", notes = "查询所有应用类别监控统计信息")
|
||||
@ApiOperation(value = "Query all application category monitoring statistics", notes = "查询所有应用类别监控统计信息")
|
||||
public ResponseEntity<Message<Dashboard>> appMonitors() {
|
||||
List<AppCount> appsCount = monitorService.getAllAppMonitorsCount();
|
||||
Message<Dashboard> message = new Message<>(new Dashboard(appsCount));
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.Set;
|
||||
|
||||
/**
|
||||
* AuthResources 数据库操作
|
||||
*
|
||||
* @author tomsun28
|
||||
* @date 2021/11/14 11:24
|
||||
*/
|
||||
@@ -22,12 +23,14 @@ public interface MonitorDao extends JpaRepository<Monitor, Long>, JpaSpecificati
|
||||
|
||||
/**
|
||||
* 根据监控ID列表删除监控
|
||||
*
|
||||
* @param monitorIds 监控ID列表
|
||||
*/
|
||||
void deleteAllByIdIn(Set<Long> monitorIds);
|
||||
|
||||
/**
|
||||
* 根据监控ID列表查询监控
|
||||
*
|
||||
* @param monitorIds 监控ID列表
|
||||
* @return 监控列表
|
||||
*/
|
||||
@@ -35,6 +38,7 @@ public interface MonitorDao extends JpaRepository<Monitor, Long>, JpaSpecificati
|
||||
|
||||
/**
|
||||
* 根据监控类型查询监控
|
||||
*
|
||||
* @param app 监控类型
|
||||
* @return 监控列表
|
||||
*/
|
||||
@@ -42,29 +46,35 @@ public interface MonitorDao extends JpaRepository<Monitor, Long>, JpaSpecificati
|
||||
|
||||
/**
|
||||
* 查询已下发采集任务的监控
|
||||
*
|
||||
* @param status 监控状态
|
||||
* @return 监控列表
|
||||
*/
|
||||
List<Monitor> findMonitorsByStatusNotInAndAndJobIdNotNull(List<Byte> status);
|
||||
|
||||
/**
|
||||
* 根据监控名称查询监控
|
||||
* @param name 监控名称
|
||||
* @return 监控列表
|
||||
* Query monitoring by monitoring name 根据监控名称查询监控
|
||||
*
|
||||
* @param name monitoring name 监控名称
|
||||
* @return monitoring list 监控列表
|
||||
*/
|
||||
Optional<Monitor> findMonitorByNameEquals(String name);
|
||||
|
||||
/**
|
||||
* Query the monitoring category - the number of monitoring corresponding to the status
|
||||
* 查询监控类别-状态对应的监控数量
|
||||
* @return 监控类别-状态与监控数量映射
|
||||
*
|
||||
* @return Monitoring Category-Status and Monitoring Quantity Mapping 监控类别-状态与监控数量映射
|
||||
*/
|
||||
@Query("select new com.usthe.manager.pojo.dto.AppCount(mo.app, mo.status, COUNT(mo.id)) from Monitor mo group by mo.app, mo.status")
|
||||
List<AppCount> findAppsStatusCount();
|
||||
|
||||
/**
|
||||
* Update the status of the specified monitor
|
||||
* 更新指定监控的状态
|
||||
* @param id 监控ID
|
||||
* @param status 监控状态
|
||||
*
|
||||
* @param id Monitor ID 监控ID
|
||||
* @param status 监控状态 Monitor Status
|
||||
*/
|
||||
@Modifying
|
||||
@Query("update Monitor set status = :status where id = :id")
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 邮箱发送服务
|
||||
* Email delivery service 邮箱发送服务
|
||||
*
|
||||
* @author 花城
|
||||
* @version 1.0
|
||||
@@ -15,9 +15,11 @@ import org.springframework.stereotype.Service;
|
||||
public interface MailService {
|
||||
|
||||
/**
|
||||
* Build an alert email template
|
||||
* 构建告警邮件模版
|
||||
* @param alert 告警信息
|
||||
* @return 邮件内容
|
||||
*
|
||||
* @param alert Alarm data element information 告警数据元信息
|
||||
* @return content of email 邮件内容
|
||||
*/
|
||||
String buildAlertHtmlTemplate(Alert alert);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.Set;
|
||||
|
||||
/**
|
||||
* 监控管理服务
|
||||
*
|
||||
* @author tomsun28
|
||||
* @date 2021/11/14 11:28
|
||||
*/
|
||||
@@ -23,38 +24,43 @@ public interface MonitorService {
|
||||
|
||||
/**
|
||||
* 监控可用性探测
|
||||
*
|
||||
* @param monitor 监控实体信息
|
||||
* @param params 参数信息
|
||||
* @param params 参数信息
|
||||
* @throws MonitorDetectException 探测失败抛出
|
||||
*/
|
||||
void detectMonitor(Monitor monitor, List<Param> params) throws MonitorDetectException;
|
||||
|
||||
/**
|
||||
* 新增监控
|
||||
*
|
||||
* @param monitor 监控实体
|
||||
* @param params 参数信息
|
||||
* @param params 参数信息
|
||||
* @throws RuntimeException 新增过程异常抛出
|
||||
*/
|
||||
void addMonitor(Monitor monitor, List<Param> params) throws RuntimeException;
|
||||
|
||||
/**
|
||||
* 校验请求数据参数正确性
|
||||
*
|
||||
* @param monitorDto monitorDto
|
||||
* @param isModify 是否是修改监控
|
||||
* @param isModify 是否是修改监控
|
||||
* @throws IllegalArgumentException 校验参数错误抛出
|
||||
*/
|
||||
void validate(MonitorDto monitorDto, Boolean isModify) throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* 修改更新监控
|
||||
*
|
||||
* @param monitor 监控实体
|
||||
* @param params 参数信息
|
||||
* @param params 参数信息
|
||||
* @throws RuntimeException 修改过程中异常抛出
|
||||
*/
|
||||
void modifyMonitor(Monitor monitor, List<Param> params) throws RuntimeException;
|
||||
|
||||
/**
|
||||
* 删除监控
|
||||
*
|
||||
* @param id 监控ID
|
||||
* @throws RuntimeException 删除过程中异常抛出
|
||||
*/
|
||||
@@ -62,6 +68,7 @@ public interface MonitorService {
|
||||
|
||||
/**
|
||||
* 批量删除监控
|
||||
*
|
||||
* @param ids 监控ID
|
||||
* @throws RuntimeException 删除过程中异常抛出
|
||||
*/
|
||||
@@ -69,6 +76,7 @@ public interface MonitorService {
|
||||
|
||||
/**
|
||||
* 获取监控信息
|
||||
*
|
||||
* @param id 监控ID
|
||||
* @return MonitorDto
|
||||
* @throws RuntimeException 查询过程中异常抛出
|
||||
@@ -77,46 +85,55 @@ public interface MonitorService {
|
||||
|
||||
/**
|
||||
* 动态条件查询
|
||||
*
|
||||
* @param specification 查询条件
|
||||
* @param pageRequest 分页参数
|
||||
* @param pageRequest 分页参数
|
||||
* @return 查询结果
|
||||
*/
|
||||
Page<Monitor> getMonitors(Specification<Monitor> specification, PageRequest pageRequest);
|
||||
|
||||
/**
|
||||
* 根据监控ID列表批量取消纳管监控项
|
||||
*
|
||||
* @param ids 监控IDs
|
||||
*/
|
||||
void cancelManageMonitors(HashSet<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据监控ID列表批量启动纳管监控项
|
||||
*
|
||||
* @param ids 监控IDs
|
||||
*/
|
||||
void enableManageMonitors(HashSet<Long> ids);
|
||||
|
||||
/**
|
||||
* 查询监控类别及其对应的监控数量
|
||||
*
|
||||
* @return 监控类别与监控数量映射
|
||||
*/
|
||||
List<AppCount> getAllAppMonitorsCount();
|
||||
|
||||
/**
|
||||
* Query monitoring
|
||||
* 查询监控
|
||||
* @param monitorId 监控ID
|
||||
* @return 监控信息
|
||||
*
|
||||
* @param monitorId Monitor ID 监控ID
|
||||
* @return Monitor information 监控信息
|
||||
*/
|
||||
Monitor getMonitor(Long monitorId);
|
||||
|
||||
/**
|
||||
* Update the status of the specified monitor
|
||||
* 更新指定监控的状态
|
||||
* @param monitorId 监控ID
|
||||
* @param status 监控状态
|
||||
*
|
||||
* @param monitorId monitorId 监控ID
|
||||
* @param status monitor status 监控状态
|
||||
*/
|
||||
void updateMonitorStatus(Long monitorId, byte status);
|
||||
|
||||
/**
|
||||
* 查询指定监控类型下的所有监控信息列表
|
||||
*
|
||||
* @param app 监控类型
|
||||
* @return 监控列表
|
||||
*/
|
||||
|
||||
@@ -8,66 +8,86 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Message notification configuration interface
|
||||
* 消息通知配置接口
|
||||
*
|
||||
* @author tom
|
||||
* @date 2021/12/16 16:14
|
||||
*/
|
||||
public interface NoticeConfigService {
|
||||
|
||||
/**
|
||||
* Dynamic conditional query
|
||||
* 动态条件查询
|
||||
* @param specification 查询条件
|
||||
* @return 查询结果
|
||||
*
|
||||
* @param specification Query conditions 查询条件
|
||||
* @return Search result 查询结果
|
||||
*/
|
||||
List<NoticeReceiver> getNoticeReceivers(Specification<NoticeReceiver> specification);
|
||||
|
||||
/**
|
||||
* Dynamic conditional query
|
||||
* 动态条件查询
|
||||
* @param specification 查询条件
|
||||
* @return 查询结果
|
||||
*
|
||||
* @param specification Query conditions 查询条件
|
||||
* @return Search result 查询结果
|
||||
*/
|
||||
List<NoticeRule> getNoticeRules(Specification<NoticeRule> specification);
|
||||
|
||||
/**
|
||||
* Add a notification recipient
|
||||
* 新增一个通知接收人
|
||||
* @param noticeReceiver 接收人信息
|
||||
*
|
||||
* @param noticeReceiver recipient information 接收人信息
|
||||
*/
|
||||
void addReceiver(NoticeReceiver noticeReceiver);
|
||||
|
||||
/**
|
||||
* Modify notification recipients
|
||||
* 修改通知接收人
|
||||
* @param noticeReceiver 接收人信息
|
||||
*
|
||||
* @param noticeReceiver recipient information 接收人信息
|
||||
*/
|
||||
void editReceiver(NoticeReceiver noticeReceiver);
|
||||
|
||||
/**
|
||||
* Delete recipient information based on recipient ID
|
||||
* 根据接收人ID删除接收人信息
|
||||
* @param receiverId 接收人ID
|
||||
*
|
||||
* @param receiverId Recipient ID 接收人ID
|
||||
*/
|
||||
void deleteReceiver(Long receiverId);
|
||||
|
||||
/**
|
||||
* Added notification policy
|
||||
* 新增通知策略
|
||||
* @param noticeRule 通知策略
|
||||
*
|
||||
* @param noticeRule Notification strategy 通知策略
|
||||
*/
|
||||
void addNoticeRule(NoticeRule noticeRule);
|
||||
|
||||
/**
|
||||
* Modify Notification Policy
|
||||
* 修改通知策略
|
||||
* @param noticeRule 通知策略
|
||||
*
|
||||
* @param noticeRule Notification strategy 通知策略
|
||||
*/
|
||||
void editNoticeRule(NoticeRule noticeRule);
|
||||
|
||||
/**
|
||||
* Delete the specified notification policy
|
||||
* 删除指定的通知策略
|
||||
* @param ruleId 通知策略ID
|
||||
*
|
||||
* @param ruleId Notification Policy ID 通知策略ID
|
||||
*/
|
||||
void deleteNoticeRule(Long ruleId);
|
||||
|
||||
/**
|
||||
* According to the alarm information matching all notification policies, filter out the recipients who need to be notified
|
||||
* 根据告警信息与所有通知策略匹配,过滤出需要通知的接收人
|
||||
* @param alert 告警信息
|
||||
* @return 接收人
|
||||
*
|
||||
* @param alert Alarm information 告警信息
|
||||
* @return Receiver 接收人
|
||||
*/
|
||||
List<NoticeReceiver> getReceiverFilterRule(Alert alert);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.usthe.manager.service.AppService;
|
||||
import com.usthe.manager.service.MonitorService;
|
||||
import com.usthe.manager.support.exception.MonitorDatabaseException;
|
||||
import com.usthe.manager.support.exception.MonitorDetectException;
|
||||
import jdk.nashorn.internal.runtime.regexp.joni.constants.Traverse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -40,6 +41,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 监控管理服务实现
|
||||
*
|
||||
* @author tomsun28
|
||||
* @date 2021/11/14 13:06
|
||||
*/
|
||||
@@ -391,7 +393,8 @@ public class MonitorServiceImpl implements MonitorService {
|
||||
if (appCounts == null) {
|
||||
return null;
|
||||
}
|
||||
// 关联大类别信息 计算每个状态对应数量
|
||||
//Statistical category information, calculate the number of corresponding states for each monitor
|
||||
//统计类别信息,计算每个监控分别对应状态的数量
|
||||
Map<String, AppCount> appCountMap = new HashMap<>(appCounts.size());
|
||||
for (AppCount item : appCounts) {
|
||||
AppCount appCount = appCountMap.getOrDefault(item.getApp(), new AppCount());
|
||||
@@ -409,10 +412,13 @@ public class MonitorServiceImpl implements MonitorService {
|
||||
case CommonConstants.UN_REACHABLE_CODE:
|
||||
appCount.setUnReachableSize(appCount.getUnReachableSize() + item.getSize());
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
appCountMap.put(item.getApp(), appCount);
|
||||
}
|
||||
//Traverse the map obtained by statistics and convert it into a List<App Count> result set
|
||||
//遍历统计得到的map,转换成List<App Count>结果集
|
||||
return appCountMap.values().stream().peek(item -> {
|
||||
item.setSize(item.getAvailableSize() + item.getUnManageSize()
|
||||
+ item.getUnReachableSize() + item.getUnAvailableSize());
|
||||
|
||||
Reference in New Issue
Block a user