From 3201a13cc88f2bf371aab8a07f374a7d537af3f2 Mon Sep 17 00:00:00 2001 From: nieziyan Date: Thu, 21 Sep 2023 14:08:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix=EF=BC=9A=E8=AE=B0=E5=BD=95=E6=8A=A5?= =?UTF-8?q?=E8=AD=A6=E6=97=A5=E5=BF=97=E7=BC=BA=E5=B0=91RuleId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeecg/modules/quartz/job/SysInfoJob.java | 19 ++++++++++--------- .../org/jeecg/modules/test/JobController.java | 4 ++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/SysInfoJob.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/SysInfoJob.java index 49d432ad..a9611a70 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/SysInfoJob.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/SysInfoJob.java @@ -90,7 +90,6 @@ public class SysInfoJob implements Job { // 向运管查询监控项数据 Result result = monitorSystem.itemBack(itemId, 0, start, end); Double current = result.getResult().getNow(); - log.error("当前CPU使用率为:{}", current); // 解析预警规则,判断是否需要报警 ObjectMapper mapper = new ObjectMapper(); @@ -98,24 +97,26 @@ public class SysInfoJob implements Job { rule.setCurrent(current); boolean needWarn = parse(rule); if (needWarn){ - // 组织要发送的预警信息 + // 记录报警日志 + AlarmLog alarmLog = new AlarmLog(); + alarmLog.setRuleId(ruleId); + alarmLog.setAlarmValue(StrUtil.toString(current)); String ruleName = alarmRule.getName(); + Double threshold = rule.getThreshold(); String message = "您设定的预警规则:"+ruleName+"," + "预警信息为:"+ operator + ",当前值为:" + current; + alarmLog.setAlarmInfo(message); + alarmClient.create(alarmLog); + // 规则触发报警后,设置该规则的沉默周期(如果有) // 沉默周期失效之前,该规则不会再次被触发 Long silenceCycle = alarmRule.getSilenceCycle(); ruleSilence(silenceKey, silenceCycle); + // 发送报警信息 String groupId = alarmRule.getContactId(); String notific = alarmRule.getNotification(); - sendMessage.send(message,groupId,notific); - // 记录报警日志 - AlarmLog alarmLog = new AlarmLog(); - alarmLog.setAlarmStartDate(LocalDateTime.now()); - alarmLog.setAlarmValue(current.toString()); - alarmLog.setAlarmInfo(message); - alarmClient.create(alarmLog); + sendMessage.send(message, groupId, notific); } } catch (JsonProcessingException e) { log.error("预警规则{}解析失败!", operator); diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/test/JobController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/test/JobController.java index 7fef3815..3b1b6ffe 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/test/JobController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/test/JobController.java @@ -103,8 +103,8 @@ public class JobController { alarmLog.setAlarmValue(StrUtil.toString(current)); String ruleName = alarmRule.getName(); Double threshold = rule.getThreshold(); - String message = "您设定的预警规则:"+ruleName+"," + "预警阈值为:["+ - operator+threshold+"],当前值为:"+current; + String message = "您设定的预警规则:"+ruleName+"," + + "预警信息为:"+ operator + ",当前值为:" + current; alarmLog.setAlarmInfo(message); alarmClient.create(alarmLog); From 699a8b068b2046a5b4c903d53d0dfbb1c6e9490f Mon Sep 17 00:00:00 2001 From: nieziyan Date: Thu, 21 Sep 2023 16:05:20 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix=EF=BC=9A=E6=8A=A5=E8=AD=A6=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=BB=91=E5=AE=9A=E5=BD=93=E5=89=8D=E6=8A=A5=E8=AD=A6?= =?UTF-8?q?=E8=A7=84=E5=88=99,=E9=9D=9E=E6=9C=80=E6=96=B0=E8=A7=84?= =?UTF-8?q?=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/modules/base/entity/postgre/AlarmLog.java | 6 ++++++ .../java/org/jeecg/modules/mapper/xml/AlarmLogMapper.xml | 2 +- .../main/java/org/jeecg/modules/quartz/job/SysInfoJob.java | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/postgre/AlarmLog.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/postgre/AlarmLog.java index f375178a..6e844e04 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/postgre/AlarmLog.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/postgre/AlarmLog.java @@ -47,6 +47,12 @@ public class AlarmLog implements Serializable { @TableField(value = "alarm_value") private String alarmValue; + /** + * 当前的规则信息 + */ + @TableField(value = "operator") + private String operator; + public AlarmLog() { this.alarmStartDate = LocalDateTime.now(); } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/AlarmLogMapper.xml b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/AlarmLogMapper.xml index 9610858d..697e3bbd 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/AlarmLogMapper.xml +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/AlarmLogMapper.xml @@ -30,7 +30,7 @@ l.alarm_start_date, l.alarm_info, l.alarm_value, - r.OPERATOR, + l.OPERATOR, r.source_type, CASE r.source_type diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/SysInfoJob.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/SysInfoJob.java index a9611a70..ad939483 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/SysInfoJob.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/SysInfoJob.java @@ -100,6 +100,7 @@ public class SysInfoJob implements Job { // 记录报警日志 AlarmLog alarmLog = new AlarmLog(); alarmLog.setRuleId(ruleId); + alarmLog.setOperator(operator); alarmLog.setAlarmValue(StrUtil.toString(current)); String ruleName = alarmRule.getName(); Double threshold = rule.getThreshold();