[monitor] 最高调度级别的采集数据告警恢复时监控状态联动
This commit is contained in:
@@ -55,7 +55,6 @@ public class DispatchAlarm {
|
||||
}
|
||||
|
||||
private void storeAlertData(Alert alert) {
|
||||
// todo 过滤重复告警 使用 告警持续时间参数-duration 这个时间段的相同重复告警应该被过滤
|
||||
// todo 使用缓存不直接操作库
|
||||
Monitor monitor = monitorService.getMonitor(alert.getMonitorId());
|
||||
if (monitor == null) {
|
||||
@@ -67,8 +66,7 @@ public class DispatchAlarm {
|
||||
// 当监控未管理时 忽略静默其告警信息
|
||||
return;
|
||||
}
|
||||
if (monitor.getStatus() != CommonConstants.UN_AVAILABLE_CODE
|
||||
&& monitor.getStatus() != CommonConstants.UN_REACHABLE_CODE) {
|
||||
if (monitor.getStatus() == CommonConstants.AVAILABLE_CODE) {
|
||||
if (CommonConstants.AVAILABLE.equals(alert.getTarget())) {
|
||||
// 可用性告警 需变更监控状态为不可用
|
||||
monitorService.updateMonitorStatus(monitor.getId(), CommonConstants.UN_AVAILABLE_CODE);
|
||||
@@ -76,6 +74,11 @@ public class DispatchAlarm {
|
||||
// 可达性告警 需变更监控状态为不可达
|
||||
monitorService.updateMonitorStatus(monitor.getId(), CommonConstants.UN_REACHABLE_CODE);
|
||||
}
|
||||
} else {
|
||||
// 若是恢复告警 需对监控状态进行恢复
|
||||
if (alert.getStatus() == 2) {
|
||||
monitorService.updateMonitorStatus(alert.getMonitorId(), CommonConstants.AVAILABLE_CODE);
|
||||
}
|
||||
}
|
||||
// 告警落库
|
||||
alertService.addAlert(alert);
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.usthe.manager.pojo.dto.AppCount;
|
||||
import com.usthe.manager.pojo.entity.Monitor;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
@@ -50,6 +51,7 @@ public interface MonitorDao extends JpaRepository<Monitor, Long>, JpaSpecificati
|
||||
* @param id 监控ID
|
||||
* @param status 监控状态
|
||||
*/
|
||||
@Modifying
|
||||
@Query("update Monitor set status = :status where id = :id")
|
||||
void updateMonitorStatus(@Param(value = "id") Long id, @Param(value = "status") byte status);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import java.util.stream.Collectors;
|
||||
* @date 2021/11/14 13:06
|
||||
*/
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Slf4j
|
||||
public class MonitorServiceImpl implements MonitorService {
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ CREATE TABLE alert
|
||||
alert_define_id bigint not null comment '告警关联的告警定义ID',
|
||||
priority tinyint not null default 0 comment '告警级别 0:高-emergency-紧急告警-红色 1:中-critical-严重告警-橙色 2:低-warning-警告告警-黄色',
|
||||
content varchar(255) not null comment '告警通知实际内容',
|
||||
status tinyint not null default 0 comment '告警状态: 0-待发送 1-已发送 2-已过期(已经超过持续时间)',
|
||||
status tinyint not null default 0 comment '告警状态: 0-正常告警 1-阈值触发但未达到告警次数 2-恢复告警',
|
||||
times int not null comment '触发次数,即达到告警定义的触发阈值次数要求后才会发告警',
|
||||
gmt_create timestamp default current_timestamp comment 'create time',
|
||||
primary key (id)
|
||||
|
||||
Reference in New Issue
Block a user