fix:Eamil Send
This commit is contained in:
parent
cdd9ef1a30
commit
71a4860c63
|
@ -328,8 +328,9 @@ public class EmailServiceManager {
|
|||
props.put("mail.smtp.host", email.getEmailServerAddress());
|
||||
props.put("mail.smtp.port", email.getPort());
|
||||
props.put("mail.smtp.auth", "true");
|
||||
/*props.put("mail.smtp.socketFactory.port", email.getPort());
|
||||
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");*/
|
||||
props.put("mail.smtp.starttls.enable", "true");
|
||||
props.put("mail.smtp.socketFactory.port", email.getPort());
|
||||
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
||||
|
||||
Session session = Session.getInstance(props);
|
||||
|
||||
|
|
|
@ -3,8 +3,12 @@ package org.jeecg.modules.base.dto;
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import org.jeecg.common.util.NumUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
|
@ -17,4 +21,8 @@ public class NuclideInfo implements Serializable {
|
|||
private String datasource;
|
||||
|
||||
private String value;
|
||||
|
||||
public void keepSix(){
|
||||
this.value = NumUtil.keepStr(this.value, 6);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,14 +150,17 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
|
|||
String betaOrGamma = info.getBetaOrGamma();
|
||||
String datasource = info.getDatasource();
|
||||
List<String> conditions = ListUtil.toList(conditionStr.split(COMMA));
|
||||
List<String> first = new ArrayList<>();
|
||||
List<String> average = new ArrayList<>();
|
||||
List<String> meanwhile = new ArrayList<>();
|
||||
for (String con : conditions) {
|
||||
Condition condition = Condition.valueOf1(con);
|
||||
if (ObjectUtil.isNotNull(condition)){
|
||||
switch (condition){
|
||||
case FIRST_FOUND: // 首次发现该元素
|
||||
firstDetected = firstDetected(betaOrGamma,datasource,nuclideNames);
|
||||
firstDetected = firstDetected(betaOrGamma, datasource, nuclideNames);
|
||||
if (CollUtil.isNotEmpty(firstDetected)){
|
||||
String message = "First discovery of nuclides: [" + StrUtil.join(COMMA,firstDetected) + "]";
|
||||
String message = "First discovery of nuclides: [" + StrUtil.join(COMMA, firstDetected) + "]";
|
||||
alarmInfo.append(message);
|
||||
}
|
||||
break;
|
||||
|
@ -167,14 +170,14 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
|
|||
for (NuclideInfo nuclideInfo : moreThanAvg) {
|
||||
String nuclide = nuclideInfo.getNuclide();
|
||||
String threshold = nuclideInfo.getThreshold();
|
||||
String message = "Nuclide " + nuclide + "is above average: " + threshold;
|
||||
String message = "Nuclide " + nuclide + " is above average: " + threshold;
|
||||
alarmInfo.append(COMMA).append(message);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MEANWHILE: // 同时出现两种及以上核素
|
||||
if (nuclideNames.size() >= 2){
|
||||
String message = "Simultaneously detecting nuclides: [" + StrUtil.join(COMMA,nuclideNames) + "]";
|
||||
String message = "Simultaneously detecting nuclides: [" + StrUtil.join(COMMA, nuclideNames) + "]";
|
||||
alarmInfo.append(COMMA).append(message);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -75,6 +75,7 @@ public class AlarmAnalysisLogServiceImpl extends ServiceImpl<AlarmAnalysisLogMap
|
|||
try {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
List<NuclideInfo> nuclideInfos = mapper.readValue(nuclideInfo, new TypeReference<List<NuclideInfo>>() {});
|
||||
nuclideInfos.forEach(NuclideInfo::keepSix);
|
||||
logDto.setNuclideList(nuclideInfos);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("NuclideInfo解析异常: {}", e.getMessage());
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.jeecg.modules.feignclient;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.constant.RedisConstant;
|
||||
import org.jeecg.common.system.util.JwtUtil;
|
||||
|
@ -9,6 +10,7 @@ import org.jeecg.modules.base.dto.LoginResult;
|
|||
import org.jeecg.modules.base.dto.LoginVo;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
@Slf4j
|
||||
public class ManageUtil {
|
||||
|
||||
private static RedisUtil redisUtil;
|
||||
|
@ -31,20 +33,28 @@ public class ManageUtil {
|
|||
* 登录运管系统 获取Token
|
||||
* */
|
||||
public static String getToken(){
|
||||
if (redisUtil.hasKey(RedisConstant.MANAGE_TOKEN))
|
||||
return (String) redisUtil.get(RedisConstant.MANAGE_TOKEN);
|
||||
|
||||
LoginVo loginVo = new LoginVo(username, password);
|
||||
Result<LoginResult> loginRes = monitorSystem.login(loginVo);
|
||||
String token = loginRes.getResult().getToken();
|
||||
redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME / 1000 - 10);
|
||||
return token;
|
||||
String token = null;
|
||||
try {
|
||||
if (redisUtil.hasKey(RedisConstant.MANAGE_TOKEN))
|
||||
return (String) redisUtil.get(RedisConstant.MANAGE_TOKEN);
|
||||
LoginVo loginVo = new LoginVo(username, password);
|
||||
Result<LoginResult> loginRes = monitorSystem.login(loginVo);
|
||||
token = loginRes.getResult().getToken();
|
||||
redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME / 1000 - 10);
|
||||
return token;
|
||||
}catch (RuntimeException e){
|
||||
return token;
|
||||
}
|
||||
}
|
||||
|
||||
public static void refreshToken(){
|
||||
LoginVo loginVo = new LoginVo(username, password);
|
||||
Result<LoginResult> loginRes = monitorSystem.login(loginVo);
|
||||
String token = loginRes.getResult().getToken();
|
||||
redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME / 1000 - 10);
|
||||
try {
|
||||
LoginVo loginVo = new LoginVo(username, password);
|
||||
Result<LoginResult> loginRes = monitorSystem.login(loginVo);
|
||||
String token = loginRes.getResult().getToken();
|
||||
redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME / 1000 - 10);
|
||||
}catch (RuntimeException e){
|
||||
log.error("运管系统登录异常, Token刷新失败: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.collection.ListUtil;
|
|||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.api.dto.message.MessageDTO;
|
||||
import org.jeecg.common.constant.SymbolConstant;
|
||||
import org.jeecg.common.constant.enums.MessageTypeEnum;
|
||||
|
@ -27,6 +28,7 @@ import static org.jeecg.common.constant.enums.MessageTypeEnum.*;
|
|||
* @author nieziyan
|
||||
* @date 2023-06-21
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class SendMessage {
|
||||
|
||||
|
@ -50,6 +52,7 @@ public class SendMessage {
|
|||
*/
|
||||
public void send(MessageDTO messageDTO, String groupId, String notific){
|
||||
Map<String, String> contact = getContact(groupId);
|
||||
if (MapUtil.isEmpty(contact)) return;
|
||||
if (StrUtil.isBlank(notific)) return;
|
||||
List<String> ways = ListUtil.toList(StrUtil.split(notific, COMMA));
|
||||
if (ways.contains(ALL.getValue()))
|
||||
|
@ -96,26 +99,33 @@ public class SendMessage {
|
|||
* @param groupId
|
||||
*/
|
||||
private Map<String, String> getContact(String groupId){
|
||||
List<String> userIds = abnormalAlarmClient.userIds(groupId).getResult();
|
||||
// 查询用户信息
|
||||
List<SysUser> sysUsers = sysUserService.listByIds(userIds);
|
||||
// 用户名
|
||||
String usernameList = sysUsers.stream().map(SysUser::getUsername).filter(StrUtil::isNotBlank)
|
||||
.collect(Collectors.joining(COMMA));
|
||||
// 邮箱
|
||||
String emailList = sysUsers.stream().map(SysUser::getEmail).filter(StrUtil::isNotBlank)
|
||||
.collect(Collectors.joining(COMMA));
|
||||
// 用户名-邮箱Map
|
||||
Map<String, String> userEmail = sysUsers.stream()
|
||||
.collect(Collectors.toMap(SysUser::getUsername, SysUser::getEmail));
|
||||
// 手机号码
|
||||
String phoneList = sysUsers.stream().map(SysUser::getPhone).filter(StrUtil::isNotBlank)
|
||||
.collect(Collectors.joining(COMMA));
|
||||
Map<String,String> result = new HashMap<>();
|
||||
result.put(SYSTEM, usernameList);
|
||||
result.put(EMAIL, emailList);
|
||||
result.put(SMS, phoneList);
|
||||
result.putAll(userEmail);
|
||||
return result;
|
||||
try {
|
||||
List<String> userIds = abnormalAlarmClient.userIds(groupId).getResult();
|
||||
// 查询用户信息
|
||||
List<SysUser> sysUsers = sysUserService.listByIds(userIds);
|
||||
// 用户名
|
||||
String usernameList = sysUsers.stream().map(SysUser::getUsername).filter(StrUtil::isNotBlank)
|
||||
.collect(Collectors.joining(COMMA));
|
||||
// 邮箱
|
||||
String emailList = sysUsers.stream().map(SysUser::getEmail).filter(StrUtil::isNotBlank)
|
||||
.collect(Collectors.joining(COMMA));
|
||||
// 用户名-邮箱Map
|
||||
Map<String, String> userEmail = sysUsers.stream()
|
||||
.filter(item -> StrUtil.isNotBlank(item.getEmail()))
|
||||
.collect(Collectors.toMap(SysUser::getUsername, SysUser::getEmail));
|
||||
// 手机号码
|
||||
String phoneList = sysUsers.stream().map(SysUser::getPhone).filter(StrUtil::isNotBlank)
|
||||
.collect(Collectors.joining(COMMA));
|
||||
|
||||
result.put(SYSTEM, usernameList);
|
||||
result.put(EMAIL, emailList);
|
||||
result.put(SMS, phoneList);
|
||||
result.putAll(userEmail);
|
||||
return result;
|
||||
}catch (Exception e) {
|
||||
log.error("获取收件人联系信息异常: {}", e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|||
import cn.hutool.core.util.StrUtil;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import feign.FeignException;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.api.dto.message.MessageDTO;
|
||||
|
@ -102,6 +103,10 @@ public class DatabaseJob extends Monitor implements Job{
|
|||
}*/
|
||||
// 向运管查询监控项数据
|
||||
String token = ManageUtil.getToken();
|
||||
if(StrUtil.isBlank(token)){
|
||||
log.error("运管系统登录异常, Token获取失败");
|
||||
continue;
|
||||
}
|
||||
Result<ItemHistory> result = getMonitorSystem().itemBack(itemId, itemType, start, end, token);
|
||||
ItemHistory itemHistory = result.getResult();
|
||||
if (ObjectUtil.isNull(itemHistory)){
|
||||
|
@ -141,9 +146,12 @@ public class DatabaseJob extends Monitor implements Job{
|
|||
getSendMessage().send(messageDTO, groupId, notific);
|
||||
getPushAppUtil().pushToSingle(messageDTO, groupId);
|
||||
}
|
||||
} catch (FeignException.Unauthorized e){
|
||||
ManageUtil.refreshToken();
|
||||
log.warn("向运管系统查询ItemHistory信息异常: Token失效,已刷新Token");
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Database预警规则: {}解析失败,失败原因: {}", operator, e.getMessage());
|
||||
}catch (Exception e){
|
||||
} catch (Exception e){
|
||||
log.error("Database监控异常: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,6 +85,10 @@ public class ServerJob extends Monitor implements Job {
|
|||
|
||||
// 向运管查询监控项数据
|
||||
String token = ManageUtil.getToken();
|
||||
if(StrUtil.isBlank(token)){
|
||||
log.error("运管系统登录异常, Token获取失败");
|
||||
continue;
|
||||
}
|
||||
Result<ItemHistory> result = getMonitorSystem().itemBack(itemId, itemType, start, end, token);
|
||||
ItemHistory itemHistory = result.getResult();
|
||||
if (ObjectUtil.isNull(itemHistory)){
|
||||
|
@ -124,12 +128,12 @@ public class ServerJob extends Monitor implements Job {
|
|||
getSendMessage().send(messageDTO, groupId, notific);
|
||||
getPushAppUtil().pushToSingle(messageDTO, groupId);
|
||||
}
|
||||
}catch (FeignException.Unauthorized e){
|
||||
} catch (FeignException.Unauthorized e){
|
||||
ManageUtil.refreshToken();
|
||||
log.warn("向运管系统查询ItemHistory信息异常: Token失效,已刷新Token");
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Server预警规则: {}解析失败,失败原因: {}", operator, e.getMessage());
|
||||
}catch (Exception e){
|
||||
} catch (Exception e){
|
||||
log.error("Server监控异常: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|||
import cn.hutool.core.util.StrUtil;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import feign.FeignException;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.api.dto.message.MessageDTO;
|
||||
|
@ -86,6 +87,10 @@ public class DatabaseJob extends Monitor {
|
|||
|
||||
// 向运管查询监控项数据
|
||||
String token = ManageUtil.getToken();
|
||||
if(StrUtil.isBlank(token)){
|
||||
log.error("运管系统登录异常, Token获取失败");
|
||||
continue;
|
||||
}
|
||||
Result<ItemHistory> result = getMonitorSystem().itemBack(itemId, itemType, start, end, token);
|
||||
ItemHistory itemHistory = result.getResult();
|
||||
if (ObjectUtil.isNull(itemHistory)){
|
||||
|
@ -125,11 +130,13 @@ public class DatabaseJob extends Monitor {
|
|||
getSendMessage().send(messageDTO, groupId, notific);
|
||||
getPushAppUtil().pushToSingle(messageDTO, groupId);
|
||||
}
|
||||
}catch (FeignException.Unauthorized e){
|
||||
ManageUtil.refreshToken();
|
||||
log.warn("向运管系统查询ItemHistory信息异常: Token失效,已刷新Token");
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Database预警规则: {}解析失败,失败原因: {}", operator, e.getMessage());
|
||||
}catch (Exception e){
|
||||
log.error("Database监控异常: {}", e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
destroy();
|
||||
|
|
|
@ -111,7 +111,6 @@ public class EmailJob extends Monitor{
|
|||
log.error("Email预警规则: {}解析失败,失败原因: {}", operator, e.getMessage());
|
||||
}catch (Exception e){
|
||||
log.error("Email监控异常: {}", e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
destroy();
|
||||
|
|
|
@ -84,6 +84,10 @@ public class ServerJob extends Monitor{
|
|||
|
||||
// 向运管查询监控项数据
|
||||
String token = ManageUtil.getToken();
|
||||
if(StrUtil.isBlank(token)){
|
||||
log.error("运管系统登录异常, Token获取失败");
|
||||
continue;
|
||||
}
|
||||
Result<ItemHistory> result = getMonitorSystem().itemBack(itemId, itemType, start, end, token);
|
||||
ItemHistory itemHistory = result.getResult();
|
||||
if (ObjectUtil.isNull(itemHistory)){
|
||||
|
@ -123,14 +127,13 @@ public class ServerJob extends Monitor{
|
|||
getSendMessage().send(messageDTO, groupId, notific);
|
||||
getPushAppUtil().pushToSingle(messageDTO, groupId);
|
||||
}
|
||||
}catch (FeignException.Unauthorized e){
|
||||
} catch (FeignException.Unauthorized e){
|
||||
ManageUtil.refreshToken();
|
||||
log.warn("向运管系统查询ItemHistory信息异常: Token失效,已刷新Token");
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Server预警规则: {}解析失败,失败原因: {}", operator, e.getMessage());
|
||||
}catch (Exception e){
|
||||
} catch (Exception e){
|
||||
log.error("Server监控异常: {}", e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
destroy();
|
||||
|
|
|
@ -44,7 +44,7 @@ public class TableSpaceJob extends Monitor {
|
|||
/**
|
||||
* 解析Oracle 表空间预警规则
|
||||
**/
|
||||
@Scheduled(cron = "${task.period-space:0 0 */1 * * ?}")
|
||||
@Scheduled(cron = "${task.period-space:0 0/1 * * * ?}")
|
||||
public void execute(){
|
||||
init();
|
||||
|
||||
|
@ -124,7 +124,6 @@ public class TableSpaceJob extends Monitor {
|
|||
log.error("Database-TableSpace预警规则: {}解析失败,失败原因: {}", operator, e.getMessage());
|
||||
}catch (Exception e){
|
||||
log.error("Database-TableSpace监控异常: {}", e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
destroy();
|
||||
|
|
Loading…
Reference in New Issue
Block a user