feat:增加自动处理邮箱邮件监控
This commit is contained in:
parent
99f74539d2
commit
fc978d459e
|
@ -7,12 +7,13 @@ import lombok.Getter;
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum Item {
|
public enum Item {
|
||||||
EMAIL_CONN("1", "Connection Status"),
|
EMAIL_CONN("1", "Email Connection Status"),
|
||||||
TABLESPACE_USAGE("2", "TableSpace Usage");
|
TABLESPACE_USAGE("2", "TableSpace Usage"),
|
||||||
|
EMAIL_PROCESS("3", "Email Process");
|
||||||
|
|
||||||
private String value;
|
private final String value;
|
||||||
|
|
||||||
private String name;
|
private final String name;
|
||||||
|
|
||||||
public static Item of(String value){
|
public static Item of(String value){
|
||||||
for (Item item : Item.values()) {
|
for (Item item : Item.values()) {
|
||||||
|
|
|
@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
@ -67,4 +68,10 @@ public class SysEmailLogController {
|
||||||
@RequestParam("endDate") String endDate){
|
@RequestParam("endDate") String endDate){
|
||||||
return sysEmailLogService.analysis(emailId, startDate, endDate);
|
return sysEmailLogService.analysis(emailId, startDate, endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("hoursAgo")
|
||||||
|
public Boolean hoursAgo(@RequestParam("emailId") String emailId,
|
||||||
|
@RequestParam("hoursAgo") String hoursAgo){
|
||||||
|
return sysEmailLogService.hoursAgo(emailId, hoursAgo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.modules.base.entity.postgre.SysEmailLog;
|
import org.jeecg.modules.base.entity.postgre.SysEmailLog;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface ISysEmailLogService extends IService<SysEmailLog> {
|
public interface ISysEmailLogService extends IService<SysEmailLog> {
|
||||||
|
@ -16,4 +17,6 @@ public interface ISysEmailLogService extends IService<SysEmailLog> {
|
||||||
Result<?> todayMin(String emailId);
|
Result<?> todayMin(String emailId);
|
||||||
|
|
||||||
Result<?> analysis(String emailId, String startDate, String endDate);
|
Result<?> analysis(String emailId, String startDate, String endDate);
|
||||||
|
|
||||||
|
Boolean hoursAgo(String emailId, String hoursAgo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -227,4 +227,12 @@ public class SysEmailLogServiceImpl extends ServiceImpl<SysEmailLogMapper, SysEm
|
||||||
result.put("yData",yData);
|
result.put("yData",yData);
|
||||||
return Result.OK(result);
|
return Result.OK(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean hoursAgo(String emailId, String hoursAgo) {
|
||||||
|
LambdaQueryWrapper<SysEmailLog> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(SysEmailLog::getEmailId, emailId);
|
||||||
|
wrapper.gt(SysEmailLog::getCreateTime, hoursAgo);
|
||||||
|
return CollUtil.isEmpty(this.list(wrapper));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,4 +43,9 @@ public interface AbnormalAlarmClient {
|
||||||
/* SysServerController下相关接口 */
|
/* SysServerController下相关接口 */
|
||||||
@GetMapping("/sysServer/getNameById")
|
@GetMapping("/sysServer/getNameById")
|
||||||
String getServerName(@RequestParam String id);
|
String getServerName(@RequestParam String id);
|
||||||
|
|
||||||
|
/* SysEmailLogController下相关接口 */
|
||||||
|
@GetMapping("/sysEmailLog/hoursAgo")
|
||||||
|
Boolean hoursAgo(@RequestParam String emailId,
|
||||||
|
@RequestParam String hoursAgo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ public class DatabaseJob extends Monitor {
|
||||||
String op = rule.getOperator();
|
String op = rule.getOperator();
|
||||||
Double threshold = rule.getThreshold();
|
Double threshold = rule.getThreshold();
|
||||||
boolean needWarn = NumUtil.compare(current, threshold, op);
|
boolean needWarn = NumUtil.compare(current, threshold, op);
|
||||||
if (needWarn){
|
if (!needWarn) continue;
|
||||||
// 记录报警日志
|
// 记录报警日志
|
||||||
AlarmLog alarmLog = new AlarmLog();
|
AlarmLog alarmLog = new AlarmLog();
|
||||||
alarmLog.setRuleId(ruleId);
|
alarmLog.setRuleId(ruleId);
|
||||||
|
@ -129,7 +129,6 @@ public class DatabaseJob extends Monitor {
|
||||||
String notific = alarmRule.getNotification();
|
String notific = alarmRule.getNotification();
|
||||||
getSendMessage().send(messageDTO, groupId, notific);
|
getSendMessage().send(messageDTO, groupId, notific);
|
||||||
getPushAppUtil().pushToSingle(messageDTO, groupId);
|
getPushAppUtil().pushToSingle(messageDTO, groupId);
|
||||||
}
|
|
||||||
}catch (FeignException.Unauthorized e){
|
}catch (FeignException.Unauthorized e){
|
||||||
ManageUtil.refreshToken();
|
ManageUtil.refreshToken();
|
||||||
log.warn("向运管系统查询ItemHistory信息异常: Token失效,已刷新Token");
|
log.warn("向运管系统查询ItemHistory信息异常: Token失效,已刷新Token");
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.jeecg.modules.quartz.jobs;
|
package org.jeecg.modules.quartz.jobs;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
@ -8,6 +9,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.jeecg.common.api.dto.message.MessageDTO;
|
import org.jeecg.common.api.dto.message.MessageDTO;
|
||||||
|
import org.jeecg.common.constant.DateConstant;
|
||||||
|
import org.jeecg.common.constant.FillRuleConstant;
|
||||||
import org.jeecg.common.constant.RedisConstant;
|
import org.jeecg.common.constant.RedisConstant;
|
||||||
import org.jeecg.common.util.DataTool;
|
import org.jeecg.common.util.DataTool;
|
||||||
import org.jeecg.common.util.NumUtil;
|
import org.jeecg.common.util.NumUtil;
|
||||||
|
@ -19,9 +22,12 @@ import org.jeecg.modules.base.entity.postgre.AlarmRule;
|
||||||
import org.jeecg.modules.base.enums.Item;
|
import org.jeecg.modules.base.enums.Item;
|
||||||
import org.jeecg.modules.quartz.entity.Monitor;
|
import org.jeecg.modules.quartz.entity.Monitor;
|
||||||
import org.quartz.*;
|
import org.quartz.*;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -32,6 +38,10 @@ import static org.jeecg.modules.base.enums.Template.MONITOR_EMAIL;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class EmailJob extends Monitor{
|
public class EmailJob extends Monitor{
|
||||||
|
|
||||||
|
@Value("${task.undealHours:2}")
|
||||||
|
private Integer undealHours; // 邮箱邮件未处理时长 单位: h 默认: 2h
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析Email预警规则
|
* 解析Email预警规则
|
||||||
**/
|
**/
|
||||||
|
@ -69,8 +79,11 @@ public class EmailJob extends Monitor{
|
||||||
if (ObjectUtil.isNull(item)) continue;
|
if (ObjectUtil.isNull(item)) continue;
|
||||||
Number current = null;
|
Number current = null;
|
||||||
switch (item){
|
switch (item){
|
||||||
case EMAIL_CONN: // 监控项-1: 测试邮箱服务是否可以连接成功
|
case EMAIL_CONN: // 监控项id 1: 测试邮箱服务是否可以连接成功
|
||||||
current = isConnection(sourceId);
|
current = connectionStatus(sourceId);
|
||||||
|
break;
|
||||||
|
case EMAIL_PROCESS: // 监控项id 3: 邮箱邮件是否被自动处理程序处理
|
||||||
|
current = process(sourceId);
|
||||||
break;
|
break;
|
||||||
// 追加的监控项...
|
// 追加的监控项...
|
||||||
default:
|
default:
|
||||||
|
@ -82,7 +95,7 @@ public class EmailJob extends Monitor{
|
||||||
String op = rule.getOperator();
|
String op = rule.getOperator();
|
||||||
Double threshold = rule.getThreshold();
|
Double threshold = rule.getThreshold();
|
||||||
boolean needWarn = NumUtil.compare(current, threshold, op);
|
boolean needWarn = NumUtil.compare(current, threshold, op);
|
||||||
if (needWarn){
|
if (!needWarn) continue;
|
||||||
// 记录报警日志
|
// 记录报警日志
|
||||||
AlarmLog alarmLog = new AlarmLog();
|
AlarmLog alarmLog = new AlarmLog();
|
||||||
alarmLog.setRuleId(ruleId);
|
alarmLog.setRuleId(ruleId);
|
||||||
|
@ -106,7 +119,6 @@ public class EmailJob extends Monitor{
|
||||||
String notific = alarmRule.getNotification();
|
String notific = alarmRule.getNotification();
|
||||||
getSendMessage().send(messageDTO, groupId, notific);
|
getSendMessage().send(messageDTO, groupId, notific);
|
||||||
getPushAppUtil().pushToSingle(messageDTO, groupId);
|
getPushAppUtil().pushToSingle(messageDTO, groupId);
|
||||||
}
|
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
log.error("Email预警规则: {}解析失败,失败原因: {}", operator, e.getMessage());
|
log.error("Email预警规则: {}解析失败,失败原因: {}", operator, e.getMessage());
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
|
@ -117,9 +129,9 @@ public class EmailJob extends Monitor{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 监控项-1: 测试邮箱服务是否可以连接成功 (0:失败 1:成功)
|
* 监控项id: 1 测试邮箱服务是否可以连接成功 (预警值: 0 非0值则不需要报警)
|
||||||
* */
|
* */
|
||||||
private Integer isConnection(String emailId){
|
private Integer connectionStatus(String emailId){
|
||||||
int res = 1;
|
int res = 1;
|
||||||
String statusKey = RedisConstant.EMAIL_STATUS;
|
String statusKey = RedisConstant.EMAIL_STATUS;
|
||||||
NameValue nameValue = (NameValue)getRedisUtil().hget(statusKey, emailId);
|
NameValue nameValue = (NameValue)getRedisUtil().hget(statusKey, emailId);
|
||||||
|
@ -127,4 +139,18 @@ public class EmailJob extends Monitor{
|
||||||
res = 0;
|
res = 0;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 监控项id: 3 邮箱邮件在一定时间内是否被处理 (预警值: 0 非0值则不需要报警)
|
||||||
|
* */
|
||||||
|
private Integer process(String emailId){
|
||||||
|
int res = 1;
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateConstant.DATE_TIME);
|
||||||
|
LocalDateTime minusHours = LocalDateTime.now().minusHours(undealHours);
|
||||||
|
String hoursAgo = minusHours.format(formatter);
|
||||||
|
Boolean result = getAlarmClient().hoursAgo(emailId, hoursAgo);
|
||||||
|
if (ObjectUtil.isNotNull(result) && result)
|
||||||
|
res = 0;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,7 @@ public class ServerJob extends Monitor{
|
||||||
String op = rule.getOperator();
|
String op = rule.getOperator();
|
||||||
Double threshold = rule.getThreshold();
|
Double threshold = rule.getThreshold();
|
||||||
boolean needWarn = NumUtil.compare(current, threshold, op);
|
boolean needWarn = NumUtil.compare(current, threshold, op);
|
||||||
if (needWarn){
|
if (!needWarn) continue;
|
||||||
// 记录报警日志
|
// 记录报警日志
|
||||||
AlarmLog alarmLog = new AlarmLog();
|
AlarmLog alarmLog = new AlarmLog();
|
||||||
alarmLog.setRuleId(ruleId);
|
alarmLog.setRuleId(ruleId);
|
||||||
|
@ -126,7 +126,6 @@ public class ServerJob extends Monitor{
|
||||||
String notific = alarmRule.getNotification();
|
String notific = alarmRule.getNotification();
|
||||||
getSendMessage().send(messageDTO, groupId, notific);
|
getSendMessage().send(messageDTO, groupId, notific);
|
||||||
getPushAppUtil().pushToSingle(messageDTO, groupId);
|
getPushAppUtil().pushToSingle(messageDTO, groupId);
|
||||||
}
|
|
||||||
} catch (FeignException.Unauthorized e){
|
} catch (FeignException.Unauthorized e){
|
||||||
ManageUtil.refreshToken();
|
ManageUtil.refreshToken();
|
||||||
log.warn("向运管系统查询ItemHistory信息异常: Token失效,已刷新Token");
|
log.warn("向运管系统查询ItemHistory信息异常: Token失效,已刷新Token");
|
||||||
|
|
|
@ -95,7 +95,7 @@ public class TableSpaceJob extends Monitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果当前值超过阈值 则需要发送报警信息
|
// 如果当前值超过阈值 则需要发送报警信息
|
||||||
if (needWarn){
|
if (!needWarn) continue;
|
||||||
// 记录报警日志
|
// 记录报警日志
|
||||||
AlarmLog alarmLog = new AlarmLog();
|
AlarmLog alarmLog = new AlarmLog();
|
||||||
alarmLog.setRuleId(ruleId);
|
alarmLog.setRuleId(ruleId);
|
||||||
|
@ -119,7 +119,6 @@ public class TableSpaceJob extends Monitor {
|
||||||
String notific = alarmRule.getNotification();
|
String notific = alarmRule.getNotification();
|
||||||
getSendMessage().send(messageDTO, groupId, notific);
|
getSendMessage().send(messageDTO, groupId, notific);
|
||||||
getPushAppUtil().pushToSingle(messageDTO, groupId);
|
getPushAppUtil().pushToSingle(messageDTO, groupId);
|
||||||
}
|
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
log.error("Database-TableSpace预警规则: {}解析失败,失败原因: {}", operator, e.getMessage());
|
log.error("Database-TableSpace预警规则: {}解析失败,失败原因: {}", operator, e.getMessage());
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
|
|
Loading…
Reference in New Issue
Block a user