feat:运管监控服务调用
This commit is contained in:
parent
754d55faae
commit
cb7449fcd6
|
@ -34,4 +34,6 @@ public interface RedisConstant {
|
|||
String SERVER_STATUS = "Status:Server_Status";
|
||||
|
||||
String EMAIL_SENDER = "Email_Sender";
|
||||
|
||||
String MANAGE_TOKEN = "Manage:Token";
|
||||
}
|
||||
|
|
|
@ -11,19 +11,4 @@ public class AnalysisLogDto extends AlarmAnalysisLog {
|
|||
private String stationCode;
|
||||
|
||||
private List<NuclideInfo> nuclideList;
|
||||
|
||||
/* 以下属性作废 */
|
||||
// TODO del
|
||||
|
||||
private String name; // 规则名称
|
||||
|
||||
private String source; // 当前规则关注的数据源(逗号分隔)
|
||||
|
||||
private List<String> sourceList;
|
||||
|
||||
private String stations; // 当前规则关注的台站(逗号分隔)
|
||||
|
||||
private List<String> stationList;
|
||||
|
||||
private String nuclides; // 当前规则关注的核素(逗号分隔)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package org.jeecg.modules.base.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class LoginResult implements Serializable {
|
||||
|
||||
private String token;
|
||||
private Object userInfo;
|
||||
private Object departs;
|
||||
private Object multi_depart;
|
||||
private Object roles;
|
||||
private Object sysAllDictItems;
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.jeecg.modules.base.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class LoginVo implements Serializable {
|
||||
|
||||
private String captcha;
|
||||
private String checkKey;
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
public LoginVo(String username, String password) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package org.jeecg.modules.base.enums;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum Condition {
|
||||
FIRST_FOUND("1"), ABOVE_AVERAGE("2"), MEANWHILE("3");
|
||||
|
||||
private String value;
|
||||
|
||||
public static Condition valueOf1(String value){
|
||||
for (Condition condition : Condition.values()) {
|
||||
if (StrUtil.equals(condition.getValue(), value))
|
||||
return condition;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package org.jeecg.modules.controller;
|
|||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.modules.feignclient.ManageUtil;
|
||||
import org.jeecg.modules.feignclient.MonitorAlarm;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -23,7 +24,8 @@ public class SystemMonitorController {
|
|||
Result<?> list(String code, String hostId,
|
||||
Integer pageNo, Integer pageSize,
|
||||
String status, String type){
|
||||
return monitorAlarm.list(code, hostId, pageNo, pageSize, status, type);
|
||||
String token = ManageUtil.getToken();
|
||||
return monitorAlarm.list(code, hostId, pageNo, pageSize, status, type, token);
|
||||
}
|
||||
|
||||
@GetMapping("queryHostDetails")
|
||||
|
@ -32,7 +34,8 @@ public class SystemMonitorController {
|
|||
@RequestParam String pageName,
|
||||
Integer pageNo, Integer pageSize,
|
||||
String start, String end){
|
||||
return monitorAlarm.detail(hostId, pageName, pageNo, pageSize, start, end);
|
||||
String token = ManageUtil.getToken();
|
||||
return monitorAlarm.detail(hostId, pageName, pageNo, pageSize, start, end, token);
|
||||
}
|
||||
|
||||
@GetMapping("queryItemHistory")
|
||||
|
@ -41,7 +44,8 @@ public class SystemMonitorController {
|
|||
@RequestParam Integer itemType,
|
||||
@RequestParam String start,
|
||||
@RequestParam String end){
|
||||
return monitorAlarm.item(itemId, itemType, start, end);
|
||||
String token = ManageUtil.getToken();
|
||||
return monitorAlarm.item(itemId, itemType, start, end, token);
|
||||
}
|
||||
|
||||
@GetMapping("queryItemHistoryData")
|
||||
|
@ -50,6 +54,7 @@ public class SystemMonitorController {
|
|||
@RequestParam Integer itemType,
|
||||
@RequestParam String start,
|
||||
@RequestParam String end){
|
||||
return monitorAlarm.itemData(itemId, itemType, start, end);
|
||||
String token = ManageUtil.getToken();
|
||||
return monitorAlarm.itemData(itemId, itemType, start, end, token);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package org.jeecg.modules.feignclient;
|
||||
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.constant.RedisConstant;
|
||||
import org.jeecg.common.system.util.JwtUtil;
|
||||
import org.jeecg.common.util.RedisUtil;
|
||||
import org.jeecg.common.util.SpringContextUtils;
|
||||
import org.jeecg.modules.base.dto.LoginResult;
|
||||
import org.jeecg.modules.base.dto.LoginVo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Component;
|
||||
public class ManageUtil {
|
||||
|
||||
private static RedisUtil redisUtil;
|
||||
|
||||
private static MonitorAlarm monitorAlarm;
|
||||
|
||||
private static String username;
|
||||
|
||||
private static String password;
|
||||
|
||||
static {
|
||||
redisUtil = SpringContextUtils.getBean(RedisUtil.class);
|
||||
monitorAlarm = SpringContextUtils.getBean(MonitorAlarm.class);
|
||||
Environment env = SpringContextUtils.getBean(Environment.class);
|
||||
username = env.getProperty("monitor.username");
|
||||
password = env.getProperty("monitor.password");
|
||||
}
|
||||
|
||||
/*
|
||||
* 登录运管系统 获取Token
|
||||
* */
|
||||
public static String getToken(){
|
||||
if (redisUtil.hasKey(RedisConstant.MANAGE_TOKEN))
|
||||
return (String) redisUtil.get(RedisConstant.MANAGE_TOKEN);
|
||||
|
||||
LoginVo loginVo = new LoginVo(username, password);
|
||||
Result<LoginResult> loginRes = monitorAlarm.login(loginVo);
|
||||
String token = loginRes.getResult().getToken();
|
||||
redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME * 2 / 1000 - 10);
|
||||
return token;
|
||||
}
|
||||
}
|
|
@ -1,81 +1,102 @@
|
|||
package org.jeecg.modules.feignclient;
|
||||
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.modules.base.dto.LoginResult;
|
||||
import org.jeecg.modules.base.dto.LoginVo;
|
||||
import org.jeecg.modules.base.entity.monitor.Host;
|
||||
import org.jeecg.modules.base.entity.monitor.ItemHistory;
|
||||
import org.jeecg.modules.base.entity.monitor.Servers;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Component
|
||||
@FeignClient(name = "monitorAlarm",url = "${monitor.url}")
|
||||
@FeignClient(name = "monitorAlarm", url = "${monitor.url}")
|
||||
public interface MonitorAlarm {
|
||||
|
||||
// 系统登录
|
||||
@PostMapping("/sys/login")
|
||||
Result<LoginResult> login(@RequestBody LoginVo loginVo);
|
||||
|
||||
// --------------------后端专用-------------------
|
||||
@GetMapping("list") // 获取所有 服务器/数据库服务 信息
|
||||
Result<Servers> listApp(@RequestParam("type") String type);
|
||||
@GetMapping("/omms/device/monitor/list") // 获取所有 服务器/数据库服务 信息
|
||||
Result<Servers> listApp(@RequestParam("type") String type,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
|
||||
@GetMapping("list") // 获取所有在线 服务器/数据库服务 信息
|
||||
@GetMapping("/omms/device/monitor/list") // 获取所有在线 服务器/数据库服务 信息
|
||||
Result<Servers> listOnApp(@RequestParam("status") String status,
|
||||
@RequestParam("type") String type);
|
||||
@RequestParam("type") String type,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
|
||||
@GetMapping("queryHostDetails") // 获取服务器摘要信息
|
||||
@GetMapping("/omms/device/monitor/queryHostDetails") // 获取服务器摘要信息
|
||||
Result<Host> summary(@RequestParam("hostId") String hostId,
|
||||
@RequestParam("pageName") String pageName);
|
||||
@RequestParam("pageName") String pageName,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
|
||||
|
||||
@GetMapping("queryItemHistory")
|
||||
@GetMapping("/omms/device/monitor/queryItemHistory")
|
||||
Result<ItemHistory> itemBack(@RequestParam String itemId,
|
||||
@RequestParam Integer itemType,
|
||||
@RequestParam String start,
|
||||
@RequestParam String end);
|
||||
@RequestParam String end,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
|
||||
// --------------------前端专用-------------------
|
||||
@GetMapping("list")
|
||||
@GetMapping("/omms/device/monitor/list")
|
||||
Result<?> list(@RequestParam String code,
|
||||
@RequestParam String hostId,
|
||||
@RequestParam Integer pageNo,
|
||||
@RequestParam Integer pageSize,
|
||||
@RequestParam String status,
|
||||
@RequestParam String type);
|
||||
@RequestParam String type,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
|
||||
@GetMapping("queryHostDetails")
|
||||
@GetMapping("/omms/device/monitor/queryHostDetails")
|
||||
Result<?> detail(@RequestParam String hostId,
|
||||
@RequestParam String pageName,
|
||||
@RequestParam Integer pageNo,
|
||||
@RequestParam Integer pageSize,
|
||||
@RequestParam String start,
|
||||
@RequestParam String end);
|
||||
@RequestParam String end,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
|
||||
@GetMapping("queryItemHistory")
|
||||
@GetMapping("/omms/device/monitor/queryItemHistory")
|
||||
Result<?> item(@RequestParam String itemId,
|
||||
@RequestParam Integer itemType,
|
||||
@RequestParam String start,
|
||||
@RequestParam String end);
|
||||
@RequestParam String end,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
|
||||
@GetMapping("queryItemHistoryData")
|
||||
@GetMapping("/omms/device/monitor/queryItemHistoryData")
|
||||
Result<?> itemData(@RequestParam String itemId,
|
||||
@RequestParam Integer itemType,
|
||||
@RequestParam String start,
|
||||
@RequestParam String end);
|
||||
@RequestParam String end,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
|
||||
@GetMapping("log")
|
||||
@GetMapping("/omms/device/monitor/log")
|
||||
Result<?> log(@RequestParam String code,
|
||||
@RequestParam String deviceType,
|
||||
@RequestParam Integer pageNo,
|
||||
@RequestParam Integer pageSize,
|
||||
@RequestParam String start,
|
||||
@RequestParam String end,
|
||||
@RequestParam String status);
|
||||
@RequestParam String status,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
|
||||
@GetMapping("log/{hostId}")
|
||||
@GetMapping("/omms/device/monitor/log/{hostId}")
|
||||
Result<?> OneLog(@PathVariable("hostId") String hostId,
|
||||
@RequestParam Integer pageNo,
|
||||
@RequestParam Integer pageSize,
|
||||
@RequestParam String start,
|
||||
@RequestParam String end,
|
||||
@RequestParam String status);
|
||||
@RequestParam String status,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
|
||||
// 数据库相关
|
||||
@GetMapping("/omms/monitor/db/item/detail")
|
||||
Result<?> dbDetail(@RequestHeader("X-Access-Token") String token);
|
||||
|
||||
@GetMapping("/omms/monitor/db/list")
|
||||
Result<?> dbList(@RequestHeader("X-Access-Token") String token);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
|||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -20,6 +21,7 @@ import org.jeecg.modules.base.dto.Info;
|
|||
import org.jeecg.modules.base.entity.postgre.AlarmAnalysisLog;
|
||||
import org.jeecg.modules.base.entity.postgre.AlarmAnalysisNuclideAvg;
|
||||
import org.jeecg.modules.base.entity.postgre.AlarmAnalysisRule;
|
||||
import org.jeecg.modules.base.enums.Condition;
|
||||
import org.jeecg.modules.feignclient.SystemClient;
|
||||
import org.jeecg.modules.service.AnalysisResultService;
|
||||
import org.jeecg.modules.service.IAlarmAnalysisLogService;
|
||||
|
@ -83,7 +85,7 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
|
|||
// 消费完成后,手动确认消费消息[消息消费成功]
|
||||
// 否则就是消费抛出异常,进入pending_ids[消息消费失败]
|
||||
redisStreamUtil.ack(streamKey, groupName, recordId.getValue());
|
||||
// TODO 手动删除已消费消息
|
||||
// TODO del 取消手动删除已消费消息
|
||||
// redisStreamUtil.del(streamKey, recordId.getValue());
|
||||
}
|
||||
}catch (RuntimeException e){
|
||||
|
@ -139,7 +141,6 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
|
|||
}
|
||||
|
||||
private void judge(Info info, Map<String,String> nuclidesCross){
|
||||
String ONE = "1";String TWO = "2";String THREE = "3";
|
||||
Set<String> nuclideNames = nuclidesCross.keySet();
|
||||
StringBuilder alarmInfo = new StringBuilder();
|
||||
List<String> firstDetected;
|
||||
|
@ -149,13 +150,17 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
|
|||
String datasource = info.getDatasource();
|
||||
List<String> conditions = ListUtil.toList(conditionStr.split(comma));
|
||||
for (String con : conditions) {
|
||||
if (ONE.equals(con)){ // 首次发现该元素
|
||||
Condition condition = Condition.valueOf1(con);
|
||||
if (ObjectUtil.isNotNull(condition)){
|
||||
switch (condition){
|
||||
case FIRST_FOUND: // 首次发现该元素
|
||||
firstDetected = firstDetected(betaOrGamma,datasource,nuclideNames);
|
||||
if (CollUtil.isNotEmpty(firstDetected)){
|
||||
String message = "First discovery of nuclides: [" + StrUtil.join(comma,firstDetected) + "]";
|
||||
alarmInfo.append(message);
|
||||
}
|
||||
} else if (TWO.equals(con)) { // 元素浓度高于均值
|
||||
break;
|
||||
case ABOVE_AVERAGE: // 元素浓度高于均值
|
||||
moreThanAvg = moreThanAvg(datasource,nuclidesCross);
|
||||
if (CollUtil.isNotEmpty(moreThanAvg)){
|
||||
for (NuclideInfo nuclideInfo : moreThanAvg) {
|
||||
|
@ -165,11 +170,16 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
|
|||
alarmInfo.append(comma).append(message);
|
||||
}
|
||||
}
|
||||
} else if (THREE.equals(con)) { // 同时出现两种及以上核素
|
||||
break;
|
||||
case MEANWHILE: // 同时出现两种及以上核素
|
||||
if (nuclideNames.size() >= 2){
|
||||
String message = "Simultaneously detecting nuclides: [" + StrUtil.join(comma,nuclideNames) + "]";
|
||||
alarmInfo.append(comma).append(message);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(alarmInfo.toString())){
|
||||
|
@ -186,7 +196,7 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
|
|||
String groupId = info.getGroupId();
|
||||
if (StrUtil.isNotBlank(groupId))
|
||||
systemClient.sendMessage("Nuclide Analysis Warn Message",
|
||||
alarmInfo.toString(),groupId, ALL.getValue());
|
||||
alarmInfo.toString(), groupId, ALL.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,13 +66,9 @@ public class AlarmAnalysisLogServiceImpl extends ServiceImpl<AlarmAnalysisLogMap
|
|||
// 数据源
|
||||
String datasource = logDto.getDatasource();
|
||||
logDto.setDatasource(sourceMap.getOrDefault(datasource, "--"));
|
||||
// TODO del
|
||||
logDto.setSourceList(ListUtil.toList(sourceMap.getOrDefault(datasource, "--")));
|
||||
// 台站
|
||||
String stationId = logDto.getStationId();
|
||||
logDto.setStationCode(stationCodesMap.getOrDefault(stationId, "--"));
|
||||
// TODO del
|
||||
logDto.setStationList(ListUtil.toList(stationCodesMap.getOrDefault(stationId, "--")));
|
||||
// 将nuclide的json串转换为对象集合
|
||||
String nuclideInfo = logDto.getNuclideInfo();
|
||||
if (StrUtil.isNotBlank(nuclideInfo)){
|
||||
|
@ -81,7 +77,7 @@ public class AlarmAnalysisLogServiceImpl extends ServiceImpl<AlarmAnalysisLogMap
|
|||
List<NuclideInfo> nuclideInfos = mapper.readValue(nuclideInfo, new TypeReference<List<NuclideInfo>>() {});
|
||||
logDto.setNuclideList(nuclideInfos);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("nuclideInfo解析异常: {}", e.getMessage());
|
||||
log.error("NuclideInfo解析异常: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +96,7 @@ public class AlarmAnalysisLogServiceImpl extends ServiceImpl<AlarmAnalysisLogMap
|
|||
}
|
||||
return save(analysisLog);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
log.error("NuclideInfo解析异常: {}", e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.jeecg.modules.base.entity.postgre.AlarmItem;
|
|||
import org.jeecg.modules.base.entity.postgre.AlarmItemDe;
|
||||
import org.jeecg.modules.base.entity.postgre.SysServer;
|
||||
import org.jeecg.modules.base.enums.SourceType;
|
||||
import org.jeecg.modules.feignclient.ManageUtil;
|
||||
import org.jeecg.modules.feignclient.MonitorAlarm;
|
||||
import org.jeecg.modules.mapper.AlarmItemMapper;
|
||||
import org.jeecg.modules.service.IAlarmItemDeService;
|
||||
|
@ -95,7 +96,8 @@ public class AlarmItemServiceImpl extends ServiceImpl<AlarmItemMapper, AlarmItem
|
|||
public boolean syncServerItem() {
|
||||
try {
|
||||
// 获取所有监控服务器信息(不包括数据库服务)
|
||||
List<Host> hosts = monitorAlarm.listApp(MonitorConstant.SERVER_APP).getResult().getRecords();
|
||||
String token = ManageUtil.getToken();
|
||||
List<Host> hosts = monitorAlarm.listApp(MonitorConstant.SERVER_APP, token).getResult().getRecords();
|
||||
// 获取所有服务器信息
|
||||
List<SysServer> servers = serverService.list();
|
||||
List<String> hostIds = servers.stream().map(SysServer::getHostId).filter(StrUtil::isNotBlank)
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.jeecg.modules.base.entity.postgre.SysServer;
|
|||
import org.jeecg.modules.base.bizVo.SourceVo;
|
||||
import org.jeecg.modules.base.enums.ServerStatus;
|
||||
import org.jeecg.modules.entity.AlarmHistory;
|
||||
import org.jeecg.modules.feignclient.ManageUtil;
|
||||
import org.jeecg.modules.feignclient.MonitorAlarm;
|
||||
import org.jeecg.modules.mapper.SysServerMapper;
|
||||
import org.jeecg.modules.service.IAlarmRuleService;
|
||||
|
@ -74,8 +75,9 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|||
// 获取所有在线服务器信息
|
||||
List<Host> hosts = new ArrayList<>();
|
||||
try {
|
||||
String token = ManageUtil.getToken();
|
||||
hosts = monitorAlarm.listOnApp(ServerStatus.ON.getValue(),
|
||||
MonitorConstant.SERVER_APP).getResult().getRecords();
|
||||
MonitorConstant.SERVER_APP, token).getResult().getRecords();
|
||||
}catch (Exception e){
|
||||
log.error("向运管系统查询Hosts信息异常: {}", e.getMessage());
|
||||
}
|
||||
|
@ -244,7 +246,8 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|||
return Result.error("HostId" + Prompt.PARAM_REQUIRED);
|
||||
Host host = null;
|
||||
try {
|
||||
host = monitorAlarm.summary(hostId, MonitorConstant.PAGE_SUMMARY).getResult();
|
||||
String token = ManageUtil.getToken();
|
||||
host = monitorAlarm.summary(hostId, MonitorConstant.PAGE_SUMMARY, token).getResult();
|
||||
}catch (Exception e){
|
||||
log.error("向运管系统查询Host信息异常: {}", e.getMessage());
|
||||
}
|
||||
|
@ -315,7 +318,8 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|||
String key = RedisConstant.SERVER_STATUS;
|
||||
Map<String, Object> values = new HashMap<>();
|
||||
try {
|
||||
List<Host> hosts = monitorAlarm.listApp(MonitorConstant.SERVER_APP).getResult().getRecords();
|
||||
String token = ManageUtil.getToken();
|
||||
List<Host> hosts = monitorAlarm.listApp(MonitorConstant.SERVER_APP, token).getResult().getRecords();
|
||||
Map<String, Host> hostMap = hosts.stream().collect(Collectors.toMap(Host::getHostId, Host -> Host));
|
||||
for (SysServer server : sysServers) {
|
||||
String hostId = server.getHostId();
|
||||
|
@ -368,8 +372,9 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|||
String status = ServerStatus.UNKNOWN.getValue(); // 初始值为-1
|
||||
String name = server.getName();
|
||||
try {
|
||||
String token = ManageUtil.getToken();
|
||||
Servers servers = monitorAlarm.listApp(MonitorConstant.SERVER_APP, token).getResult();
|
||||
String ipAddress = server.getIpAddress();
|
||||
Servers servers = monitorAlarm.listApp(MonitorConstant.SERVER_APP).getResult();
|
||||
// 获取所有监控主机信息
|
||||
List<Host> hosts = servers.getRecords();
|
||||
for (Host host : hosts) {
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package org.jeecg.modules.feignclient;
|
||||
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.constant.RedisConstant;
|
||||
import org.jeecg.common.system.util.JwtUtil;
|
||||
import org.jeecg.common.util.RedisUtil;
|
||||
import org.jeecg.common.util.SpringContextUtils;
|
||||
import org.jeecg.modules.base.dto.LoginResult;
|
||||
import org.jeecg.modules.base.dto.LoginVo;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
public class ManageUtil {
|
||||
|
||||
private static RedisUtil redisUtil;
|
||||
|
||||
private static MonitorSystem monitorSystem;
|
||||
|
||||
private static String username;
|
||||
|
||||
private static String password;
|
||||
|
||||
static {
|
||||
redisUtil = SpringContextUtils.getBean(RedisUtil.class);
|
||||
monitorSystem = SpringContextUtils.getBean(MonitorSystem.class);
|
||||
Environment env = SpringContextUtils.getBean(Environment.class);
|
||||
username = env.getProperty("monitor.username");
|
||||
password = env.getProperty("monitor.password");
|
||||
}
|
||||
|
||||
/*
|
||||
* 登录运管系统 获取Token
|
||||
* */
|
||||
public static String getToken(){
|
||||
if (redisUtil.hasKey(RedisConstant.MANAGE_TOKEN))
|
||||
return (String) redisUtil.get(RedisConstant.MANAGE_TOKEN);
|
||||
|
||||
LoginVo loginVo = new LoginVo(username, password);
|
||||
Result<LoginResult> loginRes = monitorSystem.login(loginVo);
|
||||
String token = loginRes.getResult().getToken();
|
||||
redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME * 2 / 1000 - 10);
|
||||
return token;
|
||||
}
|
||||
}
|
|
@ -1,19 +1,25 @@
|
|||
package org.jeecg.modules.feignclient;
|
||||
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.modules.base.dto.LoginResult;
|
||||
import org.jeecg.modules.base.dto.LoginVo;
|
||||
import org.jeecg.modules.base.entity.monitor.ItemHistory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Component
|
||||
@FeignClient(name = "monitorSystem",url = "${monitor.url}")
|
||||
public interface MonitorSystem {
|
||||
|
||||
// 系统登录
|
||||
@PostMapping("/sys/login")
|
||||
Result<LoginResult> login(@RequestBody LoginVo loginVo);
|
||||
|
||||
@GetMapping("queryItemHistory")
|
||||
Result<ItemHistory> itemBack(@RequestParam String itemId,
|
||||
@RequestParam Integer itemType,
|
||||
@RequestParam String start,
|
||||
@RequestParam String end);
|
||||
@RequestParam String end,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ public class SendMessage {
|
|||
*/
|
||||
public void send(String title, String message, String groupId, String notific){
|
||||
// 封装MessageDTO消息体
|
||||
MessageDTO messageDTO = new MessageDTO(title,message);
|
||||
MessageDTO messageDTO = new MessageDTO(title, message);
|
||||
|
||||
Map<String, String> contact = getContact(groupId);
|
||||
if (StrUtil.isBlank(notific))return;
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.jeecg.modules.base.entity.monitor.ItemHistory;
|
|||
import org.jeecg.modules.base.entity.postgre.AlarmLog;
|
||||
import org.jeecg.modules.base.entity.postgre.AlarmRule;
|
||||
import org.jeecg.modules.feignclient.AbnormalAlarmClient;
|
||||
import org.jeecg.modules.feignclient.ManageUtil;
|
||||
import org.jeecg.modules.feignclient.MonitorSystem;
|
||||
import org.jeecg.modules.message.SendMessage;
|
||||
import org.jeecg.modules.quartz.entity.Monitor;
|
||||
|
@ -82,7 +83,8 @@ public class ServerJob extends Monitor implements Job {
|
|||
String serverName = getAlarmClient().getServerName(sourceId);
|
||||
|
||||
// 向运管查询监控项数据
|
||||
Result<ItemHistory> result = getMonitorSystem().itemBack(itemId, 0, start, end);
|
||||
String token = ManageUtil.getToken();
|
||||
Result<ItemHistory> result = getMonitorSystem().itemBack(itemId, 0, start, end, token);
|
||||
Double current = result.getResult().getNow();
|
||||
|
||||
// 解析预警规则,判断是否需要报警
|
||||
|
|
Loading…
Reference in New Issue
Block a user