Skip to content

Commit d4cd5e0

Browse files
authored
feat: add alarm rrd (#883)
1 parent 189c997 commit d4cd5e0

File tree

17 files changed

+601
-4
lines changed

17 files changed

+601
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0.
3+
*/
4+
package io.holoinsight.server.common.dao.entity;
5+
6+
import lombok.Data;
7+
8+
/**
9+
* 报警计数
10+
*
11+
* @author limengyang
12+
* @version AlarmCountable.java, v 0.1 2024年09月19日 17:38 limengyang
13+
*/
14+
@Data
15+
public class AlarmCountable {
16+
public Long customPluginId;
17+
public Long parentFolderId;
18+
public Long historyId;
19+
}

server/common/common-dao/src/main/java/io/holoinsight/server/common/dao/entity/Folder.java

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public class Folder {
2222
public String tenant;
2323
public String workspace;
2424
public Long parentFolderId;
25+
public Boolean alarmed;
26+
public Integer recentAlarm;
27+
public Long alarmRrdTime;
28+
public String recentAlarmHistoryId;
2529
public String creator;
2630
public String modifier;
2731

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0.
3+
*/
4+
package io.holoinsight.server.common.dao.entity;
5+
6+
import lombok.Data;
7+
8+
import java.io.Serializable;
9+
10+
/**
11+
* @author limengyang
12+
* @version FolderPath.java, v 0.1 2024年09月20日 11:14 limengyang
13+
*/
14+
@Data
15+
public class FolderPath implements Serializable {
16+
private static final long serialVersionUID = -783815229535552853L;
17+
private Long id;
18+
private String name;
19+
private String type = FOLDER;
20+
21+
public static final String FILE = "file";
22+
public static final String FOLDER = "folder";
23+
24+
public FolderPath(Long id, String name) {
25+
super();
26+
this.id = id;
27+
this.name = name;
28+
}
29+
30+
public FolderPath(Long id, String name, String type) {
31+
super();
32+
this.id = id;
33+
this.name = name;
34+
this.type = type;
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0.
3+
*/
4+
package io.holoinsight.server.common.dao.entity;
5+
6+
import lombok.Data;
7+
8+
import java.io.Serializable;
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
12+
/**
13+
* 文件夹路径
14+
*
15+
* @author limengyang
16+
* @version FolderPaths.java, v 0.1 2024年09月20日 10:09 limengyang
17+
*/
18+
@Data
19+
public class FolderPaths implements Serializable {
20+
private static final long serialVersionUID = 685496251839004159L;
21+
public List<FolderPath> paths = new ArrayList<FolderPath>();
22+
}

server/common/common-service/src/main/java/io/holoinsight/server/common/service/AlarmHistoryDetailService.java

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.baomidou.mybatisplus.extension.service.IService;
77
import io.holoinsight.server.common.MonitorPageRequest;
88
import io.holoinsight.server.common.MonitorPageResult;
9+
import io.holoinsight.server.common.dao.entity.AlarmHistory;
910
import io.holoinsight.server.common.dao.entity.AlarmHistoryDetail;
1011
import io.holoinsight.server.common.dao.entity.dto.AlarmHistoryDetailDTO;
1112

@@ -24,4 +25,6 @@ MonitorPageResult<AlarmHistoryDetailDTO> getListByPage(
2425

2526
List<Map<String, Object>> count(MonitorPageRequest<AlarmHistoryDetailDTO> pageRequest);
2627

28+
List<AlarmHistoryDetail> queryByTime(long from, long to);
29+
2730
}

server/common/common-service/src/main/java/io/holoinsight/server/common/service/AlarmHistoryService.java

+1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ MonitorPageResult<AlarmHistoryDTO> getListByPage(MonitorPageRequest<AlarmHistory
2525

2626
Boolean deleteById(Long id);
2727

28+
List<AlarmHistory> queryByTime(long from, long to);
2829
}

server/common/common-service/src/main/java/io/holoinsight/server/common/service/impl/AlarmHistoryDetailServiceImpl.java

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.holoinsight.server.common.DateUtil;
77
import io.holoinsight.server.common.J;
88
import io.holoinsight.server.common.dao.converter.AlarmHistoryDetailConverter;
9+
import io.holoinsight.server.common.dao.entity.AlarmHistory;
910
import io.holoinsight.server.common.dao.mapper.AlarmHistoryDetailMapper;
1011
import io.holoinsight.server.common.dao.entity.AlarmHistoryDetail;
1112
import io.holoinsight.server.common.dao.entity.dto.AlarmHistoryDetailDTO;
@@ -122,4 +123,13 @@ public List<Map<String, Object>> count(MonitorPageRequest<AlarmHistoryDetailDTO>
122123

123124
return list;
124125
}
126+
127+
@Override
128+
public List<AlarmHistoryDetail> queryByTime(long from, long to) {
129+
QueryWrapper<AlarmHistoryDetail> wrapper = new QueryWrapper<>();
130+
wrapper.le("alarm_time", new Date(to));
131+
wrapper.ge("alarm_time", new Date(from));
132+
List<AlarmHistoryDetail> alarmHistoryDetails = list(wrapper);
133+
return alarmHistoryDetails;
134+
}
125135
}

server/common/common-service/src/main/java/io/holoinsight/server/common/service/impl/AlarmHistoryServiceImpl.java

+14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
88
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
99
import io.holoinsight.server.common.EventBusHolder;
10+
import io.holoinsight.server.common.J;
1011
import io.holoinsight.server.common.MonitorPageRequest;
1112
import io.holoinsight.server.common.MonitorPageResult;
1213
import io.holoinsight.server.common.dao.converter.AlarmHistoryConverter;
@@ -22,7 +23,10 @@
2223

2324
import javax.annotation.Resource;
2425
import java.util.Date;
26+
import java.util.HashMap;
2527
import java.util.List;
28+
import java.util.Map;
29+
import java.util.Objects;
2630

2731
@Service
2832
public class AlarmHistoryServiceImpl extends ServiceImpl<AlarmHistoryMapper, AlarmHistory>
@@ -57,6 +61,16 @@ public Boolean deleteById(Long id) {
5761
return this.removeById(id);
5862
}
5963

64+
@Override
65+
public List<AlarmHistory> queryByTime(long from, long to) {
66+
QueryWrapper<AlarmHistory> wrapper = new QueryWrapper<>();
67+
wrapper.le("alarm_time", to);
68+
wrapper.ge("alarm_time", from);
69+
wrapper.eq("deleted", false);
70+
List<AlarmHistory> alarmHistories = list(wrapper);
71+
return alarmHistories;
72+
}
73+
6074
@Override
6175
public MonitorPageResult<AlarmHistoryDTO> getListByPage(
6276
MonitorPageRequest<AlarmHistoryDTO> pageRequest, List<String> uniqueIds) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ALTER TABLE `custom_plugin`
2+
ADD COLUMN `alarmed` TINYINT(4) NULL COMMENT '(归档)是否报警';
3+
ALTER TABLE `custom_plugin`
4+
ADD COLUMN `recent_alarm_rule_unique_id` varchar(5000) DEFAULT NULL COMMENT '(归档)最近报警unique ID';
5+
ALTER TABLE `custom_plugin`
6+
ADD COLUMN `recent_alarm` int(11) NULL COMMENT '(归档)最近报警数量';
7+
ALTER TABLE `custom_plugin`
8+
ADD COLUMN `alarm_rrd_time` bigint(20) NULL COMMENT '归档时间';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ALTER TABLE `folder` ADD COLUMN `alarmed` tinyint(4) DEFAULT NULL COMMENT '(归档)是否报警';
2+
ALTER TABLE `folder` ADD COLUMN `recent_alarm_rule_unique_id` varchar(5000) DEFAULT NULL COMMENT '(归档)最近报警unique ID';
3+
ALTER TABLE `folder` ADD COLUMN `recent_alarm` int(11) DEFAULT NULL COMMENT '(归档)最近报警数量';
4+
ALTER TABLE `folder` ADD COLUMN `alarm_rrd_time` bigint(20) DEFAULT NULL COMMENT '归档时间';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE `folder` ADD COLUMN `recent_alarm_history_id` varchar(5000) DEFAULT NULL COMMENT '(归档)最近报警历史ID';
2+
ALTER TABLE `custom_plugin` ADD COLUMN `recent_alarm_history_id` varchar(5000) DEFAULT NULL COMMENT '(归档)最近报警历史ID';

server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/model/event/WebhookInfo.java

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public class WebhookInfo implements Cloneable {
4747
*/
4848
private String webhookMsg;
4949

50+
/**
51+
* 回调类型
52+
*/
53+
private Byte type;
54+
5055
public WebhookInfo clone() {
5156
try {
5257
return (WebhookInfo) super.clone();

server/home/home-alert/src/main/java/io/holoinsight/server/home/alert/plugin/GetSubscriptionHandler.java

+27-4
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,23 @@ public void handle(List<AlertNotify> alertNotifies) {
172172
break;
173173
case "webhook":
174174
if (!alertNotify.getIsRecover()) {
175-
AlarmWebhook alertWebhook =
176-
alarmWebhookDOMapper.selectById(alertSubscribe.getGroupId());
177-
if (alertWebhook != null && alertWebhook.getStatus().equals((byte) 1)) {
178-
webhookInfos.add(DoConvert.alertWebhookDoConverter(alertWebhook));
175+
List<AlarmWebhook> alertWebhookList =
176+
getAllAlertWebHook(alertSubscribe.getTenant());
177+
List<Long> alertWebhookIdList = alertWebhookList.stream()
178+
.map(AlarmWebhook::getId).collect(Collectors.toList());
179+
if (!alertWebhookIdList.contains(alertSubscribe.getGroupId())) {
180+
AlarmWebhook alertWebhook =
181+
alarmWebhookDOMapper.selectById(alertSubscribe.getGroupId());
182+
if (alertWebhook != null) {
183+
alertWebhookList.add(alertWebhook);
184+
}
185+
}
186+
if (!CollectionUtils.isEmpty(alertWebhookList)) {
187+
for (AlarmWebhook webhook : alertWebhookList) {
188+
if (webhook != null && webhook.getStatus().equals((byte) 1)) {
189+
webhookInfos.add(DoConvert.alertWebhookDoConverter(webhook));
190+
}
191+
}
179192
}
180193
LOGGER.info("{} webhookInfos is {}.", alertNotify.getTraceId(),
181194
J.toJson(webhookInfos));
@@ -230,6 +243,16 @@ public void handle(List<AlertNotify> alertNotifies) {
230243
}
231244
}
232245

246+
public List<AlarmWebhook> getAllAlertWebHook(String tenant) {
247+
QueryWrapper<AlarmWebhook> wrapper = new QueryWrapper<>();
248+
if (StringUtils.isNotBlank(tenant)) {
249+
wrapper.eq("tenant", tenant);
250+
}
251+
wrapper.eq("type", 1);
252+
List<AlarmWebhook> alarmWebhookList = alarmWebhookDOMapper.selectList(wrapper);
253+
return alarmWebhookList;
254+
}
255+
233256
private boolean keepSilence(boolean notifyRecover, AlertSilenceConfig alertSilenceConfig,
234257
Long alarmTime) {
235258
if (notifyRecover) {

server/home/home-dal/src/main/java/io/holoinsight/server/home/dal/model/CustomPlugin.java

+8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ public class CustomPlugin {
3030

3131
public String sampleLog;
3232

33+
public Boolean alarmed;
34+
35+
public Integer recentAlarm;
36+
37+
public Long alarmRrdTime;
38+
39+
public String recentAlarmHistoryId;
40+
3341
public String creator;
3442

3543
public String modifier;

server/home/home-dal/src/main/java/io/holoinsight/server/home/dal/model/dto/CustomPluginDTO.java

+8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ public class CustomPluginDTO {
4040

4141
public String sampleLog;
4242

43+
public Boolean alarmed;
44+
45+
public Integer recentAlarm;
46+
47+
public Long alarmRrdTime;
48+
49+
public String recentAlarmHistoryId;
50+
4351
public String creator;
4452

4553
public String modifier;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0.
3+
*/
4+
package io.holoinsight.server.home.task;
5+
6+
import io.holoinsight.server.common.model.CLUSTER_ROLE_CONST;
7+
import io.holoinsight.server.common.service.AlarmHistoryDetailService;
8+
import io.holoinsight.server.common.service.AlarmMetricService;
9+
import io.holoinsight.server.common.service.FolderService;
10+
import io.holoinsight.server.common.service.MetricInfoService;
11+
import io.holoinsight.server.home.biz.service.CustomPluginService;
12+
import org.springframework.beans.factory.annotation.Autowired;
13+
import org.springframework.stereotype.Service;
14+
15+
import java.util.ArrayList;
16+
import java.util.List;
17+
18+
/**
19+
* @author limengyang
20+
* @version MonitorAlarmRrdTask.java, v 0.1 2024年09月19日 15:41 limengyang
21+
*/
22+
@Service
23+
@TaskHandler(code = "MONITOR_ALARM_RRD")
24+
public class MonitorAlarmRrdTask extends AbstractMonitorTask {
25+
26+
public final static String TASK_ID = "MONITOR_ALARM_RRD";
27+
28+
public final static Long PERIOD = 5 * MINUTE;
29+
30+
@Autowired
31+
private AlarmHistoryDetailService alarmHistoryDetailService;
32+
33+
@Autowired
34+
private CustomPluginService customPluginService;
35+
36+
@Autowired
37+
private FolderService folderService;
38+
39+
@Autowired
40+
private MetricInfoService metricInfoService;
41+
42+
@Autowired
43+
private AlarmMetricService alarmMetricService;
44+
45+
46+
public MonitorAlarmRrdTask() {
47+
super(1, 10, "MONITOR_ALARM_RRD");
48+
}
49+
50+
@Override
51+
public long getTaskPeriod() {
52+
return PERIOD;
53+
}
54+
55+
@Override
56+
public boolean needRun() {
57+
return true;
58+
}
59+
60+
@Override
61+
public List<MonitorTaskJob> buildJobs(long period) {
62+
List<MonitorTaskJob> jobs = new ArrayList<>();
63+
jobs.add(new MonitorAlarmRrdTaskJob(period, alarmHistoryDetailService, customPluginService,
64+
metricInfoService, alarmMetricService, folderService));
65+
return jobs;
66+
}
67+
68+
public String getRole() {
69+
// 代表执行本任务的具体Role
70+
return CLUSTER_ROLE_CONST.META;
71+
}
72+
73+
}

0 commit comments

Comments
 (0)