Merge remote-tracking branch 'origin/station' into mdc
This commit is contained in:
commit
21c14e7aa5
|
@ -2,6 +2,10 @@ package org.jeecg.common.constant;
|
|||
|
||||
public interface MonitorConstant {
|
||||
|
||||
Integer pageNo = 1;
|
||||
|
||||
Integer pageSize = 99;
|
||||
|
||||
// 监控项名称
|
||||
String ITEM_CPUUSED = "cpuUtilization";
|
||||
String ITEM_SWAPUSED = "swapUtilization";
|
||||
|
|
|
@ -60,7 +60,6 @@ public class JDBCUtil {
|
|||
try (Connection connection = dataSource.getConnection()) {
|
||||
return new ConnR().setConn(true);
|
||||
} catch (SQLException e) {
|
||||
// String message = String.format("[xxx数据源]连接失败: %s", e.getMessage());
|
||||
return new ConnR().setInfo(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package org.jeecg.common.util;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ParamUtil {
|
||||
|
||||
public static Map<String, Object> set(Object... value){
|
||||
Map<String, Object> data = MapUtil.newHashMap();
|
||||
if (ArrayUtil.isEmpty(value))
|
||||
return data;
|
||||
for (int i = 0; i < value.length; i++) {
|
||||
data.put("param" + (i + 1), value[i]);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package org.jeecg.modules.base.entity.monitor;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Servers implements Serializable {
|
||||
|
||||
private List<Host> records;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package org.jeecg.modules.base.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum Template {
|
||||
IDC_DATASOURCE_STATUS("IDC_Datasource_Status");
|
||||
|
||||
private final String code;
|
||||
}
|
|
@ -1,14 +1,19 @@
|
|||
package org.jeecg.modules.aspect;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.netease.qiye.qiyeopenplatform.sdk.QiyeOpenPlatSDK;
|
||||
import feign.FeignException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.constant.MonitorConstant;
|
||||
import org.jeecg.common.constant.RedisConstant;
|
||||
import org.jeecg.common.constant.SymbolConstant;
|
||||
|
@ -17,7 +22,8 @@ import org.jeecg.common.util.JDBCUtil;
|
|||
import org.jeecg.common.util.RedisUtil;
|
||||
import org.jeecg.modules.base.dto.NameValue;
|
||||
import org.jeecg.modules.base.entity.monitor.Host;
|
||||
import org.jeecg.modules.base.entity.monitor.Servers;
|
||||
import org.jeecg.modules.base.entity.monitor.Item;
|
||||
import org.jeecg.modules.base.entity.postgre.AlarmItem;
|
||||
import org.jeecg.modules.base.entity.postgre.SysDatabase;
|
||||
import org.jeecg.modules.base.entity.postgre.SysEmail;
|
||||
import org.jeecg.modules.base.entity.postgre.SysServer;
|
||||
|
@ -28,15 +34,15 @@ import org.jeecg.modules.qiyeEmail.base.InstanceSDK;
|
|||
import org.jeecg.modules.qiyeEmail.base.RParam;
|
||||
import org.jeecg.modules.qiyeEmail.base.dto.AccountInfo;
|
||||
import org.jeecg.modules.qiyeEmail.service.Account;
|
||||
import org.jeecg.modules.service.IAlarmRuleService;
|
||||
import org.jeecg.modules.service.ISysDatabaseService;
|
||||
import org.jeecg.modules.service.ISysEmailService;
|
||||
import org.jeecg.modules.service.ISysServerService;
|
||||
import org.jeecg.modules.service.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jeecg.modules.base.enums.Qiye.IS;
|
||||
|
@ -64,6 +70,9 @@ public class StatusAspect {
|
|||
@Autowired
|
||||
private IAlarmRuleService alarmRuleService;
|
||||
|
||||
@Autowired
|
||||
private IAlarmItemService alarmItemService;
|
||||
|
||||
// 新增|修改邮箱服务器信息后 异步更新其状态信息
|
||||
@Async
|
||||
@AfterReturning("execution(* org.jeecg.modules.service.impl.SysEmailServiceImpl.update(..)) || " +
|
||||
|
@ -106,20 +115,43 @@ public class StatusAspect {
|
|||
String ipAddress = server.getIpAddress();
|
||||
try {
|
||||
String token = ManageUtil.getToken();
|
||||
Servers servers = monitorAlarm.listApp(ipAddress, MonitorConstant.SERVER_APP, token).getResult();
|
||||
// 获取所有监控主机信息
|
||||
List<Host> hosts = servers.getRecords();
|
||||
for (Host host : hosts) {
|
||||
String code = host.getCode();
|
||||
if (!StrUtil.equals(ipAddress, code))
|
||||
continue;
|
||||
server.setHostId(host.getHostId());
|
||||
status = host.getStatus();
|
||||
Page<Host> hostPage = monitorAlarm.listApp(ipAddress, MonitorConstant.SERVER_APP,
|
||||
MonitorConstant.pageNo, MonitorConstant.pageSize, token).getResult();
|
||||
if (ObjectUtil.isNull(hostPage) || CollUtil.isEmpty(hostPage.getRecords())){
|
||||
redisUtil.hset(key, id, new NameValue(name, status));
|
||||
return;
|
||||
}
|
||||
List<Host> hosts = hostPage.getRecords();
|
||||
Host host = null;
|
||||
for (Host oneHost : hosts) {
|
||||
String code = oneHost.getCode();
|
||||
if (StrUtil.equals(ipAddress, code))
|
||||
host = oneHost;
|
||||
}
|
||||
if (ObjectUtil.isNull(host)){
|
||||
redisUtil.hset(key, id, new NameValue(name, status));
|
||||
return;
|
||||
}
|
||||
status = host.getStatus();
|
||||
String hostId = host.getHostId();
|
||||
server.setHostId(hostId);
|
||||
// 更新该服务器状态信息
|
||||
redisUtil.hset(key, id, new NameValue(name, status));
|
||||
// 更新该服务器的HostId
|
||||
serverService.updateById(server);
|
||||
// 同步服务器监控项
|
||||
Page<Item> itemPage = monitorAlarm.allItems(hostId,
|
||||
MonitorConstant.pageNo, MonitorConstant.pageSize, token).getResult();
|
||||
if (ObjectUtil.isNull(itemPage) || CollUtil.isEmpty(itemPage.getRecords()))
|
||||
return;
|
||||
List<Item> items = itemPage.getRecords();
|
||||
List<AlarmItem> alarmItems = new ArrayList<>();
|
||||
items.forEach(item -> {
|
||||
AlarmItem alarmItem = BeanUtil.copyProperties(item, AlarmItem.class);
|
||||
alarmItem.setId(item.getItemId());
|
||||
alarmItems.add(alarmItem);
|
||||
});
|
||||
alarmItemService.saveOrUpdateBatch(alarmItems);
|
||||
}catch (FeignException.Unauthorized e){
|
||||
ManageUtil.refreshToken();
|
||||
log.warn("向运管系统查询Hosts信息异常: Token失效,已刷新Token");
|
||||
|
@ -129,15 +161,32 @@ public class StatusAspect {
|
|||
}
|
||||
|
||||
/*
|
||||
* 删除Email|Database|Server时 同步删除Redis和数据库中相关联的预警规则
|
||||
* */
|
||||
* Server时 同步删除数据库中相关联的监控项&报警规则
|
||||
* */
|
||||
@Async
|
||||
@AfterReturning("execution(* org.jeecg.modules.service.impl.SysServerServiceImpl.deleteById(..)) ||" +
|
||||
"execution(* org.jeecg.modules.service.impl.SysEmailServiceImpl.deleteById(..)) || " +
|
||||
"execution(* org.jeecg.modules.service.impl.SysDatabaseServiceImpl.deleteById(..))")
|
||||
public void deleteRules(JoinPoint point){
|
||||
@AfterReturning(value = "execution(* org.jeecg.modules.service.impl.SysServerServiceImpl.deleteById(..))", returning = "result")
|
||||
public void deleteItems(JoinPoint point, Object result){
|
||||
if (ObjectUtil.isNotNull(result)){
|
||||
String hostId = ((Result<String>) result).getResult();
|
||||
// 删除服务器相关联的监控项
|
||||
alarmItemService.deleteByHostId(hostId);
|
||||
}
|
||||
// 删除服务器相关联的报警规则
|
||||
Object[] args = point.getArgs();
|
||||
if (ArrayUtil.length(args) > 0)
|
||||
alarmRuleService.deleteBySourceId((String) args[0]);
|
||||
}
|
||||
|
||||
/*
|
||||
* 删除Email|Database时 同步删除Redis和数据库中相关联的预警规则
|
||||
* */
|
||||
@Async
|
||||
@AfterReturning("execution(* org.jeecg.modules.service.impl.SysEmailServiceImpl.deleteById(..)) || " +
|
||||
"execution(* org.jeecg.modules.service.impl.SysDatabaseServiceImpl.deleteById(..))")
|
||||
public void deleteRules(JoinPoint point){
|
||||
Object[] args = point.getArgs();
|
||||
// 删除数据库和邮箱相关联的报警规则
|
||||
if (ArrayUtil.length(args) > 0)
|
||||
alarmRuleService.deleteBySourceId((String) args[0]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
package org.jeecg.modules.feignclient;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import kotlin.reflect.jvm.internal.impl.descriptors.Visibilities;
|
||||
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.Item;
|
||||
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.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@FeignClient(name = "monitorAlarm", url = "${monitor.url}")
|
||||
public interface MonitorAlarm {
|
||||
|
@ -20,18 +24,30 @@ public interface MonitorAlarm {
|
|||
|
||||
// --------------------后端专用-------------------
|
||||
@GetMapping("/omms/device/monitor/list") // 获取所有 服务器/数据库服务 信息
|
||||
Result<Servers> listApp(@RequestParam("type") String type,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
Result<Page<Host>> listApp(@RequestParam("type") String type,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
|
||||
@GetMapping("/omms/device/monitor/list") // 获取所有 服务器/数据库服务 信息
|
||||
Result<Servers> listApp(@RequestParam("code") String code,
|
||||
@RequestParam("type") String type,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
Result<Page<Host>> listApp(@RequestParam("code") String code,
|
||||
@RequestParam("type") String type,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
|
||||
@GetMapping("/omms/device/monitor/list") // 获取所有在线 服务器/数据库服务 信息
|
||||
Result<Servers> listOnApp(@RequestParam("status") String status,
|
||||
@RequestParam("type") String type,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
Result<Page<Host>> listOnApp(@RequestParam("status") String status,
|
||||
@RequestParam("type") String type,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
|
||||
@GetMapping("/omms/device/monitor/queryAllItems")
|
||||
Result<Page<Item>> allItems(@RequestParam("hostId") String hostId,
|
||||
@RequestParam("pageNo") Integer pageNo,
|
||||
@RequestParam("pageSize") Integer pageSize,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
|
||||
@GetMapping("/omms/device/monitor/queryHostDetails") // 获取服务器摘要信息
|
||||
Result<Host> summary(@RequestParam("hostId") String hostId,
|
||||
|
@ -98,9 +114,10 @@ public interface MonitorAlarm {
|
|||
@RequestParam String status,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
|
||||
// 数据库相关
|
||||
// -------------------------------------------数据库相关-----------------------------------------------------
|
||||
@GetMapping("/omms/monitor/db/item/detail")
|
||||
Result<?> dbDetail(@RequestHeader("X-Access-Token") String token);
|
||||
Result<?> dbDetail(@RequestParam("hostId") String hostId,
|
||||
@RequestHeader("X-Access-Token") String token);
|
||||
|
||||
@GetMapping("/omms/monitor/db/list")
|
||||
Result<?> dbList(@RequestHeader("X-Access-Token") String token);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.jeecg.modules.idc;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -7,6 +8,7 @@ import org.jeecg.common.api.dto.message.MessageDTO;
|
|||
import org.jeecg.common.config.mqtoken.UserTokenContext;
|
||||
import org.jeecg.common.constant.enums.MessageTypeEnum;
|
||||
import org.jeecg.common.util.JDBCUtil;
|
||||
import org.jeecg.common.util.ParamUtil;
|
||||
import org.jeecg.modules.base.dto.ConnR;
|
||||
import org.jeecg.modules.feignclient.SystemClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -22,6 +24,7 @@ import java.util.Map;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.jeecg.common.util.TokenUtils.getTempToken;
|
||||
import static org.jeecg.modules.base.enums.Template.IDC_DATASOURCE_STATUS;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
|
@ -52,7 +55,7 @@ public class IDCDataFetch {
|
|||
@Scheduled(fixedDelayString = "${request-interval}", timeUnit = TimeUnit.SECONDS)
|
||||
public void fetch() {
|
||||
JdbcTemplate template;
|
||||
MessageDTO messageDTO = new MessageDTO("IDC数据源异常", "IDC_Datasource_Status", "admin");
|
||||
MessageDTO messageDTO = new MessageDTO(null, IDC_DATASOURCE_STATUS.getCode(), "admin");
|
||||
messageDTO.setType(MessageTypeEnum.XT.getType());
|
||||
ConnR connR = JDBCUtil.isConnection(urlM, usernameM, passwordM);
|
||||
if (connR.isConn()) {
|
||||
|
@ -69,11 +72,9 @@ public class IDCDataFetch {
|
|||
// 对发送警告消息时可能出现的异常进行捕获(503) 防止影响后续代码执行
|
||||
try {
|
||||
// 给管理员发送预警信息
|
||||
/*String message = StrUtil.replace(connR.getInfo(), "xxx", "inland");
|
||||
messageDTO.setContent(message);*/
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("datasource", "inland(测试)");
|
||||
data.put("info", connR.getInfo());
|
||||
data.put("param1", "inland");
|
||||
data.put("param2", connR.getInfo());
|
||||
messageDTO.setData(data);
|
||||
systemClient.sendTo(messageDTO);
|
||||
}catch (Exception e){
|
||||
|
@ -93,8 +94,8 @@ public class IDCDataFetch {
|
|||
}
|
||||
try {
|
||||
// 给管理员发送预警信息
|
||||
String message = StrUtil.replace(connR.getInfo(), "xxx", "oversea");
|
||||
messageDTO.setContent(message);
|
||||
Map<String, Object> data = ParamUtil.set("oversea", connR.getInfo());
|
||||
messageDTO.setData(data);
|
||||
systemClient.sendTo(messageDTO);
|
||||
}catch (Exception e){
|
||||
log.error("发送oversea数据源异常信息失败: {}", e.getMessage());
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.jeecg.modules.mapper.AlarmItemMapper">
|
||||
|
||||
<select id="alarmItems" resultType="org.jeecg.modules.base.entity.postgre.AlarmItem">
|
||||
SELECT
|
||||
i.*
|
||||
|
|
|
@ -10,6 +10,8 @@ import java.util.List;
|
|||
public interface IAlarmItemService extends IService<AlarmItem> {
|
||||
boolean syncServerItem();
|
||||
|
||||
void deleteByHostId(String serverId);
|
||||
|
||||
List<AlarmItem> alarmItems(String sourceId);
|
||||
|
||||
List<ItemDto> allItems(String sourceType, String sourceId);
|
||||
|
|
|
@ -18,7 +18,6 @@ import org.jeecg.common.util.SpringContextUtils;
|
|||
import org.jeecg.modules.base.dto.ItemDto;
|
||||
import org.jeecg.modules.base.entity.monitor.Host;
|
||||
import org.jeecg.modules.base.entity.monitor.Item;
|
||||
import org.jeecg.modules.base.entity.monitor.Servers;
|
||||
import org.jeecg.modules.base.entity.postgre.AlarmItem;
|
||||
import org.jeecg.modules.base.entity.postgre.AlarmItemDe;
|
||||
import org.jeecg.modules.base.entity.postgre.SysServer;
|
||||
|
@ -55,50 +54,13 @@ public class AlarmItemServiceImpl extends ServiceImpl<AlarmItemMapper, AlarmItem
|
|||
@Autowired
|
||||
private IAlarmItemDeService alarmItemDeService;
|
||||
|
||||
/**
|
||||
* 同步所有服务器监控项信息
|
||||
*/
|
||||
/*@Transactional
|
||||
public boolean syncServerItem() {
|
||||
try {
|
||||
// 获取所有服务器信息(不包括数据库服务)
|
||||
List<Host> hosts = monitorAlarm.listApp(MonitorConstant.SERVER_APP).getResult().getRecords();
|
||||
// 获取所有服务器信息
|
||||
List<SysServer> servers = serverService.list();
|
||||
for (SysServer server : servers) {
|
||||
String ipAddress = server.getIpAddress();
|
||||
String serverId = server.getId();
|
||||
// 批量保存服务器对应的监控项信息
|
||||
for (Host host : hosts) {
|
||||
String code = host.getCode();
|
||||
if (!StrUtil.equals(ipAddress, code))
|
||||
continue;
|
||||
server.setHostId(host.getHostId());
|
||||
List<Item> items = ListUtil.toList(host.getItems().values());
|
||||
List<AlarmItem> alarmItems = new ArrayList<>();
|
||||
for (Item item : items) {
|
||||
AlarmItem alarmItem = BeanUtil.copyProperties(item, AlarmItem.class);
|
||||
alarmItem.setId(item.getItemId());
|
||||
alarmItem.setSourceId(serverId);
|
||||
alarmItems.add(alarmItem);
|
||||
}
|
||||
saveOrUpdateBatch(alarmItems);
|
||||
}
|
||||
}
|
||||
// 添加或更新SysServer的HostId
|
||||
return serverService.updateBatchById(servers);
|
||||
}catch (Exception e){
|
||||
log.error("向运管系统同步Server监控项信息异常: {}", e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
|
||||
@Transactional
|
||||
public boolean syncServerItem() {
|
||||
try {
|
||||
// 获取所有监控服务器信息(不包括数据库服务)
|
||||
String token = ManageUtil.getToken();
|
||||
List<Host> hosts = monitorAlarm.listApp(MonitorConstant.SERVER_APP, token).getResult().getRecords();
|
||||
List<Host> hosts = monitorAlarm.listApp(MonitorConstant.SERVER_APP,
|
||||
MonitorConstant.pageNo, MonitorConstant.pageSize, token).getResult().getRecords();
|
||||
// 获取所有服务器信息
|
||||
List<SysServer> servers = serverService.list();
|
||||
List<String> hostIds = servers.stream().map(SysServer::getHostId).filter(StrUtil::isNotBlank)
|
||||
|
@ -124,6 +86,13 @@ public class AlarmItemServiceImpl extends ServiceImpl<AlarmItemMapper, AlarmItem
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByHostId(String hostId) {
|
||||
LambdaQueryWrapper<AlarmItem> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(AlarmItem::getHostId, hostId);
|
||||
remove(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sourceId
|
||||
*
|
||||
|
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
@ -26,7 +27,6 @@ import org.jeecg.common.util.SpringContextUtils;
|
|||
import org.jeecg.modules.base.dto.*;
|
||||
import org.jeecg.modules.base.entity.monitor.Host;
|
||||
import org.jeecg.modules.base.entity.monitor.Item;
|
||||
import org.jeecg.modules.base.entity.monitor.Servers;
|
||||
import org.jeecg.modules.base.entity.postgre.SysServer;
|
||||
import org.jeecg.modules.base.bizVo.SourceVo;
|
||||
import org.jeecg.modules.base.enums.ServerStatus;
|
||||
|
@ -77,8 +77,8 @@ 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, token).getResult().getRecords();
|
||||
hosts = monitorAlarm.listOnApp(ServerStatus.ON.getValue(), MonitorConstant.SERVER_APP,
|
||||
MonitorConstant.pageNo, MonitorConstant.pageSize, token).getResult().getRecords();
|
||||
}catch (FeignException.Unauthorized e){
|
||||
ManageUtil.refreshToken();
|
||||
log.warn("向运管系统查询Hosts信息异常: Token失效,已刷新Token");
|
||||
|
@ -89,6 +89,7 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|||
Map<String, Host> hostMap = hosts.stream().collect(Collectors.toMap(Host::getHostId, Host -> Host));
|
||||
// 获取服务器状态信息
|
||||
Map<Object, Object> statusMap = redisUtil.hmget(RedisConstant.SERVER_STATUS);
|
||||
statusMap = MapUtil.isEmpty(statusMap) ? MapUtil.newHashMap() : statusMap;
|
||||
for (ServerDto serverDto : serverDtos) {
|
||||
int alarms = serverDto.getAlarms();
|
||||
String id = serverDto.getId();
|
||||
|
@ -185,10 +186,13 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|||
@Override
|
||||
@Transactional
|
||||
public Result<?> deleteById(String id) {
|
||||
String hostId = null;
|
||||
SysServer server = getById(id);
|
||||
boolean success = removeById(id);
|
||||
if(success) {
|
||||
delStatus(id);
|
||||
return Result.OK(Prompt.DELETE_SUCC);
|
||||
hostId = ObjectUtil.isNotNull(server) ? server.getHostId() : hostId;
|
||||
return Result.OK(Prompt.DELETE_SUCC, hostId);
|
||||
}
|
||||
return Result.error(Prompt.DELETE_ERR);
|
||||
}
|
||||
|
@ -261,6 +265,7 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|||
// 服务器是否在线
|
||||
String status = host.getStatus();
|
||||
boolean online = StrUtil.equals(status, ServerStatus.ON.getValue());
|
||||
|
||||
Map<String, Item> items = host.getItems();
|
||||
Item empty;
|
||||
empty = items.get(MonitorConstant.ITEM_RUNTIME);
|
||||
|
@ -352,7 +357,8 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|||
Map<String, Object> values = new HashMap<>();
|
||||
try {
|
||||
String token = ManageUtil.getToken();
|
||||
List<Host> hosts = monitorAlarm.listApp(MonitorConstant.SERVER_APP, token).getResult().getRecords();
|
||||
List<Host> hosts = monitorAlarm.listApp(MonitorConstant.SERVER_APP,
|
||||
MonitorConstant.pageNo, MonitorConstant.pageSize, token).getResult().getRecords();
|
||||
Map<String, Host> hostMap = hosts.stream().collect(Collectors.toMap(Host::getHostId, Host -> Host));
|
||||
for (SysServer server : sysServers) {
|
||||
String hostId = server.getHostId();
|
||||
|
|
|
@ -1234,18 +1234,23 @@ public class SysBaseApiImpl implements ISysBaseAPI {
|
|||
|
||||
public void sendTemplateMessage(MessageDTO message) {
|
||||
String type = message.getType();
|
||||
String title = message.getTitle();
|
||||
String code = message.getTemplateCode();
|
||||
if(StrUtil.isNotBlank(code)){
|
||||
SysMessageTemplate template = getTemplateEntity(code);
|
||||
String content = template.getTemplateContent();
|
||||
Map<String, Object> data = message.getData();
|
||||
boolean notBlank = StrUtil.isNotBlank(content);
|
||||
boolean notEmpty = ObjectUtil.isNotEmpty(data);
|
||||
if(notBlank && notEmpty){
|
||||
content = FreemarkerParseFactory
|
||||
.parseTemplateContent(content, data, false);
|
||||
if(ObjectUtil.isNotNull(template)){
|
||||
String name = template.getTemplateName();
|
||||
String content = template.getTemplateContent();
|
||||
title = StrUtil.isNotBlank(title) ? title : name;
|
||||
Map<String, Object> data = message.getData();
|
||||
boolean notBlank = StrUtil.isNotBlank(content);
|
||||
boolean notEmpty = ObjectUtil.isNotEmpty(data);
|
||||
if(notBlank && notEmpty){
|
||||
content = FreemarkerParseFactory
|
||||
.parseTemplateContent(content, data, false);
|
||||
}
|
||||
message.setTitle(title).setContent(content);
|
||||
}
|
||||
message.setContent(content);
|
||||
}
|
||||
if(XT.getType().equals(type)){ // 站内消息
|
||||
systemSendMsgHandle.sendMessage(message);
|
||||
|
|
Loading…
Reference in New Issue
Block a user