feat:自动处理邮箱邮件监控报警逻辑
This commit is contained in:
parent
ebf8958f60
commit
035e842240
|
@ -9,7 +9,7 @@ import lombok.Getter;
|
||||||
public enum Item {
|
public enum Item {
|
||||||
EMAIL_CONN("1", "Email Connection Status"),
|
EMAIL_CONN("1", "Email Connection Status"),
|
||||||
TABLESPACE_USAGE("2", "TableSpace Usage"),
|
TABLESPACE_USAGE("2", "TableSpace Usage"),
|
||||||
EMAIL_PROCESS("3", "Email Process");
|
EMAIL_UNPROCESSED("3", "Email Unprocessed");
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
|
|
|
@ -69,9 +69,8 @@ public class SysEmailLogController {
|
||||||
return sysEmailLogService.analysis(emailId, startDate, endDate);
|
return sysEmailLogService.analysis(emailId, startDate, endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("hoursAgo")
|
@GetMapping("getMinus")
|
||||||
public Boolean hoursAgo(@RequestParam("emailId") String emailId,
|
public Integer getMinus(@RequestParam("emailId") String emailId){
|
||||||
@RequestParam("hoursAgo") String hoursAgo){
|
return sysEmailLogService.getMinus(emailId);
|
||||||
return sysEmailLogService.hoursAgo(emailId, hoursAgo);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,5 +18,5 @@ public interface ISysEmailLogService extends IService<SysEmailLog> {
|
||||||
|
|
||||||
Result<?> analysis(String emailId, String startDate, String endDate);
|
Result<?> analysis(String emailId, String startDate, String endDate);
|
||||||
|
|
||||||
Boolean hoursAgo(String emailId, String hoursAgo);
|
Integer getMinus(String emailId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package org.jeecg.modules.service.impl;
|
package org.jeecg.modules.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
|
import cn.hutool.core.date.DateUnit;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
@ -229,10 +232,18 @@ public class SysEmailLogServiceImpl extends ServiceImpl<SysEmailLogMapper, SysEm
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean hoursAgo(String emailId, String hoursAgo) {
|
public Integer getMinus(String emailId) {
|
||||||
LambdaQueryWrapper<SysEmailLog> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysEmailLog> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(SysEmailLog::getEmailId, emailId);
|
wrapper.eq(SysEmailLog::getEmailId, emailId);
|
||||||
wrapper.gt(SysEmailLog::getCreateTime, hoursAgo);
|
wrapper.orderByDesc(SysEmailLog::getCreateTime);
|
||||||
return CollUtil.isEmpty(this.list(wrapper));
|
wrapper.last("limit 1");
|
||||||
|
SysEmailLog emailLog = getOne(wrapper, false);
|
||||||
|
if (ObjectUtil.isNull(emailLog))
|
||||||
|
return -1;
|
||||||
|
Date createTime = emailLog.getCreateTime();
|
||||||
|
if (ObjectUtil.isNull(createTime))
|
||||||
|
return -1;
|
||||||
|
// 获取最新一条数据和当前时间所间隔的分钟数
|
||||||
|
return Math.toIntExact(DateUtil.between(createTime, new Date(), DateUnit.MINUTE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,6 @@ public interface AbnormalAlarmClient {
|
||||||
String getServerName(@RequestParam String id);
|
String getServerName(@RequestParam String id);
|
||||||
|
|
||||||
/* SysEmailLogController下相关接口 */
|
/* SysEmailLogController下相关接口 */
|
||||||
@GetMapping("/sysEmailLog/hoursAgo")
|
@GetMapping("/sysEmailLog/getMinus")
|
||||||
Boolean hoursAgo(@RequestParam String emailId,
|
Integer getMinus(@RequestParam String emailId);
|
||||||
@RequestParam String hoursAgo);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
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;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
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;
|
||||||
|
@ -21,16 +17,11 @@ import org.jeecg.modules.base.entity.postgre.AlarmLog;
|
||||||
import org.jeecg.modules.base.entity.postgre.AlarmRule;
|
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.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 static org.jeecg.modules.base.enums.SourceType.EMAIL;
|
import static org.jeecg.modules.base.enums.SourceType.EMAIL;
|
||||||
import static org.jeecg.modules.base.enums.Template.MONITOR_EMAIL;
|
import static org.jeecg.modules.base.enums.Template.MONITOR_EMAIL;
|
||||||
|
@ -39,9 +30,6 @@ import static org.jeecg.modules.base.enums.Template.MONITOR_EMAIL;
|
||||||
@Component
|
@Component
|
||||||
public class EmailJob extends Monitor{
|
public class EmailJob extends Monitor{
|
||||||
|
|
||||||
@Value("${task.undealHours:2}")
|
|
||||||
private Integer undealHours; // 邮箱邮件未处理时长 单位: h 默认: 2h
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析Email预警规则
|
* 解析Email预警规则
|
||||||
**/
|
**/
|
||||||
|
@ -82,8 +70,8 @@ public class EmailJob extends Monitor{
|
||||||
case EMAIL_CONN: // 监控项id 1: 测试邮箱服务是否可以连接成功
|
case EMAIL_CONN: // 监控项id 1: 测试邮箱服务是否可以连接成功
|
||||||
current = connectionStatus(sourceId);
|
current = connectionStatus(sourceId);
|
||||||
break;
|
break;
|
||||||
case EMAIL_PROCESS: // 监控项id 3: 邮箱邮件是否被自动处理程序处理
|
case EMAIL_UNPROCESSED: // 监控项id 3: 邮箱邮件是否被自动处理程序处理
|
||||||
current = process(sourceId);
|
current = unProcess(sourceId);
|
||||||
break;
|
break;
|
||||||
// 追加的监控项...
|
// 追加的监控项...
|
||||||
default:
|
default:
|
||||||
|
@ -141,18 +129,9 @@ public class EmailJob extends Monitor{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 监控项id: 3 邮箱邮件在一定时间内是否被处理 (预警值: 0 非0值则不需要报警)
|
* 监控项id: 3 邮箱邮件在一定时间内是否被自动处理程序处理
|
||||||
* */
|
* */
|
||||||
private Integer process(String emailId){
|
private Integer unProcess(String emailId){
|
||||||
int res = 1;
|
return getAlarmClient().getMinus(emailId);
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateConstant.DATE_TIME);
|
|
||||||
LocalDateTime minusHours = LocalDateTime.now().minusHours(undealHours);
|
|
||||||
LocalDateTime minusMinutes = LocalDateTime.now().minusMinutes(undealHours);
|
|
||||||
String hoursAgo = minusHours.format(formatter);
|
|
||||||
String minutesAgo = minusMinutes.format(formatter);
|
|
||||||
Boolean result = getAlarmClient().hoursAgo(emailId, minutesAgo);
|
|
||||||
if (ObjectUtil.isNotNull(result) && result)
|
|
||||||
res = 0;
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user