优化交换机数据采集、脚本策略、agent更新优化、注册增加路由信息
This commit is contained in:
@@ -112,7 +112,7 @@ public interface RemoteRevenueConfigService
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/registration/innerupdateRegist")
|
||||
@PostMapping("/registration/innerUpdateRegist")
|
||||
public R<Integer> innerUpdateRegist(@RequestBody RmResourceRegistrationRemote rmResourceRegistrationRemote, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
}
|
||||
|
||||
@@ -86,4 +86,13 @@ public interface RemoteRocketMqService {
|
||||
*/
|
||||
@PostMapping("/monitorPolicy/updatePolicyMsgInner")
|
||||
public R<Integer> updatePolicyMsgInner(@RequestBody RmMonitorPolicyRemote rmMonitorPolicyRemote, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 下发优先级为0的策略
|
||||
* @param clientId
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/monitorPolicy/issueDefaultPolicyByClientId")
|
||||
public R<Integer> issueDefaultPolicyByClientId(String clientId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.ruoyi.system.api.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RouteMsg {
|
||||
/** 网卡名称 */
|
||||
private String name;
|
||||
/** 网关地址 */
|
||||
private String gateway;
|
||||
|
||||
}
|
||||
@@ -72,6 +72,11 @@ public class RemoteRocketMqFallbackFactory implements FallbackFactory<RemoteRock
|
||||
public R<Integer> updatePolicyMsgInner(RmMonitorPolicyRemote rmMonitorPolicyRemote, String source) {
|
||||
return R.fail(throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Integer> issueDefaultPolicyByClientId(String clientId, String source) {
|
||||
return R.fail(throwable.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ public class RmResourceRegistrationController extends BaseController
|
||||
@PostMapping("/bindBusinessPubulicIp")
|
||||
public AjaxResult bindBusinessPubulicIp(@RequestBody RmResourceRegistration rmResourceRegistration)
|
||||
{
|
||||
int rows = rmResourceRegistrationService.bindBusinessPubulicIp(rmResourceRegistration);
|
||||
int rows = rmResourceRegistrationService.bindBusinessPublicIp(rmResourceRegistration);
|
||||
return toAjax(rows);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ public class RmEpsTopologyManagement extends BaseEntity
|
||||
/** 交换机硬件SN */
|
||||
@Excel(name = "交换机硬件SN")
|
||||
private String switchSn;
|
||||
/** 交换机clientId */
|
||||
private String clientId;
|
||||
|
||||
/** 接口名称 */
|
||||
@Excel(name = "接口名称")
|
||||
|
||||
@@ -7,9 +7,11 @@ import java.time.Instant;
|
||||
@Data
|
||||
public class RspVo {
|
||||
/** 状态码,0、失败;1、成功*/
|
||||
private int resCode;
|
||||
private Integer resCode;
|
||||
/** 描述 */
|
||||
private String resMag;
|
||||
/** 路由 */
|
||||
private String addRoute;
|
||||
/** 时间戳 */
|
||||
private long timestamp = Instant.now().getEpochSecond();
|
||||
}
|
||||
|
||||
@@ -112,5 +112,5 @@ public interface IRmResourceRegistrationService
|
||||
* @param rmResourceRegistration
|
||||
* @return
|
||||
*/
|
||||
int bindBusinessPubulicIp(RmResourceRegistration rmResourceRegistration);
|
||||
int bindBusinessPublicIp(RmResourceRegistration rmResourceRegistration);
|
||||
}
|
||||
|
||||
@@ -9,10 +9,7 @@ import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.security.utils.SecurityUtils;
|
||||
import com.ruoyi.system.api.RemoteRocketMqService;
|
||||
import com.ruoyi.system.api.domain.NetworkInfo;
|
||||
import com.ruoyi.system.api.domain.RmNetworkInterfaceRemote;
|
||||
import com.ruoyi.system.api.domain.RmRegisterMsgRemote;
|
||||
import com.ruoyi.system.api.domain.RmResourceRegistrationRemote;
|
||||
import com.ruoyi.system.api.domain.*;
|
||||
import com.ruoyi.system.domain.*;
|
||||
import com.ruoyi.system.domain.vo.MessageVo;
|
||||
import com.ruoyi.system.domain.vo.ResourceVo;
|
||||
@@ -25,10 +22,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -530,6 +524,24 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
content.append("流量网口设置为").append(networkInfo.getName());
|
||||
recordAddData.setChangeContent(content.toString());
|
||||
epsMethodChangeRecordMapper.insertEpsMethodChangeRecord(recordAddData);
|
||||
// 设置路由信息
|
||||
RouteMsg routeMsg = new RouteMsg();
|
||||
routeMsg.setName(networkInfo.getName());
|
||||
routeMsg.setGateway(networkInfo.getGateway());
|
||||
// 构建注册应答信息
|
||||
MessageVo messageVo = new MessageVo();
|
||||
messageVo.setClientId(registerMsg.getClientId());
|
||||
messageVo.setDataType(MsgEnum.注册应答.getValue());
|
||||
RspVo rspVo = new RspVo();
|
||||
rspVo.setResCode(1);
|
||||
rspVo.setResMag("注册成功");
|
||||
rspVo.setAddRoute(JSONObject.toJSONString(routeMsg));
|
||||
messageVo.setData(JSONObject.toJSONString(rspVo));
|
||||
remoteRocketMqService.sendAsyncProducerMessage(
|
||||
"tr_agent_down", "", "regist_rsp", JSONObject.toJSONString(messageVo), SecurityConstants.INNER
|
||||
);
|
||||
// 第一次注册
|
||||
return 2;
|
||||
}else{
|
||||
insertData.setClientId(registerMsg.getClientId());
|
||||
insertData.setHardwareSn(registerMsg.getSn());
|
||||
@@ -539,32 +551,8 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
insertData.setCreateTime(createTime);
|
||||
rmResourceRegistrationMapper.insertRmResourceRegistration(insertData);
|
||||
}
|
||||
// 构建注册应答信息
|
||||
MessageVo messageVo = new MessageVo();
|
||||
messageVo.setClientId(registerMsg.getClientId());
|
||||
messageVo.setDataType(MsgEnum.注册应答.getValue());
|
||||
RspVo rspVo = new RspVo();
|
||||
rspVo.setResCode(1);
|
||||
rspVo.setResMag("注册成功");
|
||||
messageVo.setData(JSONObject.toJSONString(rspVo));
|
||||
remoteRocketMqService.sendAsyncProducerMessage(
|
||||
"tr_agent_down", "", "", JSONObject.toJSONString(messageVo), SecurityConstants.INNER
|
||||
);
|
||||
// 第一次注册
|
||||
return 2;
|
||||
}catch (Exception e){
|
||||
log.error("注册服务器失败:{}",e.getMessage());
|
||||
// 构建注册应答信息
|
||||
MessageVo messageVo = new MessageVo();
|
||||
messageVo.setClientId(registerMsg.getClientId());
|
||||
messageVo.setDataType(MsgEnum.注册应答.getValue());
|
||||
RspVo rspVo = new RspVo();
|
||||
rspVo.setResCode(1);
|
||||
rspVo.setResMag("平台错误信息:" + e.getMessage());
|
||||
messageVo.setData(JSONObject.toJSONString(rspVo));
|
||||
remoteRocketMqService.sendAsyncProducerMessage(
|
||||
"tr_agent_down", "", "", JSONObject.toJSONString(messageVo), SecurityConstants.INNER
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -601,34 +589,78 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
}
|
||||
|
||||
@Override
|
||||
public int bindBusinessPubulicIp(RmResourceRegistration rmResourceRegistration) {
|
||||
List<Map> bindMsgMap = rmResourceRegistration.getBindNetworkMsg();
|
||||
for (Map map : bindMsgMap) {
|
||||
// id
|
||||
Long id = (Long) map.get("id");
|
||||
String status = map.get("status").toString();
|
||||
String interfaceName = map.get("interfaceName").toString();
|
||||
// 绑定ip
|
||||
RmNetworkInterfaceRemote rmNetworkInterfaceRemote = new RmNetworkInterfaceRemote();
|
||||
rmNetworkInterfaceRemote.setId(id);
|
||||
rmNetworkInterfaceRemote.setBindIp(status);
|
||||
remoteRocketMqService.bindPublicIp(rmNetworkInterfaceRemote, SecurityConstants.INNER);
|
||||
// 添加业务变更记录
|
||||
EpsMethodChangeRecord recordAddData = new EpsMethodChangeRecord();
|
||||
recordAddData.setClientId(rmResourceRegistration.getClientId());
|
||||
recordAddData.setTrafficPort(interfaceName);
|
||||
recordAddData.setUpdateTime(DateUtils.getNowDate());
|
||||
recordAddData.setUpdateBy(SecurityUtils.getUsername());
|
||||
recordAddData.setCreatBy(SecurityUtils.getUsername());
|
||||
StringBuilder content = new StringBuilder();
|
||||
content.append("流量网口设置为").append(interfaceName);
|
||||
recordAddData.setChangeContent(content.toString());
|
||||
epsMethodChangeRecordMapper.insertEpsMethodChangeRecord(recordAddData);
|
||||
public int bindBusinessPublicIp(RmResourceRegistration rmResourceRegistration) {
|
||||
// 参数校验
|
||||
if (rmResourceRegistration == null || StringUtils.isEmpty(rmResourceRegistration.getClientId())) {
|
||||
throw new IllegalArgumentException("参数不合法");
|
||||
}
|
||||
// 修改多公网IP状态为已绑定
|
||||
|
||||
String clientId = rmResourceRegistration.getClientId();
|
||||
String username = SecurityUtils.getUsername();
|
||||
Date now = DateUtils.getNowDate();
|
||||
|
||||
// 1. 处理IP绑定和记录
|
||||
rmResourceRegistration.getBindNetworkMsg().forEach(map -> {
|
||||
// 绑定IP
|
||||
RmNetworkInterfaceRemote network = new RmNetworkInterfaceRemote();
|
||||
network.setId((Long) map.get("id"));
|
||||
network.setBindIp(map.get("status").toString());
|
||||
remoteRocketMqService.bindPublicIp(network, SecurityConstants.INNER);
|
||||
|
||||
// 添加变更记录
|
||||
EpsMethodChangeRecord record = new EpsMethodChangeRecord();
|
||||
record.setClientId(clientId);
|
||||
record.setTrafficPort(map.get("interfaceName").toString());
|
||||
record.setUpdateTime(now);
|
||||
record.setUpdateBy(username);
|
||||
record.setCreatBy(username);
|
||||
record.setChangeContent("流量网口设置为" + map.get("interfaceName"));
|
||||
epsMethodChangeRecordMapper.insertEpsMethodChangeRecord(record);
|
||||
});
|
||||
|
||||
// 2. 更新注册状态
|
||||
RmResourceRegistration updateData = new RmResourceRegistration();
|
||||
updateData.setId(rmResourceRegistration.getId());
|
||||
updateData.setMultiPublicIpStatus("1");
|
||||
|
||||
// 处理未注册情况
|
||||
RmResourceRegistration isRegist = rmResourceRegistrationMapper.selectRmResourceRegistrationById(rmResourceRegistration.getId());
|
||||
if (isRegist != null && "0".equals(isRegist.getRegistrationStatus())) {
|
||||
RmNetworkInterfaceRemote queryParam = new RmNetworkInterfaceRemote();
|
||||
queryParam.setClientId(clientId);
|
||||
|
||||
Optional.ofNullable(remoteRocketMqService.getNetworkInterfaceList(queryParam, SecurityConstants.INNER))
|
||||
.map(R::getData)
|
||||
.flatMap(list -> list.stream()
|
||||
.filter(ni -> "1".equals(ni.getBindIp()) || "3".equals(ni.getBindIp()))
|
||||
.findFirst())
|
||||
.ifPresent(network -> {
|
||||
updateData.setRegistrationStatus("1");
|
||||
|
||||
// 发送注册响应
|
||||
RouteMsg routeMsg = new RouteMsg();
|
||||
routeMsg.setName(network.getInterfaceName());
|
||||
routeMsg.setGateway(network.getGateway());
|
||||
|
||||
MessageVo messageVo = new MessageVo();
|
||||
messageVo.setClientId(clientId);
|
||||
messageVo.setDataType(MsgEnum.注册应答.getValue());
|
||||
|
||||
RspVo rspVo = new RspVo();
|
||||
rspVo.setResCode(1);
|
||||
rspVo.setResMag("注册成功");
|
||||
rspVo.setAddRoute(JSONObject.toJSONString(routeMsg));
|
||||
|
||||
messageVo.setData(JSONObject.toJSONString(rspVo));
|
||||
|
||||
remoteRocketMqService.sendAsyncProducerMessage(
|
||||
"tr_agent_down", "", "regist_rsp", JSONObject.toJSONString(messageVo), SecurityConstants.INNER
|
||||
);
|
||||
// 注册成功,下发优先级为0的策略
|
||||
remoteRocketMqService.issueDefaultPolicyByClientId(clientId, SecurityConstants.INNER);
|
||||
});
|
||||
}
|
||||
|
||||
rmResourceRegistrationMapper.updateRmResourceRegistration(updateData);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<resultMap type="RmEpsTopologyManagement" id="RmEpsTopologyManagementResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="switchName" column="switch_name" />
|
||||
<result property="clientId" column="client_Id" />
|
||||
<result property="switchSn" column="switch_sn" />
|
||||
<result property="interfaceName" column="interface_name" />
|
||||
<result property="connectedDeviceType" column="connected_device_type" />
|
||||
@@ -26,7 +27,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectRmEpsTopologyManagementVo">
|
||||
select id, switch_name, switch_sn, interface_name, connected_device_type, server_name, server_sn, server_port, create_time, update_time, creator_id, creator_name, updater_id, updater_name, switch_ip_address, peer_switch_name, peer_switch_interface, server_client_id from rm_eps_topology_management
|
||||
select id, switch_name, client_id, switch_sn, interface_name, connected_device_type, server_name, server_sn, server_port, create_time, update_time, creator_id, creator_name, updater_id, updater_name, switch_ip_address, peer_switch_name, peer_switch_interface, server_client_id from rm_eps_topology_management
|
||||
</sql>
|
||||
|
||||
<select id="selectRmEpsTopologyManagementList" parameterType="RmEpsTopologyManagement" resultMap="RmEpsTopologyManagementResult">
|
||||
@@ -48,6 +49,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="peerSwitchName != null and peerSwitchName != ''"> and peer_switch_name like concat('%', #{peerSwitchName}, '%')</if>
|
||||
<if test="peerSwitchInterface != null and peerSwitchInterface != ''"> and peer_switch_interface = #{peerSwitchInterface}</if>
|
||||
<if test="serverClientId != null and serverClientId != ''"> and server_client_id = #{serverClientId}</if>
|
||||
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
@@ -60,6 +62,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
insert into rm_eps_topology_management
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="switchName != null">switch_name,</if>
|
||||
<if test="clientId != null">client_id,</if>
|
||||
<if test="switchSn != null">switch_sn,</if>
|
||||
<if test="interfaceName != null">interface_name,</if>
|
||||
<if test="connectedDeviceType != null">connected_device_type,</if>
|
||||
@@ -79,6 +82,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="switchName != null">#{switchName},</if>
|
||||
<if test="clientId != null">#{clientId},</if>
|
||||
<if test="switchSn != null">#{switchSn},</if>
|
||||
<if test="interfaceName != null">#{interfaceName},</if>
|
||||
<if test="connectedDeviceType != null">#{connectedDeviceType},</if>
|
||||
@@ -102,6 +106,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
update rm_eps_topology_management
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="switchName != null">switch_name = #{switchName},</if>
|
||||
<if test="clientId != null">client_id = #{clientId},</if>
|
||||
<if test="switchSn != null">switch_sn = #{switchSn},</if>
|
||||
<if test="interfaceName != null">interface_name = #{interfaceName},</if>
|
||||
<if test="connectedDeviceType != null">connected_device_type = #{connectedDeviceType},</if>
|
||||
|
||||
@@ -187,5 +187,15 @@ public class RmMonitorPolicyController extends BaseController
|
||||
int rows = rmMonitorPolicyService.updatePolicyMsgInner(rmMonitorPolicy);
|
||||
return R.ok(rows);
|
||||
}
|
||||
/**
|
||||
* 修改资源监控策略
|
||||
*/
|
||||
@GetMapping("/issueDefaultPolicyByClientId")
|
||||
@InnerAuth
|
||||
public R<Integer> issueDefaultPolicyByClientId(String clientId)
|
||||
{
|
||||
int rows = rmMonitorPolicyService.issueDefaultPolicyByClientId(clientId);
|
||||
return R.ok(rows);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务器脚本策略对象 rm_deployment_policy
|
||||
@@ -89,4 +90,16 @@ public class RmDeploymentPolicy extends BaseEntity
|
||||
private String scriptPath;
|
||||
/** 业务脚本参数 */
|
||||
private String defaultParams;
|
||||
/** 不在线数量 */
|
||||
private Integer offlineNum;
|
||||
/** 执行成功数量 */
|
||||
private Integer sucessNum;
|
||||
/** 执行失败数量 */
|
||||
private Integer failNum;
|
||||
/** 不在线服务器clientId集合 */
|
||||
private List<String> offlineClientIds;
|
||||
/** 执行成功clientId集合 */
|
||||
private List<String> sucessClientIds;
|
||||
/** 执行失败clientIdji和 */
|
||||
private List<String> failClientIds;
|
||||
}
|
||||
|
||||
@@ -59,5 +59,7 @@ public class RmNetworkInterface extends BaseEntity
|
||||
private String gateway;
|
||||
/** 绑定ip 1业务IP,2管理ip */
|
||||
private String bindIp;
|
||||
/** 是否为新信息 */
|
||||
private String newFlag;
|
||||
|
||||
}
|
||||
|
||||
@@ -55,4 +55,10 @@ public class RmResourceRemote extends BaseEntity
|
||||
private String connectionMethod;
|
||||
/** 脚本执行结果 */
|
||||
private String commandResult;
|
||||
/** 客户端id */
|
||||
private String clientId;
|
||||
/** 执行结果标识(0 失败 1成功) */
|
||||
private Integer resultFlag;
|
||||
/** 脚本id */
|
||||
private Long scriptId;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ServerScriptPolicyVo {
|
||||
/** 服务器脚本策略id */
|
||||
private String scriptId;
|
||||
/** 策略名称 */
|
||||
private String policyName;
|
||||
/** 外网Http(s)地址 */
|
||||
|
||||
@@ -90,12 +90,12 @@ public class MessageHandler {
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
// registerHandler(MsgEnum.执行脚本策略应答.getValue(), this::handleScriptRspMessage);
|
||||
registerHandler(MsgEnum.执行脚本策略应答.getValue(), this::handleScriptRspMessage);
|
||||
// registerHandler(MsgEnum.Agent版本更新应答.getValue(), this::handleAgentUpdateRspMessage);
|
||||
|
||||
// 其他类型消息可以单独注册处理器
|
||||
registerHandler(MsgEnum.注册.getValue(), this::handleRegisterMessage);
|
||||
// registerHandler(MsgEnum.获取最新策略.getValue(), this::handleNewPolicyMessage);
|
||||
registerHandler(MsgEnum.获取最新策略.getValue(), this::handleNewPolicyMessage);
|
||||
// registerHandler(MsgEnum.CPU上报.getValue(), this::handleCpuMessage);
|
||||
// registerHandler(MsgEnum.磁盘上报.getValue(), this::handleDiskMessage);
|
||||
// registerHandler(MsgEnum.容器上报.getValue(), this::handleDockerMessage);
|
||||
@@ -116,7 +116,7 @@ public class MessageHandler {
|
||||
RegisterMsgVo registerMsgVo = interfaces.get(0);
|
||||
String clientId = registerMsgVo.getClientId();
|
||||
// 如果未下发监控策略,下发
|
||||
rmMonitorPolicyService.issuePolicyMsgByClientId(clientId);
|
||||
// rmMonitorPolicyService.issuePolicyMsgByClientId(clientId);
|
||||
// 如果未下发服务器脚本策略,下发
|
||||
rmDeploymentPolicyService.issueDeployPolicyMsgByClientId(clientId);
|
||||
}
|
||||
@@ -654,19 +654,15 @@ public class MessageHandler {
|
||||
Date createTime = new Date(millis / 1000 * 1000); // 去除毫秒
|
||||
// 查询资源信息
|
||||
RmResourceRegistrationRemote queryParam = new RmResourceRegistrationRemote();
|
||||
queryParam.setHardwareSn(message.getClientId());
|
||||
queryParam.setClientId(message.getClientId());
|
||||
R<RmResourceRegistrationRemote> resourceMsg = remoteRevenueConfigService.getListByHardwareSn(queryParam, SecurityConstants.INNER);
|
||||
RmResourceRegistrationRemote resourceMsgData = resourceMsg.getData();
|
||||
if(rsp.getResCode() == 1){
|
||||
if(rsp.getResult() != null){
|
||||
// 构建脚本执行结果实体类
|
||||
RmResourceRemote insertData = new RmResourceRemote();
|
||||
insertData.setHardwareSn(message.getClientId());
|
||||
insertData.setResourceName(resourceMsgData.getResourceName());
|
||||
insertData.setExternalIp(resourceMsgData.getIpAddress());
|
||||
insertData.setManagementPort(22);
|
||||
insertData.setConnectionMethod("1");
|
||||
insertData.setResourceType(resourceMsgData.getResourceType());
|
||||
insertData.setClientId(message.getClientId());
|
||||
insertData.setResultFlag(1);
|
||||
insertData.setDescription(rsp.getResult());
|
||||
insertData.setCreateTime(createTime);
|
||||
// 执行插入sql
|
||||
@@ -674,6 +670,16 @@ public class MessageHandler {
|
||||
log.info("脚本执行结果入库成功:{}",rsp);
|
||||
}
|
||||
}else{
|
||||
// 构建脚本执行结果实体类
|
||||
RmResourceRemote insertData = new RmResourceRemote();
|
||||
insertData.setClientId(message.getClientId());
|
||||
insertData.setResultFlag(0);
|
||||
if(rsp.getResult() != null){
|
||||
insertData.setDescription(rsp.getResult());
|
||||
}
|
||||
insertData.setCreateTime(createTime);
|
||||
// 执行插入sql
|
||||
rmResourceRemoteService.insertRmResourceRemote(insertData);
|
||||
log.error("脚本执行失败:{}", rsp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,9 +110,16 @@ public class InitialSystemOtherCollectDataServiceImpl implements IInitialSystemO
|
||||
*/
|
||||
@Override
|
||||
public Map getMonitorMsg(InitialSystemOtherCollectData initialSystemOtherCollectData) {
|
||||
Map map = initialSystemOtherCollectDataMapper.getMonitorMsg(initialSystemOtherCollectData);
|
||||
Map<String, Object> map = initialSystemOtherCollectDataMapper.getMonitorMsg(initialSystemOtherCollectData);
|
||||
// 如果返回null,初始化一个空的Map
|
||||
if (map == null) {
|
||||
map = new HashMap<>();
|
||||
}
|
||||
// 获取cpu数量
|
||||
InitialCpuInfo cpuInfo = initialCpuInfoMapper.getCpuInfoByClientId(initialSystemOtherCollectData.getClientId());
|
||||
if (cpuInfo == null) {
|
||||
cpuInfo = new InitialCpuInfo();
|
||||
}
|
||||
map.put("systemCpuNum", cpuInfo.getNum());
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -8,11 +8,13 @@ import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.rocketmq.domain.DeviceMessage;
|
||||
import com.ruoyi.rocketmq.domain.RmDeploymentPolicy;
|
||||
import com.ruoyi.rocketmq.domain.RmResourceRemote;
|
||||
import com.ruoyi.rocketmq.domain.vo.PolicyTypeVo;
|
||||
import com.ruoyi.rocketmq.domain.vo.PolicyVo;
|
||||
import com.ruoyi.rocketmq.domain.vo.ScriptPolicyVo;
|
||||
import com.ruoyi.rocketmq.domain.vo.ServerScriptPolicyVo;
|
||||
import com.ruoyi.rocketmq.mapper.RmDeploymentPolicyMapper;
|
||||
import com.ruoyi.rocketmq.mapper.RmResourceRemoteMapper;
|
||||
import com.ruoyi.rocketmq.model.ProducerMode;
|
||||
import com.ruoyi.rocketmq.producer.MessageProducer;
|
||||
import com.ruoyi.rocketmq.service.IRmDeploymentPolicyService;
|
||||
@@ -45,6 +47,8 @@ public class RmDeploymentPolicyServiceImpl implements IRmDeploymentPolicyService
|
||||
private DataProcessUtil dataProcessUtil;
|
||||
@Autowired
|
||||
private ProducerMode producerMode;
|
||||
@Autowired
|
||||
private RmResourceRemoteMapper rmResourceRemoteMapper;
|
||||
|
||||
/**
|
||||
* 查询服务器脚本策略
|
||||
@@ -74,6 +78,30 @@ public class RmDeploymentPolicyServiceImpl implements IRmDeploymentPolicyService
|
||||
// 包含设备名称赋值
|
||||
deploymentPolicyList.forEach(policy -> {
|
||||
getIncludeNameById(policy);
|
||||
// 不在线数量赋值
|
||||
String deviceMsg = policy.getDeployDevice();
|
||||
if (deviceMsg != null) {
|
||||
List<String> offOnlineList = new ArrayList<>();
|
||||
List<String> successList = new ArrayList<>();
|
||||
List<String> failList = new ArrayList<>();
|
||||
for (String clientId : deviceMsg.split("\n")) {
|
||||
RmResourceRemote query = new RmResourceRemote();
|
||||
query.setScriptId(policy.getId());
|
||||
query.setClientId(clientId);
|
||||
List<RmResourceRemote> resultList = rmResourceRemoteMapper.selectRmResourceRemoteList(query);
|
||||
if (resultList.isEmpty()) {
|
||||
offOnlineList.add(clientId);
|
||||
continue;
|
||||
}
|
||||
resultList.forEach(resourceRemote -> {
|
||||
if (resourceRemote.getResultFlag() == 0) {
|
||||
failList.add(clientId);
|
||||
} else if (resourceRemote.getResultFlag() == 1) {
|
||||
successList.add(clientId);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deploymentPolicyList;
|
||||
@@ -279,6 +307,7 @@ public class RmDeploymentPolicyServiceImpl implements IRmDeploymentPolicyService
|
||||
for (RmDeploymentPolicy policy : policyList) {
|
||||
// 构建并发送脚本配置
|
||||
ServerScriptPolicyVo scriptPolicyVo = new ServerScriptPolicyVo();
|
||||
scriptPolicyVo.setScriptId(policy.getId().toString());
|
||||
scriptPolicyVo.setPolicyName(policy.getPolicyName());
|
||||
scriptPolicyVo.setFileUrl(policy.getScriptPath());
|
||||
scriptPolicyVo.setCommandParams(policy.getDefaultParams());
|
||||
|
||||
@@ -101,7 +101,8 @@ public class DynamicOidCollector {
|
||||
// 判断是否需要索引处理
|
||||
boolean needIndex = needIndexProcessing(oidParams, deviceType);
|
||||
// 获取过滤条件
|
||||
List<String> filterValues = switchVo.getFilterByType(deviceType);
|
||||
String filterType = deviceType + "OID";
|
||||
List<String> filterValues = switchVo.getFilterByType(filterType);
|
||||
log.info("采集交换机 {} 的 {} 设备信息,筛选条件: {}",
|
||||
switchVo.getIp(), deviceType, filterValues);
|
||||
|
||||
@@ -156,7 +157,9 @@ public class DynamicOidCollector {
|
||||
"1.3.6.1.2.1.1.4.0", // sysContact
|
||||
"1.3.6.1.2.1.1.5.0", // sysName
|
||||
"1.3.6.1.2.1.1.6.0", // sysLocation
|
||||
"1.3.6.1.4.1.2011.5.25.183.1.4.0" // hwStackSystemMac
|
||||
"1.3.6.1.4.1.2011.5.25.183.1.4.0", // hwStackSystemMac
|
||||
"1.3.6.1.4.1.2011.6.157.1.3.0", // hwAveragePower
|
||||
"1.3.6.1.4.1.2011.6.157.1.6.0" // hwCurrentPower
|
||||
));
|
||||
|
||||
// 检查所有配置的OID
|
||||
|
||||
@@ -156,7 +156,6 @@ public class MultiSwitchCollectionScheduler {
|
||||
|
||||
// OID配置(复制所有OID Map)
|
||||
resultMap.setNetOID(new LinkedHashMap<>(switchVo.getNetOID()));
|
||||
resultMap.setEntityOID(new LinkedHashMap<>(switchVo.getEntityOID()));
|
||||
resultMap.setPwrOID(new LinkedHashMap<>(switchVo.getPwrOID()));
|
||||
resultMap.setFanOID(new LinkedHashMap<>(switchVo.getFanOID()));
|
||||
resultMap.setMpuOID(new LinkedHashMap<>(switchVo.getMpuOID()));
|
||||
|
||||
@@ -157,7 +157,7 @@
|
||||
<where>
|
||||
<if test="policyStatus != null and policyStatus != ''"> and policy_status = #{policyStatus}</if>
|
||||
<if test="deployDevice != null ">
|
||||
FIND_IN_SET(#{deployDevice}, REPLACE(deploy_device, '\n', ',')) > 0
|
||||
and FIND_IN_SET(#{deployDevice}, REPLACE(deploy_device, '\n', ',')) > 0
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
@@ -21,10 +21,11 @@
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="bindIp" column="bind_ip" />
|
||||
<result property="newFlag" column="new_flag" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectRmNetworkInterfaceVo">
|
||||
select id, client_id, isp, province, city, public_ip, interface_name, mac_address, interface_type, ipv4_address, gateway, create_time, update_time, create_by, update_by, bind_ip from rm_network_interface
|
||||
select id, client_id, isp, province, city, public_ip, interface_name, mac_address, interface_type, ipv4_address, gateway, create_time, update_time, create_by, update_by, bind_ip, new_flag from rm_network_interface
|
||||
</sql>
|
||||
|
||||
<select id="selectRmNetworkInterfaceList" parameterType="RmNetworkInterface" resultMap="RmNetworkInterfaceResult">
|
||||
@@ -41,6 +42,7 @@
|
||||
<if test="ipv4Address != null and ipv4Address != ''"> and ipv4_address = #{ipv4Address}</if>
|
||||
<if test="gateway != null and gateway != ''"> and gateway = #{gateway}</if>
|
||||
<if test="bindIp != null and bindIp != ''"> and bind_ip = #{bindIp}</if>
|
||||
<if test="newFlag != null "> and new_flag = #{newFlag}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
@@ -67,6 +69,7 @@
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
<if test="bindIp != null">bind_ip,</if>
|
||||
<if test="newFlag != null">new_flag,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="clientId != null and clientId != ''">#{clientId},</if>
|
||||
@@ -84,6 +87,7 @@
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
<if test="bindIp != null">#{bindIp},</if>
|
||||
<if test="newFlag != null">#{newFlag},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
@@ -105,9 +109,21 @@
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="bindIp != null">bind_ip = #{bindIp},</if>
|
||||
<if test="newFlag != null">new_flag = #{newFlag},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteRmNetworkInterfaceById" parameterType="Long">
|
||||
delete from rm_network_interface where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteRmNetworkInterfaceByIds" parameterType="String">
|
||||
delete from rm_network_interface where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
<update id="updateRmNetworkInterfaceByMac" parameterType="RmNetworkInterface">
|
||||
update rm_network_interface
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
@@ -125,18 +141,8 @@
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="bindIp != null">bind_ip = #{bindIp},</if>
|
||||
<if test="newFlag != null">new_flag = #{newFlag},</if>
|
||||
</trim>
|
||||
where mac_address = #{macAddress}
|
||||
</update>
|
||||
|
||||
<delete id="deleteRmNetworkInterfaceById" parameterType="Long">
|
||||
delete from rm_network_interface where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteRmNetworkInterfaceByIds" parameterType="String">
|
||||
delete from rm_network_interface where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -1,9 +1,9 @@
|
||||
<?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">
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.rocketmq.mapper.RmResourceRemoteMapper">
|
||||
|
||||
|
||||
<resultMap type="RmResourceRemote" id="RmResourceRemoteResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="hardwareSn" column="hardware_sn" />
|
||||
@@ -19,15 +19,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="clientId" column="client_id" />
|
||||
<result property="resultFlag" column="result_flag" />
|
||||
<result property="scriptId" column="script_id" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectRmResourceRemoteVo">
|
||||
select id, hardware_sn, resource_type, resource_name, description, internal_ip, external_ip, management_port, online_status, connection_method, create_time, update_time, create_by, update_by from rm_resource_remote
|
||||
select id, hardware_sn, resource_type, resource_name, description, internal_ip, external_ip, management_port, online_status, connection_method, create_time, update_time, create_by, update_by, client_id, result_flag, script_id from rm_resource_remote
|
||||
</sql>
|
||||
|
||||
<select id="selectRmResourceRemoteList" parameterType="RmResourceRemote" resultMap="RmResourceRemoteResult">
|
||||
<include refid="selectRmResourceRemoteVo"/>
|
||||
<where>
|
||||
<where>
|
||||
<if test="hardwareSn != null and hardwareSn != ''"> and hardware_sn = #{hardwareSn}</if>
|
||||
<if test="resourceType != null and resourceType != ''"> and resource_type = #{resourceType}</if>
|
||||
<if test="resourceName != null and resourceName != ''"> and resource_name like concat('%', #{resourceName}, '%')</if>
|
||||
@@ -37,16 +40,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="managementPort != null "> and management_port = #{managementPort}</if>
|
||||
<if test="onlineStatus != null and onlineStatus != ''"> and online_status = #{onlineStatus}</if>
|
||||
<if test="connectionMethod != null and connectionMethod != ''"> and connection_method = #{connectionMethod}</if>
|
||||
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
|
||||
<if test="resultFlag != null "> and result_flag = #{resultFlag}</if>
|
||||
<if test="scriptId != null "> and script_id = #{scriptId}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectRmResourceRemoteById" parameterType="Long" resultMap="RmResourceRemoteResult">
|
||||
<include refid="selectRmResourceRemoteVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertRmResourceRemote" parameterType="RmResourceRemote" useGeneratedKeys="true" keyProperty="id">
|
||||
insert IGNORE into rm_resource_remote
|
||||
insert into rm_resource_remote
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="hardwareSn != null and hardwareSn != ''">hardware_sn,</if>
|
||||
<if test="resourceType != null and resourceType != ''">resource_type,</if>
|
||||
@@ -61,7 +67,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
</trim>
|
||||
<if test="clientId != null">client_id,</if>
|
||||
<if test="resultFlag != null">result_flag,</if>
|
||||
<if test="scriptId != null">script_id,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="hardwareSn != null and hardwareSn != ''">#{hardwareSn},</if>
|
||||
<if test="resourceType != null and resourceType != ''">#{resourceType},</if>
|
||||
@@ -76,7 +85,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
</trim>
|
||||
<if test="clientId != null">#{clientId},</if>
|
||||
<if test="resultFlag != null">#{resultFlag},</if>
|
||||
<if test="scriptId != null">#{scriptId},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateRmResourceRemote" parameterType="RmResourceRemote">
|
||||
@@ -95,6 +107,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="clientId != null">client_id = #{clientId},</if>
|
||||
<if test="resultFlag != null">result_flag = #{resultFlag},</if>
|
||||
<if test="scriptId != null">script_id = #{scriptId},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
@@ -104,7 +119,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</delete>
|
||||
|
||||
<delete id="deleteRmResourceRemoteByIds" parameterType="String">
|
||||
delete from rm_resource_remote where id in
|
||||
delete from rm_resource_remote where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
|
||||
Reference in New Issue
Block a user