From 817eb5a6792fc87404d5b5a1868ce9be625cf772 Mon Sep 17 00:00:00 2001 From: nieziyan Date: Tue, 19 Dec 2023 20:05:07 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat=EF=BC=9AIDC=20Data=E6=8B=BE=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/api/dto/message/MessageDTO.java | 8 ++ .../java/org/jeecg/common/util/JDBCUtil.java | 24 ++++++ .../org/jeecg/modules/base/dto/ConnR.java | 13 +++ .../jeecg/modules/aspect/StatusAspect.java | 1 + .../modules/feignclient/SystemClient.java | 5 ++ .../org/jeecg/modules/idc/IDCDataFetch.java | 82 +++++++++++++++++++ .../controller/SendMessageController.java | 14 +++- .../system/controller/LoginController.java | 4 +- .../src/main/resources/application.yml | 1 + 9 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/ConnR.java create mode 100644 jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/idc/IDCDataFetch.java diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/dto/message/MessageDTO.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/dto/message/MessageDTO.java index 0c69a6bd..9196817e 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/dto/message/MessageDTO.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/dto/message/MessageDTO.java @@ -1,6 +1,7 @@ package org.jeecg.common.api.dto.message; import lombok.Data; +import lombok.experimental.Accessors; import org.jeecg.common.constant.CommonConstant; import java.io.Serializable; @@ -11,6 +12,7 @@ import java.util.Map; * @author: jeecg-boot */ @Data +@Accessors(chain = true) public class MessageDTO implements Serializable { private static final long serialVersionUID = -5690444483968058442L; @@ -113,6 +115,12 @@ public class MessageDTO implements Serializable { this.content = content; } + public MessageDTO(String title, String content, String toUser) { + this.title = title; + this.content = content; + this.toUser = toUser; + } + public boolean isMarkdown() { return this.isMarkdown; } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/JDBCUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/JDBCUtil.java index 50673541..62881a5e 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/JDBCUtil.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/JDBCUtil.java @@ -2,6 +2,7 @@ package org.jeecg.common.util; import cn.hutool.core.util.ObjectUtil; import lombok.extern.slf4j.Slf4j; +import org.jeecg.modules.base.dto.ConnR; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DriverManagerDataSource; @@ -27,6 +28,14 @@ public class JDBCUtil { return null; } + public static JdbcTemplate template(String url, String user, String pass){ + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setUrl(url); + dataSource.setUsername(user); + dataSource.setPassword(pass); + return new JdbcTemplate(dataSource); + } + public static boolean isConnection(String url, String driver, String user, String pass){ DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setUrl(url); @@ -42,6 +51,21 @@ public class JDBCUtil { } } + public static ConnR isConnection(String url, String user, String pass){ + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setUrl(url); + dataSource.setUsername(user); + dataSource.setPassword(pass); + // try-with-resources 无须显式关闭Connection资源 + try (Connection connection = dataSource.getConnection()) { + return new ConnR().setConn(true); + } catch (SQLException e) { + String message = String.format("IDC数据源["+ url +"]连接失败: %s", e.getMessage()); + log.error(message); + return new ConnR().setInfo(message); + } + } + public static boolean isConnection(DriverManagerDataSource dataSource){ // try-with-resources 无须显式关闭Connection资源 try (Connection connection = dataSource.getConnection()) { diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/ConnR.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/ConnR.java new file mode 100644 index 00000000..b65b8b91 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/ConnR.java @@ -0,0 +1,13 @@ +package org.jeecg.modules.base.dto; + +import lombok.Data; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true) +public class ConnR { + + private boolean isConn; + + private String info; +} diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/aspect/StatusAspect.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/aspect/StatusAspect.java index 33cecb60..136e96c8 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/aspect/StatusAspect.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/aspect/StatusAspect.java @@ -31,6 +31,7 @@ import org.jeecg.modules.qiyeEmail.service.Account; import org.jeecg.modules.service.ISysEmailService; import org.jeecg.modules.service.ISysServerService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/SystemClient.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/SystemClient.java index b0343df8..bd88b422 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/SystemClient.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/SystemClient.java @@ -1,11 +1,13 @@ package org.jeecg.modules.feignclient; +import org.jeecg.common.api.dto.message.MessageDTO; import org.jeecg.common.api.vo.Result; import org.jeecg.common.system.vo.DictModel; import org.jeecg.modules.base.entity.postgre.SysUser; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -26,6 +28,9 @@ public interface SystemClient { @RequestParam String groupId, @RequestParam String notific); + @GetMapping("/sys/sendMessage/sendTo") + void sendTo(@RequestBody MessageDTO messageDTO); + /* SysDictController下相关接口 */ @GetMapping("/sys/dict/getItems") List getItems(@RequestParam String dictCode); diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/idc/IDCDataFetch.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/idc/IDCDataFetch.java new file mode 100644 index 00000000..7aaddee3 --- /dev/null +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/idc/IDCDataFetch.java @@ -0,0 +1,82 @@ +package org.jeecg.modules.idc; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.jeecg.common.api.dto.message.MessageDTO; +import org.jeecg.common.constant.enums.MessageTypeEnum; +import org.jeecg.common.util.JDBCUtil; +import org.jeecg.modules.base.dto.ConnR; +import org.jeecg.modules.feignclient.SystemClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.sql.Connection; +import java.sql.SQLException; +import java.util.concurrent.TimeUnit; + +@Component +@Slf4j +public class IDCDataFetch { + + @Value("inland.url") + private String urlM; // 本地数据源url,即为主数据源 + + @Value("inland.username") + private String usernameM; + + @Value("inland.password") + private String passwordM; + + @Value("oversea.url") + private String urlS; // 国外数据源url,即为从数据源 + + @Value("oversea.username") + private String usernameS; + + @Value("oversea.password") + private String passwordS; + + @Autowired + private SystemClient systemClient; + + // 定时拾取IDC数据 + @Scheduled(fixedDelayString = "${request-interval}", timeUnit = TimeUnit.SECONDS) + private void fetch() { + ConnR connR; + JdbcTemplate template; + MessageDTO messageDTO = new MessageDTO("IDC数据源异常", null, "admin"); + messageDTO.setType(MessageTypeEnum.XT.getType()); + connR = JDBCUtil.isConnection(urlM, usernameM, passwordM); + if (connR.isConn()) { + try { + template = JDBCUtil.template(urlM, usernameM, passwordM); + // 查询IDC Data + System.out.println("[inland数据源]IDC数据查询"); + } catch (Exception e) { + log.error("[inland数据源]IDC数据查询异常: {}", e.getMessage()); + } + return; + } + // 给管理员发送预警信息 + messageDTO.setContent(connR.getInfo()); + systemClient.sendTo(messageDTO); + // 使用备用数据源 + connR = JDBCUtil.isConnection(urlS, usernameS, passwordS); + if (connR.isConn()) { + try { + template = JDBCUtil.template(urlS, usernameS, passwordS); + // 查询IDC Data + System.out.println("[oversea数据源]IDC数据查询"); + } catch (Exception e) { + log.error("[oversea数据源]IDC数据查询异常: {}", e.getMessage()); + } + return; + } + // 给管理员发送预警信息 + messageDTO.setContent(connR.getInfo()); + systemClient.sendTo(messageDTO); + } +} diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/controller/SendMessageController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/controller/SendMessageController.java index b4decbe8..44edcb11 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/controller/SendMessageController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/controller/SendMessageController.java @@ -1,11 +1,10 @@ package org.jeecg.modules.message.controller; +import org.jeecg.common.api.dto.message.MessageDTO; +import org.jeecg.common.system.api.ISysBaseAPI; import org.jeecg.modules.message.SendMessage; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("sys/sendMessage") @@ -14,6 +13,9 @@ public class SendMessageController { @Autowired private SendMessage sendMessage; + @Autowired + private ISysBaseAPI sysBaseAPI; + @GetMapping("send") public void sendMessage(@RequestParam String title, @RequestParam String message, @@ -22,4 +24,8 @@ public class SendMessageController { sendMessage.send(title, message, groupId, notific); } + @GetMapping("sendTo") + public void sendTo(@RequestBody MessageDTO messageDTO){ + sysBaseAPI.sendTemplateMessage(messageDTO); + } } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/LoginController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/LoginController.java index 445b362b..1f9af1d2 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/LoginController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/LoginController.java @@ -88,7 +88,7 @@ public class LoginController { //update-begin-author:taoyan date:20190828 for:校验验证码 - String captcha = sysLoginModel.getCaptcha(); + /*String captcha = sysLoginModel.getCaptcha(); if(captcha==null){ result.error500("验证码无效"); return result; @@ -107,7 +107,7 @@ public class LoginController { // 改成特殊的code 便于前端判断 result.setCode(HttpStatus.PRECONDITION_FAILED.value()); return result; - } + }*/ //update-end-author:taoyan date:20190828 for:校验验证码 //1. 校验用户是否有效 diff --git a/jeecg-server-cloud/armd-abnormal-alarm-start/src/main/resources/application.yml b/jeecg-server-cloud/armd-abnormal-alarm-start/src/main/resources/application.yml index 6605266d..4beb3b36 100644 --- a/jeecg-server-cloud/armd-abnormal-alarm-start/src/main/resources/application.yml +++ b/jeecg-server-cloud/armd-abnormal-alarm-start/src/main/resources/application.yml @@ -15,4 +15,5 @@ spring: config: import: - optional:nacos:armd.yaml + - optional:nacos:IDC-Data.yaml - optional:nacos:armd-@profile.name@.yaml \ No newline at end of file From 977447bd07d796601ed4159ef57be7b65934cd93 Mon Sep 17 00:00:00 2001 From: nieziyan Date: Wed, 20 Dec 2023 11:07:13 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat=EF=BC=9AIDC=20Data=E6=8B=BE=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/jeecg/common/util/JDBCUtil.java | 7 ++- .../modules/feignclient/SystemClient.java | 7 +-- .../org/jeecg/modules/idc/IDCDataFetch.java | 54 ++++++++++++------- .../controller/SendMessageController.java | 2 +- 4 files changed, 41 insertions(+), 29 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/JDBCUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/JDBCUtil.java index 62881a5e..6bf9d222 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/JDBCUtil.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/JDBCUtil.java @@ -46,7 +46,7 @@ public class JDBCUtil { try (Connection connection = dataSource.getConnection()) { return true; } catch (SQLException e) { - log.error("JDBCUtil.isConnection():数据源["+ url +"]连接失败: {}", e.getMessage()); + log.error("数据源["+ url +"]连接失败: {}", e.getMessage()); return false; } } @@ -60,8 +60,7 @@ public class JDBCUtil { try (Connection connection = dataSource.getConnection()) { return new ConnR().setConn(true); } catch (SQLException e) { - String message = String.format("IDC数据源["+ url +"]连接失败: %s", e.getMessage()); - log.error(message); + String message = String.format("[xxx数据源]连接失败: %s", e.getMessage()); return new ConnR().setInfo(message); } } @@ -73,7 +72,7 @@ public class JDBCUtil { } catch (SQLException e) { String url = "--"; if (ObjectUtil.isNotNull(dataSource)) url = dataSource.getUrl(); - log.error("JDBCUtil.isConnection():数据源["+ url +"]连接失败: {}", e.getMessage()); + log.error("数据源["+ url +"]连接失败: {}", e.getMessage()); return false; } } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/SystemClient.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/SystemClient.java index bd88b422..bce40eb1 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/SystemClient.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/feignclient/SystemClient.java @@ -6,10 +6,7 @@ import org.jeecg.common.system.vo.DictModel; import org.jeecg.modules.base.entity.postgre.SysUser; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.stereotype.Component; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.*; import java.util.Collection; import java.util.List; @@ -28,7 +25,7 @@ public interface SystemClient { @RequestParam String groupId, @RequestParam String notific); - @GetMapping("/sys/sendMessage/sendTo") + @PostMapping("/sys/sendMessage/sendTo") void sendTo(@RequestBody MessageDTO messageDTO); /* SysDictController下相关接口 */ diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/idc/IDCDataFetch.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/idc/IDCDataFetch.java index 7aaddee3..ef5eaccb 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/idc/IDCDataFetch.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/idc/IDCDataFetch.java @@ -1,8 +1,10 @@ package org.jeecg.modules.idc; +import cn.hutool.core.util.StrUtil; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.api.dto.message.MessageDTO; +import org.jeecg.common.config.mqtoken.UserTokenContext; import org.jeecg.common.constant.enums.MessageTypeEnum; import org.jeecg.common.util.JDBCUtil; import org.jeecg.modules.base.dto.ConnR; @@ -17,26 +19,28 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.concurrent.TimeUnit; +import static org.jeecg.common.util.TokenUtils.getTempToken; + @Component @Slf4j public class IDCDataFetch { - @Value("inland.url") + @Value("${inland.url}") private String urlM; // 本地数据源url,即为主数据源 - @Value("inland.username") + @Value("${inland.username}") private String usernameM; - @Value("inland.password") + @Value("${inland.password}") private String passwordM; - @Value("oversea.url") + @Value("${oversea.url}") private String urlS; // 国外数据源url,即为从数据源 - @Value("oversea.username") + @Value("${oversea.username}") private String usernameS; - @Value("oversea.password") + @Value("${oversea.password}") private String passwordS; @Autowired @@ -44,39 +48,51 @@ public class IDCDataFetch { // 定时拾取IDC数据 @Scheduled(fixedDelayString = "${request-interval}", timeUnit = TimeUnit.SECONDS) - private void fetch() { - ConnR connR; + public void fetch() { JdbcTemplate template; MessageDTO messageDTO = new MessageDTO("IDC数据源异常", null, "admin"); messageDTO.setType(MessageTypeEnum.XT.getType()); - connR = JDBCUtil.isConnection(urlM, usernameM, passwordM); + ConnR connR = JDBCUtil.isConnection(urlM, usernameM, passwordM); if (connR.isConn()) { try { template = JDBCUtil.template(urlM, usernameM, passwordM); // 查询IDC Data - System.out.println("[inland数据源]IDC数据查询"); + } catch (Exception e) { - log.error("[inland数据源]IDC数据查询异常: {}", e.getMessage()); + log.error("[inland数据源]IDC数据处理异常: {}", e.getMessage()); } return; } - // 给管理员发送预警信息 - messageDTO.setContent(connR.getInfo()); - systemClient.sendTo(messageDTO); + UserTokenContext.setToken(getTempToken()); + // 对发送警告消息时可能出现的异常进行捕获(503) 防止影响后续代码执行 + try { + // 给管理员发送预警信息 + String message = StrUtil.replace(connR.getInfo(), "xxx", "inland"); + messageDTO.setContent(message); + systemClient.sendTo(messageDTO); + }catch (Exception e){ + log.error("发送inland数据源异常信息失败: {}", e.getMessage()); + } // 使用备用数据源 connR = JDBCUtil.isConnection(urlS, usernameS, passwordS); if (connR.isConn()) { try { template = JDBCUtil.template(urlS, usernameS, passwordS); // 查询IDC Data - System.out.println("[oversea数据源]IDC数据查询"); + } catch (Exception e) { - log.error("[oversea数据源]IDC数据查询异常: {}", e.getMessage()); + log.error("[oversea数据源]IDC数据处理异常: {}", e.getMessage()); } return; } - // 给管理员发送预警信息 - messageDTO.setContent(connR.getInfo()); - systemClient.sendTo(messageDTO); + try { + // 给管理员发送预警信息 + String message = StrUtil.replace(connR.getInfo(), "xxx", "oversea"); + messageDTO.setContent(message); + systemClient.sendTo(messageDTO); + }catch (Exception e){ + log.error("发送oversea数据源异常信息失败: {}", e.getMessage()); + } + UserTokenContext.remove(); } } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/controller/SendMessageController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/controller/SendMessageController.java index 44edcb11..aeb6eb5c 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/controller/SendMessageController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/controller/SendMessageController.java @@ -24,7 +24,7 @@ public class SendMessageController { sendMessage.send(title, message, groupId, notific); } - @GetMapping("sendTo") + @PostMapping("sendTo") public void sendTo(@RequestBody MessageDTO messageDTO){ sysBaseAPI.sendTemplateMessage(messageDTO); } From 73bc57561a7206a07a3bec42c7fbbe576788e89e Mon Sep 17 00:00:00 2001 From: nieziyan Date: Wed, 20 Dec 2023 20:22:23 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat=EF=BC=9A1.=E4=BD=BF=E7=94=A8=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=A8=A1=E6=9D=BF2.=E7=BA=BF=E7=A8=8B=E6=8D=A2?= =?UTF-8?q?=E4=B8=BA=E5=AE=9A=E6=97=B6=E8=B0=83=E5=BA=A63.=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=91=98=E8=A6=81=E4=BF=A1?= =?UTF-8?q?=E6=81=AFbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/api/dto/message/MessageDTO.java | 4 +- .../java/org/jeecg/common/util/JDBCUtil.java | 4 +- .../jeecg/modules/DatabaseStatusManager.java | 58 ----------- .../src/main/java/org/jeecg/modules/Demo.java | 38 ++----- .../org/jeecg/modules/EmailStatusManager.java | 61 ------------ .../jeecg/modules/ServerStatusManager.java | 52 ---------- .../jeecg/modules/aspect/StatusAspect.java | 98 ++++++++++--------- .../org/jeecg/modules/idc/IDCDataFetch.java | 12 ++- .../modules/service/ISysDatabaseService.java | 2 + .../service/impl/SysDatabaseServiceImpl.java | 30 +++--- .../service/impl/SysEmailServiceImpl.java | 8 +- .../service/impl/SysServerServiceImpl.java | 72 +++++++++----- .../jeecg/JeecgAbnormalAlarmApplication.java | 18 +--- 13 files changed, 147 insertions(+), 310 deletions(-) delete mode 100644 jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/DatabaseStatusManager.java delete mode 100644 jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/EmailStatusManager.java delete mode 100644 jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/ServerStatusManager.java diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/dto/message/MessageDTO.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/dto/message/MessageDTO.java index 9196817e..adf600b5 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/dto/message/MessageDTO.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/dto/message/MessageDTO.java @@ -115,9 +115,9 @@ public class MessageDTO implements Serializable { this.content = content; } - public MessageDTO(String title, String content, String toUser) { + public MessageDTO(String title, String template, String toUser) { this.title = title; - this.content = content; + this.templateCode = template; this.toUser = toUser; } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/JDBCUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/JDBCUtil.java index 6bf9d222..0c1d3b4f 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/JDBCUtil.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/JDBCUtil.java @@ -60,8 +60,8 @@ public class JDBCUtil { try (Connection connection = dataSource.getConnection()) { return new ConnR().setConn(true); } catch (SQLException e) { - String message = String.format("[xxx数据源]连接失败: %s", e.getMessage()); - return new ConnR().setInfo(message); + // String message = String.format("[xxx数据源]连接失败: %s", e.getMessage()); + return new ConnR().setInfo(e.getMessage()); } } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/DatabaseStatusManager.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/DatabaseStatusManager.java deleted file mode 100644 index 086d9941..00000000 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/DatabaseStatusManager.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.jeecg.modules; - -import lombok.extern.slf4j.Slf4j; -import org.jeecg.common.constant.RedisConstant; -import org.jeecg.common.util.JDBCUtil; -import org.jeecg.common.util.RedisUtil; -import org.jeecg.common.util.SpringContextUtils; -import org.jeecg.modules.base.entity.postgre.SysDatabase; -import org.jeecg.modules.service.ISysDatabaseService; -import org.springframework.stereotype.Component; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -@Component -@Slf4j -public class DatabaseStatusManager { - - public void start() { - DbStatusThread dbStatusThread = new DbStatusThread(); - dbStatusThread.start(); - } - - private static class DbStatusThread extends Thread{ - - private long sleepTime; - - private ISysDatabaseService databaseService; - - private DbStatusThread(){ - init(); - } - - @Override - public void run() { - while (true) { - try { - databaseService.status2Redis(); - } catch (Exception e) { - log.error("DatabaseStatusManager.run()异常: {}", e.getMessage()); - }finally { - try { - TimeUnit.MILLISECONDS.sleep(sleepTime); - } catch (InterruptedException e) { - log.error("DatabaseStatusManager.sleep()异常: {}", e.getMessage()); - } - } - } - } - - private void init(){ - sleepTime = 5 * 1000; // 睡眠时间5s - databaseService = SpringContextUtils.getBean(ISysDatabaseService.class); - } - } -} diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/Demo.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/Demo.java index de3da4d9..939a2b28 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/Demo.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/Demo.java @@ -17,36 +17,10 @@ import java.util.concurrent.*; public class Demo { public static void main(String[] args) { - EmailServiceManager manager = EmailServiceManager.getInstance(); - SysEmail email = new SysEmail(); - // Get - email.setEmailServerAddress("imap.qiye.163.com"); - email.setUsername("cnndc.rn.ng@ndc.org.cn"); - email.setPassword("cnndc66367220"); - email.setPort(993); - - /*email.setEmailServerAddress("imap.exmail.qq.com"); - email.setUsername("xiaoguangbin@hivekion.com"); - email.setPassword("Ans9sLY4kVnux7ai"); - email.setPort(143); - - // Send - email.setEmailServerAddress("smtphz.qiye.163.com"); - email.setUsername("cnndc.rn.ng@ndc.org.cn"); - email.setPassword("cnndc66367220"); - email.setPort(465); - - email.setEmailServerAddress("smtp.163.com"); - email.setUsername("armd_auto@163.com"); - email.setPassword("NVOWHFOGWVOFILVV"); - email.setPort(25);*/ - - /*manager.init(email); - long start = System.currentTimeMillis(); - System.out.println(manager.canReceiveSSL() || manager.canReceive()); - long end = System.currentTimeMillis(); - System.out.println("连接耗时: " + (end - start) / 1000 + "s");*/ - test(); + Executor executor = Executors.newFixedThreadPool(3); + for (int i = 0; i < 3; i++) { + CompletableFuture.runAsync(Demo::test2, executor); + } } public static void test(){ @@ -86,4 +60,8 @@ public class Demo { e.printStackTrace(); }*/ } + + public static void test2(){ + throw new RuntimeException("测试异常"); + } } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/EmailStatusManager.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/EmailStatusManager.java deleted file mode 100644 index 3bf35a95..00000000 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/EmailStatusManager.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.jeecg.modules; - -import lombok.extern.slf4j.Slf4j; -import org.jeecg.common.constant.RedisConstant; -import org.jeecg.common.util.EmailUtil; -import org.jeecg.common.util.JDBCUtil; -import org.jeecg.common.util.RedisUtil; -import org.jeecg.common.util.SpringContextUtils; -import org.jeecg.modules.base.entity.postgre.SysDatabase; -import org.jeecg.modules.base.entity.postgre.SysEmail; -import org.jeecg.modules.service.ISysDatabaseService; -import org.jeecg.modules.service.ISysEmailService; -import org.springframework.stereotype.Component; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -@Component -@Slf4j -public class EmailStatusManager { - - public void start() { - EmailStatusThread emailStatusThread = new EmailStatusThread(); - emailStatusThread.start(); - } - - private static class EmailStatusThread extends Thread{ - - private long sleepTime; - - private ISysEmailService emailService; - - private EmailStatusThread(){ - init(); - } - - @Override - public void run() { - while (true){ - try { - emailService.status2Redis(); - } catch (Exception e) { - log.error("EmailStatusManager.run()异常: {}", e.getMessage()); - }finally { - try { - TimeUnit.MILLISECONDS.sleep(sleepTime); - } catch (InterruptedException e) { - log.error("EmailStatusManager.sleep()异常: {}", e.getMessage()); - } - } - } - } - - private void init(){ - sleepTime = 5 * 60 * 1000; // 睡眠时间5min - emailService = SpringContextUtils.getBean(ISysEmailService.class); - } - } -} diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/ServerStatusManager.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/ServerStatusManager.java deleted file mode 100644 index 607efa6c..00000000 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/ServerStatusManager.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.jeecg.modules; - -import lombok.extern.slf4j.Slf4j; -import org.jeecg.common.util.SpringContextUtils; -import org.jeecg.modules.service.ISysDatabaseService; -import org.jeecg.modules.service.ISysServerService; -import org.springframework.stereotype.Component; - -import java.util.concurrent.TimeUnit; - -@Component -@Slf4j -public class ServerStatusManager { - - public void start() { - ServerStatusThread serverStatusThread = new ServerStatusThread(); - serverStatusThread.start(); - } - - private static class ServerStatusThread extends Thread{ - - private long sleepTime; - - private ISysServerService serverService; - - private ServerStatusThread(){ - init(); - } - - @Override - public void run() { - while (true) { - try { - serverService.status2Redis(); - } catch (Exception e) { - log.error("ServerStatusManager.run()异常: {}", e.getMessage()); - }finally { - try { - TimeUnit.MILLISECONDS.sleep(sleepTime); - } catch (InterruptedException e) { - log.error("ServerStatusManager.sleep()异常: {}", e.getMessage()); - } - } - } - } - - private void init(){ - sleepTime = 5 * 1000; // 睡眠时间5s - serverService = SpringContextUtils.getBean(ISysServerService.class); - } - } -} diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/aspect/StatusAspect.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/aspect/StatusAspect.java index 136e96c8..2dda0e0b 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/aspect/StatusAspect.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/aspect/StatusAspect.java @@ -28,6 +28,8 @@ import org.jeecg.modules.qiyeEmail.base.InstanceSDK; import org.jeecg.modules.qiyeEmail.base.RParam; import org.jeecg.modules.qiyeEmail.base.dto.AccountInfo; import org.jeecg.modules.qiyeEmail.service.Account; +import org.jeecg.modules.service.IAlarmRuleService; +import org.jeecg.modules.service.ISysDatabaseService; import org.jeecg.modules.service.ISysEmailService; import org.jeecg.modules.service.ISysServerService; import org.springframework.beans.factory.annotation.Autowired; @@ -56,16 +58,21 @@ public class StatusAspect { @Autowired private ISysServerService serverService; + @Autowired + private ISysDatabaseService databaseService; + + @Autowired + private IAlarmRuleService alarmRuleService; + // 新增|修改邮箱服务器信息后 异步更新其状态信息 @Async @AfterReturning("execution(* org.jeecg.modules.service.impl.SysEmailServiceImpl.update(..)) || " + "execution(* org.jeecg.modules.service.impl.SysEmailServiceImpl.create(..))") public void updateEamilStatus(JoinPoint point){ Object[] args = point.getArgs(); - if (ArrayUtil.length(args) > 0){ - SysEmail email = (SysEmail) args[0]; - emailService.status2Redis(email); - } + if (ArrayUtil.length(args) == 0) return; + SysEmail email = (SysEmail) args[0]; + emailService.status2Redis(email); } /* @@ -76,18 +83,9 @@ public class StatusAspect { "execution(* org.jeecg.modules.service.impl.SysDatabaseServiceImpl.create(..))") public void updateDatabaseStatus(JoinPoint point){ Object[] args = point.getArgs(); - if (ArrayUtil.length(args) > 0) { - SysDatabase database = (SysDatabase) args[0]; - String id = database.getId(); - String name = database.getName(); - String dbUrl = database.getDbUrl(); - String dbDriver = database.getDbDriver(); - String dbUsername = database.getDbUsername(); - String dbPassword = database.getDbPassword(); - boolean isConn = JDBCUtil.isConnection(dbUrl, dbDriver, dbUsername, dbPassword); - String statusKey = RedisConstant.DATABASE_STATUS; - redisUtil.hset(statusKey, id, new NameValue(name, isConn)); - } + if (ArrayUtil.length(args) == 0) return; + SysDatabase database = (SysDatabase) args[0]; + databaseService.status2Redis(database); } /* @@ -99,35 +97,47 @@ public class StatusAspect { "execution(* org.jeecg.modules.service.impl.SysServerServiceImpl.create(..))") public void updateServerStatus(JoinPoint point){ Object[] args = point.getArgs(); - if (ArrayUtil.length(args) > 0) { - String key = RedisConstant.SERVER_STATUS; - String status = ServerStatus.UNKNOWN.getValue(); // 初始值为-1 - SysServer server = (SysServer) args[0]; - String id = server.getId(); - String name = server.getName(); - String ipAddress = server.getIpAddress(); - try { - String token = ManageUtil.getToken(); - Servers servers = monitorAlarm.listApp(ipAddress, MonitorConstant.SERVER_APP, token).getResult(); - // 获取所有监控主机信息 - List hosts = servers.getRecords(); - for (Host host : hosts) { - String code = host.getCode(); - if (!StrUtil.equals(ipAddress, code)) - continue; - server.setHostId(host.getHostId()); - status = host.getStatus(); - } - // 更新该服务器状态信息 - redisUtil.hset(key, id, new NameValue(name, status)); - // 更新该服务器的HostId - serverService.updateById(server); - }catch (FeignException.Unauthorized e){ - ManageUtil.refreshToken(); - log.warn("向运管系统查询Hosts信息异常: Token失效,已刷新Token"); - }catch (Exception e){ - log.error("向运管系统查询Hosts信息异常: {}", e.getMessage()); + if (ArrayUtil.length(args) == 0) return; + String key = RedisConstant.SERVER_STATUS; + String status = ServerStatus.UNKNOWN.getValue(); // 初始值为-1 + SysServer server = (SysServer) args[0]; + String id = server.getId(); + String name = server.getName(); + String ipAddress = server.getIpAddress(); + try { + String token = ManageUtil.getToken(); + Servers servers = monitorAlarm.listApp(ipAddress, MonitorConstant.SERVER_APP, token).getResult(); + // 获取所有监控主机信息 + List hosts = servers.getRecords(); + for (Host host : hosts) { + String code = host.getCode(); + if (!StrUtil.equals(ipAddress, code)) + continue; + server.setHostId(host.getHostId()); + status = host.getStatus(); } + // 更新该服务器状态信息 + redisUtil.hset(key, id, new NameValue(name, status)); + // 更新该服务器的HostId + serverService.updateById(server); + }catch (FeignException.Unauthorized e){ + ManageUtil.refreshToken(); + log.warn("向运管系统查询Hosts信息异常: Token失效,已刷新Token"); + }catch (Exception e){ + log.error("向运管系统查询Hosts信息异常: {}", e.getMessage()); } } + + /* + * 删除Email|Database|Server时 同步删除Redis和数据库中相关联的预警规则 + * */ + @Async + @AfterReturning("execution(* org.jeecg.modules.service.impl.SysServerServiceImpl.deleteById(..)) ||" + + "execution(* org.jeecg.modules.service.impl.SysEmailServiceImpl.deleteById(..)) || " + + "execution(* org.jeecg.modules.service.impl.SysDatabaseServiceImpl.deleteById(..))") + public void deleteRules(JoinPoint point){ + Object[] args = point.getArgs(); + if (ArrayUtil.length(args) > 0) + alarmRuleService.deleteBySourceId((String) args[0]); + } } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/idc/IDCDataFetch.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/idc/IDCDataFetch.java index ef5eaccb..8429efcb 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/idc/IDCDataFetch.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/idc/IDCDataFetch.java @@ -17,6 +17,8 @@ import org.springframework.stereotype.Component; import java.sql.Connection; import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.TimeUnit; import static org.jeecg.common.util.TokenUtils.getTempToken; @@ -50,7 +52,7 @@ public class IDCDataFetch { @Scheduled(fixedDelayString = "${request-interval}", timeUnit = TimeUnit.SECONDS) public void fetch() { JdbcTemplate template; - MessageDTO messageDTO = new MessageDTO("IDC数据源异常", null, "admin"); + MessageDTO messageDTO = new MessageDTO("IDC数据源异常", "IDC_Datasource_Status", "admin"); messageDTO.setType(MessageTypeEnum.XT.getType()); ConnR connR = JDBCUtil.isConnection(urlM, usernameM, passwordM); if (connR.isConn()) { @@ -67,8 +69,12 @@ public class IDCDataFetch { // 对发送警告消息时可能出现的异常进行捕获(503) 防止影响后续代码执行 try { // 给管理员发送预警信息 - String message = StrUtil.replace(connR.getInfo(), "xxx", "inland"); - messageDTO.setContent(message); + /*String message = StrUtil.replace(connR.getInfo(), "xxx", "inland"); + messageDTO.setContent(message);*/ + Map data = new HashMap<>(); + data.put("datasource", "inland(测试)"); + data.put("info", connR.getInfo()); + messageDTO.setData(data); systemClient.sendTo(messageDTO); }catch (Exception e){ log.error("发送inland数据源异常信息失败: {}", e.getMessage()); diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysDatabaseService.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysDatabaseService.java index f6888a80..c7f7c905 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysDatabaseService.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/ISysDatabaseService.java @@ -35,5 +35,7 @@ public interface ISysDatabaseService extends IService { void status2Redis(); + void status2Redis(SysDatabase database); + String getNameById(String id); } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysDatabaseServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysDatabaseServiceImpl.java index aa388765..00cd5524 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysDatabaseServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysDatabaseServiceImpl.java @@ -29,12 +29,14 @@ import org.jeecg.modules.service.ISysDatabaseService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import static org.jeecg.common.constant.enums.DbType.*; @@ -181,9 +183,6 @@ public class SysDatabaseServiceImpl extends ServiceImpl databases = list(); - Map statusMap = new HashMap<>(); for (SysDatabase database : databases) { - String id = database.getId(); - String name = database.getName(); - String dbUrl = database.getDbUrl(); - String dbDriver = database.getDbDriver(); - String dbUsername = database.getDbUsername(); - String dbPassword = database.getDbPassword(); - boolean isConn = JDBCUtil.isConnection(dbUrl, dbDriver, dbUsername, dbPassword); - statusMap.put(id, new NameValue(name, isConn)); + this.status2Redis(database); } - // 将数据源连接状态更新到reids + } + + @Override + public void status2Redis(SysDatabase database) { String statusKey = RedisConstant.DATABASE_STATUS; - redisUtil.hmset(statusKey, statusMap); + String id = database.getId(); + String name = database.getName(); + String dbUrl = database.getDbUrl(); + String dbDriver = database.getDbDriver(); + String dbUsername = database.getDbUsername(); + String dbPassword = database.getDbPassword(); + boolean isConn = JDBCUtil.isConnection(dbUrl, dbDriver, dbUsername, dbPassword); + redisUtil.hset(statusKey, id, new NameValue(name, isConn)); } @Override diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysEmailServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysEmailServiceImpl.java index 56fdef2e..2d27d992 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysEmailServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysEmailServiceImpl.java @@ -31,6 +31,7 @@ import org.jeecg.modules.service.IAlarmRuleService; import org.jeecg.modules.service.ISysEmailService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -38,6 +39,7 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import static org.jeecg.modules.base.enums.Enabled.ENABLED; @@ -164,9 +166,6 @@ public class SysEmailServiceImpl extends ServiceImpl i boolean success = this.removeById(id); if (success){ delStatus(id); - // 同步删除Redis和数据库中的预警规则 - IAlarmRuleService alarmRuleService = SpringContextUtils.getBean(IAlarmRuleService.class); - alarmRuleService.deleteBySourceId(id); return Result.OK(Prompt.DELETE_SUCC); } return Result.error(Prompt.DELETE_ERR); @@ -218,12 +217,13 @@ public class SysEmailServiceImpl extends ServiceImpl i } @Override + @Scheduled(fixedDelay = 60, timeUnit = TimeUnit.SECONDS) public void status2Redis() { // 获取所有配置的邮箱服务器 List emails = list(); // 使用并发 更新邮箱状态及用量 for (SysEmail email : emails) { - CompletableFuture.runAsync(() -> status2Redis(email)); + CompletableFuture.runAsync(() -> this.status2Redis(email)); } } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java index c384d1d8..2d670c24 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/SysServerServiceImpl.java @@ -23,7 +23,6 @@ import org.jeecg.common.util.NumUtil; import org.jeecg.common.util.PageUtil; import org.jeecg.common.util.RedisUtil; import org.jeecg.common.util.SpringContextUtils; -import org.jeecg.modules.ServerStatusManager; import org.jeecg.modules.base.dto.*; import org.jeecg.modules.base.entity.monitor.Host; import org.jeecg.modules.base.entity.monitor.Item; @@ -38,6 +37,7 @@ import org.jeecg.modules.mapper.SysServerMapper; import org.jeecg.modules.service.IAlarmRuleService; import org.jeecg.modules.service.ISysServerService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -188,9 +188,6 @@ public class SysServerServiceImpl extends ServiceImpl items = host.getItems(); - String runTime = items.get(MonitorConstant.ITEM_RUNTIME).getLastValue(); - runTime = StrUtil.isBlank(runTime) ? "--" : - NumUtil.keepStr(Long.parseLong(runTime) / 3600.0, 1) + "h"; - String ramSize = items.get(MonitorConstant.ITEM_RAMSIZE).getLastValue(); - ramSize = StrUtil.isBlank(ramSize) ? "--" : - NumUtil.keepStr(Double.parseDouble(ramSize.replace("MB", "")) / 1024, 1) + "GB"; - String cpuCores = items.get(MonitorConstant.ITEM_CPUCORES).getLastValue(); - String totalDiskPar = items.get(MonitorConstant.ITEM_TOTALSIDKPAR).getLastValue(); - String hostName = items.get(MonitorConstant.ITEM_HOSTNAME).getLastValue(); - String osVersion = items.get(MonitorConstant.ITEM_OSVERSION).getLastValue(); - String netWork = items.get(MonitorConstant.ITEM_NETWORK).getLastValue(); - String location = items.get(MonitorConstant.ITEM_LOCATION).getLastValue(); - String ip = items.get(MonitorConstant.ITEM_IP).getLastValue(); - String zone = items.get(MonitorConstant.ITEM_ZONE).getLastValue(); - String osName = items.get(MonitorConstant.ITEM_OSNAME).getLastValue(); - String startTime = items.get(MonitorConstant.ITEM_STARTTIME).getLastValue(); - String cpuType = items.get(MonitorConstant.ITEM_CPUTYPE).getLastValue(); + Item empty; + empty = items.get(MonitorConstant.ITEM_RUNTIME); + String runTime = ObjectUtil.isNull(empty) ? "--" : + NumUtil.keepStr(Long.parseLong(empty.getLastValue()) / 3600.0, 1) + "h"; + + empty = items.get(MonitorConstant.ITEM_RAMSIZE); + String ramSize = ObjectUtil.isNull(empty) ? "--" : + NumUtil.keepStr(Double.parseDouble(empty.getLastValue().replace("MB", "")) / 1024, 1) + "GB"; + + empty = items.get(MonitorConstant.ITEM_CPUCORES); + String cpuCores = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue(); + + empty = items.get(MonitorConstant.ITEM_TOTALSIDKPAR); + String totalDiskPar = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue(); + + empty = items.get(MonitorConstant.ITEM_HOSTNAME); + String hostName = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue(); + + empty = items.get(MonitorConstant.ITEM_OSVERSION); + String osVersion = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue(); + + empty = items.get(MonitorConstant.ITEM_NETWORK); + String netWork = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue(); + + empty = items.get(MonitorConstant.ITEM_LOCATION); + String location = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue(); + + empty = items.get(MonitorConstant.ITEM_IP); + String ip = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue(); + + empty = items.get(MonitorConstant.ITEM_ZONE); + String zone = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue(); + + empty = items.get(MonitorConstant.ITEM_OSNAME); + String osName = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue(); + + empty = items.get(MonitorConstant.ITEM_STARTTIME); + String startTime = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue(); + + empty = items.get(MonitorConstant.ITEM_CPUTYPE); + String cpuType = ObjectUtil.isNull(empty) ? "--" : empty.getLastValue(); /* CPU MEMORY LOADS DISK */ - String cpuUsed = items.get(MonitorConstant.ITEM_CPUUSED).getLastValue(); // 0.24 + empty = items.get(MonitorConstant.ITEM_CPUUSED); + String cpuUsed = ObjectUtil.isNull(empty) ? null : empty.getLastValue(); // 0.24 Double cpuUsedValue = NumUtil.keep(cpuUsed, 3); cpuUsedValue = ObjectUtil.isNull(cpuUsedValue) ? 0 : cpuUsedValue * 100; - String memoryUsed = items.get(MonitorConstant.ITEM_MEMORYUSED).getLastValue(); // 16.64927 + + empty = items.get(MonitorConstant.ITEM_MEMORYUSED); + String memoryUsed = ObjectUtil.isNull(empty) ? null : empty.getLastValue(); // 16.64927 Double memoryUsedValue = NumUtil.keep(memoryUsed, 1); memoryUsedValue = ObjectUtil.isNull(memoryUsedValue) ? 0 : memoryUsedValue; + Map diskUsedMap = items.entrySet().stream() // 6.540206 .filter(entry -> entry.getKey().contains(MonitorConstant.PRIFIX_DISKUSED)) .collect(Collectors.toMap(Map.Entry::getKey, item -> item.getValue().getLastValue())); @@ -320,6 +345,7 @@ public class SysServerServiceImpl extends ServiceImpl sysServers = this.list(); String key = RedisConstant.SERVER_STATUS; diff --git a/jeecg-server-cloud/armd-abnormal-alarm-start/src/main/java/org/jeecg/JeecgAbnormalAlarmApplication.java b/jeecg-server-cloud/armd-abnormal-alarm-start/src/main/java/org/jeecg/JeecgAbnormalAlarmApplication.java index 5aa2ca35..b692a493 100644 --- a/jeecg-server-cloud/armd-abnormal-alarm-start/src/main/java/org/jeecg/JeecgAbnormalAlarmApplication.java +++ b/jeecg-server-cloud/armd-abnormal-alarm-start/src/main/java/org/jeecg/JeecgAbnormalAlarmApplication.java @@ -3,9 +3,6 @@ package org.jeecg; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.util.oConvertUtils; -import org.jeecg.modules.DatabaseStatusManager; -import org.jeecg.modules.EmailStatusManager; -import org.jeecg.modules.ServerStatusManager; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -28,12 +25,6 @@ import java.net.UnknownHostException; @RequiredArgsConstructor public class JeecgAbnormalAlarmApplication extends SpringBootServletInitializer implements CommandLineRunner { - private final ServerStatusManager serverStatusManager; - - private final EmailStatusManager emailStatusManager; - - private final DatabaseStatusManager databaseStatusManager; - @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(JeecgAbnormalAlarmApplication.class); @@ -54,12 +45,5 @@ public class JeecgAbnormalAlarmApplication extends SpringBootServletInitializer } @Override - public void run(String... args) throws Exception { - // 启动监测数据库连接状态的线程 - databaseStatusManager.start(); - // 启动监测邮箱服务器连接状态的线程 - emailStatusManager.start(); - // 启动监测服务器连接状态的线程 - serverStatusManager.start(); - } + public void run(String... args) throws Exception {} } \ No newline at end of file