perf: 优化告警信息

dev
huangfeng 1 year ago
parent 4e488ed96f
commit 543a9993be

@ -1,5 +1,6 @@
package com.xydl.cac.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.xydl.cac.comparator.Comparator;
import com.xydl.cac.comparator.FloatCompare;
@ -60,7 +61,7 @@ public class WarnRule {
private String operator;
@NotNull(message = "告警级别不能为空")
@ApiModelProperty("告警级别 0:高 1:中 2:低")
@ApiModelProperty("告警级别 0:低 1:中 2:高")
@Column(name = "level")
private Integer level;
@ -83,6 +84,7 @@ public class WarnRule {
@Transient
private ModevTypePoint typePoint;
@Transient
@JsonIgnore
private Comparator actualComp;
public void initComparator(String comparator, String operator) {
@ -103,6 +105,9 @@ public class WarnRule {
log.error("该规则(" + id + ")比较器(" + comparator + ")异常");
}
}
if (actualComp != null) {
this.operatorDesc = actualComp.supportedOperator().get(this.operator);
}
}
public boolean canDo() {

@ -54,7 +54,7 @@ public class Warning {
@Column(name = "warn_desc")
private String warnDesc;
@ApiModelProperty("告警级别 0:高 1:中 2:低")
@ApiModelProperty("告警级别 0:低 1:中 2:高")
@Column(name = "warn_level")
private Integer warnLevel;

@ -28,8 +28,8 @@ public class WarningServiceImpl implements WarningService {
PageRequest request = PageRequest.of(condition.getPageNum() - 1, condition.getPageSize());
Specification<Warning> specification = (root, query, builder) -> {
Predicate predicate = builder.conjunction();
if (condition.getDevId() != null) {
predicate.getExpressions().add(builder.equal(root.get("eqmid"), condition.getDevId().toString()));
if (condition.getId() != null) {
predicate.getExpressions().add(builder.equal(root.get("sensorId"), condition.getId().toString()));
}
if (StringUtils.isNotBlank(condition.getState())) {
predicate.getExpressions().add(builder.equal(root.get("state"), condition.getState()));

@ -8,6 +8,7 @@ import com.xydl.cac.repository.WarnRuleRepository;
import com.xydl.cac.repository.WarningRepository;
import com.xydl.cac.service.DataService;
import com.xydl.cac.util.DateUtil;
import com.xydl.cac.util.DingTalkPushUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@ -54,7 +55,7 @@ public class RuleCheckTask {
Object value = map.get(typePoint.getField());
boolean r = rule.getActualComp().compare(value, rule.getThreshold());
if (r) {
this.sendWarning(rule, date, value);
this.sendWarning(rule, date, str, String.valueOf(value));
}
}
rule.setLastDTime(date);
@ -65,7 +66,7 @@ public class RuleCheckTask {
}
}
private void sendWarning(WarnRule rule, Date date, Object value) throws Exception {
private void sendWarning(WarnRule rule, Date date, String dateStr, String value) throws Exception {
NSensor sensor = rule.getNSensor();
ModevTypePoint typePoint = rule.getTypePoint();
Warning warning = Warning.builder()
@ -73,7 +74,7 @@ public class RuleCheckTask {
.ruleId(rule.getId())
.dTime(date)
.threshold(rule.getThreshold())
.warnValue((String) value)
.warnValue(value)
.warnLevel(rule.getLevel())
.state("1")
.warnDesc(sensor.getName() + " " + typePoint.getFieldDesc() + " 告警")
@ -81,6 +82,9 @@ public class RuleCheckTask {
.processTime(new Date())
.build();
warningRepository.save(warning);
String str = warning.getWarnDesc() + ", 采集时间:" + dateStr + ", 当前值:" + value + " "
+ rule.getOperatorDesc() + " 阈值(" + rule.getThreshold() + ")";
DingTalkPushUtil.pushText(str);
}
}

@ -17,8 +17,8 @@ import java.net.URLEncoder;
@Slf4j
public class DingTalkPushUtil {
public static final String CUSTOM_ROBOT_TOKEN = "b0571a2261a96ac2346c3c913e25783e0d7994bf1bff7e64e5a5e171eeccf1f8";
public static final String SECRET = "SEC0757cffdf63deea00a57f718f4540e5d97ffe887509d199403c06d9d00c0a158";
public static final String CUSTOM_ROBOT_TOKEN = "e65e730cba22e320e16926fd4ff19ce787fa2162d065792bb6562c6d4a4cf328";
public static final String SECRET = "SEC72e5fb1b4ce7f9fed55386040d599035c50f8d2a181ad66bd1277549f0716124";
public static final String KEY_WORD = "运维告警";

Loading…
Cancel
Save