rocktmqjson串减少转义次数,数据类型与接收数据适配

This commit is contained in:
gaoyutao
2025-09-28 09:36:24 +08:00
parent cc9593b4bf
commit 9fa62124e6
20 changed files with 214 additions and 144 deletions

View File

@@ -97,15 +97,15 @@ public class InitialSwitchInfoDetails extends BaseEntity
/** 交换机ip */
private String switchIp;
/** 端口配置速率(Mbps) */
private BigDecimal ifSpeed;
private String ifSpeed;
/** 入站丢包 */
private Integer ifInDiscards;
private String ifInDiscards;
/** 出站丢包 */
private Integer ifOutDiscards;
private String ifOutDiscards;
/** 错误的入站数据包数量 */
private Integer ifInErrors;
private String ifInErrors;
/** 错误的出站数据包数量 */
private Integer ifOutErrors;
private String ifOutErrors;
/** 端口索引 */
private Integer ifIndex;
private String ifIndex;
}

View File

@@ -62,5 +62,9 @@ public class RmResourceGroup extends BaseEntity
private String discoveryRules;
/** 资源id */
private String resourceIds;
/** 资源类型 */
private String resourceType;
/** 查询条件名称 */
private String queryName;
}

View File

@@ -127,5 +127,7 @@ public class RmResourceRegistration extends BaseEntity
private String monitorItems;
/** 自动发现项 */
private String discoveryRules;
/** 查询名称 */
private String queryName;
}

View File

@@ -129,6 +129,8 @@ public class RmResourceGroupServiceImpl implements IRmResourceGroupService
pageDomain.setPageSize(rmResourceGroup.getPageSize());
if(rmResourceGroup.getId() == null){
RmResourceRegistration queryParam = new RmResourceRegistration();
queryParam.setResourceType(rmResourceGroup.getResourceType());
queryParam.setQueryName(rmResourceGroup.getQueryName());
// 开启分页
startPage(pageDomain);
List<RmResourceRegistration> rmResourceRegistrationList = rmResourceRegistrationMapper.selectRmResourceRegistrationList(queryParam);

View File

@@ -75,6 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="creatorName != null and creatorName != ''"> and creator_name like concat('%', #{creatorName}, '%')</if>
<if test="updaterId != null "> and updater_id = #{updaterId}</if>
<if test="updaterName != null and updaterName != ''"> and updater_name like concat('%', #{updaterName}, '%')</if>
<if test="queryName != null and queryName != ''"> and (hardware_sn = #{queryName} or resource_name like concat('%', #{queryName}, '%')) </if>
</where>
order by create_time desc
</select>

View File

@@ -1,6 +1,5 @@
package com.ruoyi.rocketmq.controller;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageDomain;
@@ -13,7 +12,6 @@ import com.ruoyi.rocketmq.service.IRmAgentManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
@@ -33,8 +31,8 @@ public class RmAgentManagementController extends BaseController
* 查询Agent管理列表
*/
@RequiresPermissions("rocketmq:management:list")
@GetMapping("/list")
public TableDataInfo list(RmAgentManagement rmAgentManagement)
@PostMapping("/list")
public TableDataInfo list(@RequestBody RmAgentManagement rmAgentManagement)
{
PageDomain pageDomain = new PageDomain();
pageDomain.setPageNum(rmAgentManagement.getPageNum());
@@ -44,19 +42,6 @@ public class RmAgentManagementController extends BaseController
return getDataTable(list);
}
/**
* 导出Agent管理列表
*/
@RequiresPermissions("rocketmq:management:export")
@Log(title = "Agent管理", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, RmAgentManagement rmAgentManagement)
{
List<RmAgentManagement> list = rmAgentManagementService.selectRmAgentManagementList(rmAgentManagement);
ExcelUtil<RmAgentManagement> util = new ExcelUtil<RmAgentManagement>(RmAgentManagement.class);
util.exportExcel(response, list, "Agent管理数据");
}
/**
* 获取Agent管理详细信息
*/
@@ -88,15 +73,4 @@ public class RmAgentManagementController extends BaseController
{
return toAjax(rmAgentManagementService.updateRmAgentManagement(rmAgentManagement));
}
/**
* 删除Agent管理
*/
@RequiresPermissions("rocketmq:management:remove")
@Log(title = "Agent管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(rmAgentManagementService.deleteRmAgentManagementByIds(ids));
}
}

View File

@@ -50,17 +50,17 @@ public class InitialSwitchInfo extends BaseEntity
/** 交换机ip */
private String switchIp;
/** 端口配置速率(Mbps) */
private BigDecimal ifSpeed;
private String ifSpeed;
/** 入站丢包 */
private Integer ifInDiscards;
private String ifInDiscards;
/** 出站丢包 */
private Integer ifOutDiscards;
private String ifOutDiscards;
/** 错误的入站数据包数量 */
private Integer ifInErrors;
private String ifInErrors;
/** 错误的出站数据包数量 */
private Integer ifOutErrors;
private String ifOutErrors;
/** 端口索引 */
private Integer ifIndex;
private String ifIndex;
}

View File

@@ -54,15 +54,15 @@ public class InitialSwitchInfoTemp extends BaseEntity
/** 交换机ip */
private String switchIp;
/** 端口配置速率(Mbps) */
private BigDecimal ifSpeed;
private String ifSpeed;
/** 入站丢包 */
private Integer ifInDiscards;
private String ifInDiscards;
/** 出站丢包 */
private Integer ifOutDiscards;
private String ifOutDiscards;
/** 错误的入站数据包数量 */
private Integer ifInErrors;
private String ifInErrors;
/** 错误的出站数据包数量 */
private Integer ifOutErrors;
private String ifOutErrors;
/** 端口索引 */
private Integer ifIndex;
private String ifIndex;
}

View File

@@ -5,7 +5,6 @@ import com.ruoyi.common.core.annotation.Excel;
import com.ruoyi.common.core.web.domain.BaseEntity;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.Date;
/**
@@ -49,7 +48,7 @@ public class RmAgentManagement extends BaseEntity
/** 定时更新时间cron表达式 */
@Excel(name = "定时更新时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime scheduledUpdateTime;
private Date scheduledUpdateTime;
/** 文件地址格式 */
@Excel(name = "文件地址格式")
private Long fileUrlType;
@@ -73,5 +72,7 @@ public class RmAgentManagement extends BaseEntity
private String includeIds;
/** 生效服务器名称 */
private String includeNames;
/** 查询条件名称 */
private String queryName;
}

View File

@@ -1,10 +1,8 @@
package com.ruoyi.rocketmq.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.time.Instant;
import java.time.LocalDateTime;
@Data
public class AgentUpdateVo {
@@ -17,8 +15,7 @@ public class AgentUpdateVo {
/** 执行方式0、立即执行1、定时执行 */
private Integer method;
/** 定时时间执行方式为1、定时执行时该字段必传 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime policyTime;
private long policyTime;
/** 时间戳 */
private long timestamp = Instant.now().getEpochSecond();
}

View File

@@ -11,7 +11,7 @@ public class RegisterSwitchVo {
/** 服务器端口 */
private Integer clientPort;
/** 交换机信息 */
private String switchBoard;
private SwitchOidVo switchBoard;
/** 时间戳(秒) */
private long timestamp = Instant.now().getEpochSecond();

View File

@@ -2,18 +2,23 @@ package com.ruoyi.rocketmq.domain.vo;
import lombok.Data;
import java.util.List;
import java.util.Map;
@Data
public class SwitchOidVo {
private String netOID;
private String moduleOID;
private String mpuOID;
private String pwrOID;
private String fanOID;
private String otherOID;
private Map<String, String> netOID;
private Map<String, String> moduleOID;
private Map<String, String> mpuOID;
private Map<String, String> pwrOID;
private Map<String, String> fanOID;
private Map<String, String> otherOID;
/** 团体名 */
private String community;
/** ip地址 */
private String ip;
/** 端口 */
private Integer port;
/** 过滤值 */
private Map<String, List<String>> filters;
}

View File

@@ -11,6 +11,7 @@ import com.ruoyi.rocketmq.domain.vo.CollectDataVo;
import com.ruoyi.rocketmq.domain.vo.RspVo;
import com.ruoyi.rocketmq.service.*;
import com.ruoyi.rocketmq.utils.JsonDataParser;
import com.ruoyi.rocketmq.utils.SwitchJsonDataParser;
import com.ruoyi.system.api.RemoteRevenueConfigService;
import com.ruoyi.system.api.domain.EpsInitialTrafficDataRemote;
import com.ruoyi.system.api.domain.InitialSwitchInfoDetailsRemote;
@@ -87,6 +88,8 @@ public class DeviceMessageHandler {
private IInitialSystemOtherCollectDataService iInitialSystemOtherCollectDataService;
@Autowired
private IRmResourceRemoteService rmResourceRemoteService;
@Autowired
private IRmAgentManagementService rmAgentManagementService;
// 在类中添加
private static final ObjectMapper objectMapper = new ObjectMapper();
@@ -105,7 +108,7 @@ public class DeviceMessageHandler {
registerHandler(MsgEnum.关闭交换机采集应答.getValue(), this::handleResponseMessage);
registerHandler(MsgEnum.告警设置应答.getValue(), this::handleResponseMessage);
registerHandler(MsgEnum.执行脚本策略应答.getValue(), this::handleScriptRspMessage);
registerHandler(MsgEnum.Agent版本更新应答.getValue(), this::handleResponseMessage);
registerHandler(MsgEnum.Agent版本更新应答.getValue(), this::handleAgentUpdateRspMessage);
// 其他类型消息可以单独注册处理器
registerHandler(MsgEnum.CPU上报.getValue(), this::handleCpuMessage);
@@ -119,6 +122,28 @@ public class DeviceMessageHandler {
registerHandler(MsgEnum.心跳上报.getValue(), this::handleHeartbeatMessage);
}
/**
* agent更新响应
* @param message
*/
private void handleAgentUpdateRspMessage(DeviceMessage message) {
List<RspVo> rspVoList = JsonDataParser.parseJsonData(message.getData(), RspVo.class);
if (!rspVoList.isEmpty()) {
RspVo rsp = rspVoList.get(0);
if(rsp.getResCode() == 1){
RmAgentManagement rmAgentManagement = new RmAgentManagement();
rmAgentManagement.setHardwareSn(message.getClientId());
rmAgentManagement.setLastUpdateResult("1");
rmAgentManagementService.updateRmAgentManagementByHardwareSn(rmAgentManagement);
}else{
RmAgentManagement rmAgentManagement = new RmAgentManagement();
rmAgentManagement.setHardwareSn(message.getClientId());
rmAgentManagement.setLastUpdateResult("0");
rmAgentManagementService.updateRmAgentManagementByHardwareSn(rmAgentManagement);
}
}
}
/**
* 注册消息处理器
*/
@@ -285,10 +310,9 @@ public class DeviceMessageHandler {
List<CollectDataVo> switchData = JsonDataParser.parseJsonData(message.getData(), CollectDataVo.class);
if(!switchData.isEmpty()){
CollectDataVo switchDataVo = switchData.get(0);
switchDataVo.setValue(switchDataVo.getValue().replaceAll("\"noSuchInstance\"", "null"));
switch(switchDataVo.getType()){
case "switchNetCollect":
handleSwitchMessage(switchDataVo, message.getClientId());
handleSwitchNetMessage(switchDataVo, message.getClientId());
break;
case "switchPwrCollect":
handleSwitchPwrMessage(switchDataVo, message.getClientId());
@@ -316,7 +340,7 @@ public class DeviceMessageHandler {
* @param switchDataVo
*/
private void handleSwitchPwrMessage(CollectDataVo switchDataVo, String clientId){
List<InitialSwitchPowerSupply> powerSupplyList = JsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchPowerSupply.class);
List<InitialSwitchPowerSupply> powerSupplyList = SwitchJsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchPowerSupply.class);
if (!powerSupplyList.isEmpty()){
InitialSwitchPowerSupply insertData = powerSupplyList.get(0);
// 时间戳转换
@@ -333,7 +357,7 @@ public class DeviceMessageHandler {
* @param switchDataVo
*/
private void handleSwitchModuleMessage(CollectDataVo switchDataVo, String clientId){
List<InitialSwitchOpticalModule> moduleList = JsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchOpticalModule.class);
List<InitialSwitchOpticalModule> moduleList = SwitchJsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchOpticalModule.class);
if (!moduleList.isEmpty()){
InitialSwitchOpticalModule insertData = moduleList.get(0);
// 时间戳转换
@@ -351,7 +375,7 @@ public class DeviceMessageHandler {
* @param switchDataVo
*/
private void handleSwitchMpuMessage(CollectDataVo switchDataVo, String clientId){
List<InitialSwitchMpuInfo> mpuList = JsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchMpuInfo.class);
List<InitialSwitchMpuInfo> mpuList = SwitchJsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchMpuInfo.class);
if (!mpuList.isEmpty()){
InitialSwitchMpuInfo insertData = mpuList.get(0);
// 时间戳转换
@@ -369,7 +393,7 @@ public class DeviceMessageHandler {
* @param switchDataVo
*/
private void handleSwitchFanMessage(CollectDataVo switchDataVo, String clientId){
List<InitialSwitchFanInfo> fanList = JsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchFanInfo.class);
List<InitialSwitchFanInfo> fanList = SwitchJsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchFanInfo.class);
if (!fanList.isEmpty()){
InitialSwitchFanInfo insertData = fanList.get(0);
// 时间戳转换
@@ -438,11 +462,11 @@ public class DeviceMessageHandler {
}
}
/**
* 交换机数据入库
* 交换机网卡信息数据入库
* @param switchDataVo
*/
private void handleSwitchMessage(CollectDataVo switchDataVo, String clientId) {
List<InitialSwitchInfo> switchInfos = JsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchInfo.class);
private void handleSwitchNetMessage(CollectDataVo switchDataVo, String clientId) {
List<InitialSwitchInfo> switchInfos = SwitchJsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchInfo.class);
if(!switchInfos.isEmpty()){
// 时间戳转换
long timestamp = switchDataVo.getTimestamp();

View File

@@ -16,7 +16,6 @@ import org.apache.rocketmq.remoting.exception.RemotingException;
import java.io.UnsupportedEncodingException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -167,7 +166,7 @@ public class MessageProducer {
Message msg = new Message(topic,tag,key, value.getBytes(RemotingHelper.DEFAULT_CHARSET));
//设置消息延迟级别我这里设置5对应就是延时一分钟
// "1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h"
msg.setDelayTimeLevel(4);
msg.setDelayTimeLevel(1);
// 发送消息到一个Broker
result = producer.send(msg);
// 通过sendResult返回消息是否成功送达

View File

@@ -44,6 +44,14 @@ public interface IRmAgentManagementService
*/
public int updateRmAgentManagement(RmAgentManagement rmAgentManagement);
/**
* 保存最后更新结果
*
* @param rmAgentManagement Agent管理
* @return 结果
*/
public void updateRmAgentManagementByHardwareSn(RmAgentManagement rmAgentManagement);
/**
* 批量删除Agent管理
*

View File

@@ -1,7 +1,6 @@
package com.ruoyi.rocketmq.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.enums.MsgEnum;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.rocketmq.domain.DeviceMessage;
@@ -12,13 +11,13 @@ import com.ruoyi.rocketmq.model.ProducerMode;
import com.ruoyi.rocketmq.producer.MessageProducer;
import com.ruoyi.rocketmq.service.IRmAgentManagementService;
import com.ruoyi.system.api.RemoteRevenueConfigService;
import com.ruoyi.system.api.domain.RmResourceRegistrationRemote;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@@ -37,7 +36,7 @@ public class RmAgentManagementServiceImpl implements IRmAgentManagementService
private String filePath;
// private static String COMMAND = "/usr/local/tongran/deploy.sh restart";
private static String COMMAND = "/data/saas-income/houduan/tr-client-test/deploy.sh restart";
private static String COMMAND = "nohup /data/saas-income/houduan/tr-client-test/deploy.sh restart > /dev/null 2>&1 &";
private static String COMMAND2 = "cat /data/saas-income/houduan/tr-client-test/deploy.sh";
@Autowired
private ProducerMode producerMode;
@@ -91,7 +90,17 @@ public class RmAgentManagementServiceImpl implements IRmAgentManagementService
public int updateRmAgentManagement(RmAgentManagement rmAgentManagement)
{
rmAgentManagement.setUpdateTime(DateUtils.getNowDate());
return rmAgentManagementMapper.updateRmAgentManagement(rmAgentManagement);
processAgentUpdateData(rmAgentManagement);
return 1;
}
/**
* 保存最后更新结果
*
* @param rmAgentManagement Agent管理
* @return 结果
*/
public void updateRmAgentManagementByHardwareSn(RmAgentManagement rmAgentManagement){
rmAgentManagementMapper.updateRmAgentManagementBySn(rmAgentManagement);
}
/**
@@ -124,54 +133,63 @@ public class RmAgentManagementServiceImpl implements IRmAgentManagementService
*/
@Override
public int addRmAgentManagement(RmAgentManagement rmAgentManagement) {
// 设备
String idStr = rmAgentManagement.getIncludeIds();
String[] ids = idStr.split(",");
List<RmResourceRegistrationRemote> registrationRemotes = remoteRevenueConfigService.getRegistrationByIds(ids, SecurityConstants.INNER).getData();
for (RmResourceRegistrationRemote resourceMsg : registrationRemotes) {
rmAgentManagement.setHardwareSn(resourceMsg.getHardwareSn());
rmAgentManagement.setResourceName(resourceMsg.getResourceName());
rmAgentManagement.setInternalIp(resourceMsg.getIpAddress());
// 查询该资源是否已经配置
RmAgentManagement agentQueryParam = new RmAgentManagement();
agentQueryParam.setHardwareSn(resourceMsg.getHardwareSn());
List<RmAgentManagement> agentManagements = rmAgentManagementMapper.selectRmAgentManagementList(agentQueryParam);
if(!agentManagements.isEmpty()){
// 如果存在,修改
rmAgentManagementMapper.updateRmAgentManagementBySn(rmAgentManagement);
}else{
// 如果不存在,添加
rmAgentManagementMapper.insertRmAgentManagement(rmAgentManagement);
}
// 构建更新策略
AgentUpdateVo agentUpdateVo = new AgentUpdateVo();
agentUpdateVo.setFileUrl(rmAgentManagement.getFileUrl());
agentUpdateVo.setFilePath("/data/saas-income/houduan/tr-client-test/temp");
List<String> commandList = new ArrayList<>();
commandList.add(COMMAND);
commandList.add(COMMAND2);
agentUpdateVo.setCommands(JSONObject.toJSONString(commandList));
agentUpdateVo.setMethod(rmAgentManagement.getMethod());
if(rmAgentManagement.getMethod() == 1){
agentUpdateVo.setPolicyTime(rmAgentManagement.getScheduledUpdateTime());
}
try {
DeviceMessage deviceMessage = new DeviceMessage();
deviceMessage.setClientId(resourceMsg.getHardwareSn());
deviceMessage.setDataType(MsgEnum.Agent版本更新.getValue());
deviceMessage.setData(JSONObject.toJSONString(agentUpdateVo));
MessageProducer messageProducer = new MessageProducer();
messageProducer.sendAsyncProducerMessage(
producerMode.getAgentTopic(),
"",
"",
JSONObject.toJSONString(deviceMessage)
);
} catch (Exception e) {
log.error("发送设备配置失败deviceId: {}", resourceMsg.getHardwareSn(), e);
}
}
processAgentUpdateData(rmAgentManagement);
return 1;
}
/**
* 处理agen更新数据
* @param rmAgentManagement
*/
public void processAgentUpdateData(RmAgentManagement rmAgentManagement){
// 查询该资源是否已经配置
RmAgentManagement agentQueryParam = new RmAgentManagement();
agentQueryParam.setHardwareSn(rmAgentManagement.getHardwareSn());
List<RmAgentManagement> agentManagements = rmAgentManagementMapper.selectRmAgentManagementList(agentQueryParam);
if(!agentManagements.isEmpty()){
// 如果存在,修改
rmAgentManagement.setLastUpdateTime(DateUtils.getNowDate());
if("0".equals(rmAgentManagement.getMethod())){
rmAgentManagement.setScheduledUpdateTime(null);
}
rmAgentManagementMapper.updateRmAgentManagementBySn(rmAgentManagement);
}else{
// 如果不存在,添加
rmAgentManagement.setLastUpdateTime(DateUtils.getNowDate());
if("0".equals(rmAgentManagement.getMethod())){
rmAgentManagement.setScheduledUpdateTime(null);
}
rmAgentManagementMapper.insertRmAgentManagement(rmAgentManagement);
}
// 构建更新策略
AgentUpdateVo agentUpdateVo = new AgentUpdateVo();
agentUpdateVo.setFileUrl(rmAgentManagement.getFileUrl());
agentUpdateVo.setFilePath("/data/saas-income/houduan/tr-client-test/temp");
List<String> commandList = new ArrayList<>();
commandList.add(COMMAND);
commandList.add(COMMAND2);
agentUpdateVo.setCommands(JSONObject.toJSONString(commandList));
agentUpdateVo.setMethod(rmAgentManagement.getMethod());
if(rmAgentManagement.getMethod() == 1){
Date scheduledUpdateTime = rmAgentManagement.getScheduledUpdateTime();
long scheduledTime = scheduledUpdateTime.toInstant().getEpochSecond();
agentUpdateVo.setPolicyTime(scheduledTime);
}
try {
DeviceMessage deviceMessage = new DeviceMessage();
deviceMessage.setClientId(rmAgentManagement.getHardwareSn());
deviceMessage.setDataType(MsgEnum.Agent版本更新.getValue());
deviceMessage.setData(JSONObject.toJSONString(agentUpdateVo));
MessageProducer messageProducer = new MessageProducer();
messageProducer.sendAsyncProducerMessage(
producerMode.getAgentTopic(),
"",
"",
JSONObject.toJSONString(deviceMessage)
);
} catch (Exception e) {
log.error("发送设备配置失败deviceId: {}", rmAgentManagement.getHardwareSn(), e);
}
}
}

View File

@@ -133,10 +133,6 @@ public class RmInitialMonitorItemServiceImpl implements IRmInitialMonitorItemSer
if ("monitorItem".equals(itemType)) {
// 系统信息
resultMap.put("switchOther", filterItems(allItems, "SYSTEM"));
// MPU信息
resultMap.put("switchMpu", filterItems(allItems, "MPU"));
// 电源信息
resultMap.put("switchPwr", filterItems(allItems, "POWERSOURCE"));
}
else if ("autodiscoverItem".equals(itemType)) {
// 网络端口信息
@@ -145,6 +141,10 @@ public class RmInitialMonitorItemServiceImpl implements IRmInitialMonitorItemSer
resultMap.put("switchModule", filterItems(allItems, "LIGHTMODULE"));
// 风扇信息
resultMap.put("switchFan", filterItems(allItems, "FAN"));
// MPU信息
resultMap.put("switchMpu", filterItems(allItems, "MPU"));
// 电源信息
resultMap.put("switchPwr", filterItems(allItems, "POWERSOURCE"));
}
}

View File

@@ -301,9 +301,9 @@ public class RmMonitorPolicyServiceImpl implements IRmMonitorPolicyService
}
// 更新策略状态为已下发
RmMonitorPolicy policyUpdate = new RmMonitorPolicy();
policyUpdate.setId(id);
policyUpdate.setStatus("1");
rmMonitorPolicyMapper.updateRmMonitorPolicy(policyUpdate);
// policyUpdate.setId(id);
// policyUpdate.setStatus("1");
// rmMonitorPolicyMapper.updateRmMonitorPolicy(policyUpdate);
return 1;
} catch (Exception e) {
@@ -376,7 +376,15 @@ public class RmMonitorPolicyServiceImpl implements IRmMonitorPolicyService
}
}
private <T> SwitchOidVo processSwitchOids(Map<String, List<T>> configs, String[] types) {
// oid集合
Map<String, Map<String, String>> resultMap = new HashMap<>();
// 过滤值集合
List<String> otherFilterValueList = new ArrayList<>();
List<String> netFilterValueList = new ArrayList<>();
List<String> moduleFilterValueList = new ArrayList<>();
List<String> mpuFilterValueList = new ArrayList<>();
List<String> pwrFilterValueList = new ArrayList<>();
List<String> fanFilterValueList = new ArrayList<>();
// 初始化各个OID类型的Map
resultMap.put("otherOID", new HashMap<>());
@@ -385,7 +393,6 @@ public class RmMonitorPolicyServiceImpl implements IRmMonitorPolicyService
resultMap.put("mpuOID", new HashMap<>());
resultMap.put("pwrOID", new HashMap<>());
resultMap.put("fanOID", new HashMap<>());
for (String type : types) {
if (configs.get(type) != null) {
for (T config : configs.get(type)) {
@@ -393,27 +400,46 @@ public class RmMonitorPolicyServiceImpl implements IRmMonitorPolicyService
RmTemplateSwitch switchConfig = (RmTemplateSwitch) config;
String oid = switchConfig.getOid();
String metricKey = switchConfig.getMetricKey();
String filterValue = switchConfig.getFilterValue();
switch(type) {
case "switchOther":
resultMap.get("otherOID").put(oid, metricKey);
if(filterValue != null){
otherFilterValueList.add(filterValue);
}
break;
case "switchMpu":
resultMap.get("mpuOID").put(oid, metricKey);
if(filterValue != null){
mpuFilterValueList.add(filterValue);
}
break;
case "switchPwr":
resultMap.get("pwrOID").put(oid, metricKey);
if(filterValue != null){
pwrFilterValueList.add(filterValue);
}
break;
case "switchNet":
if(oid != null && oid != "null"){
resultMap.get("netOID").put(oid, metricKey);
if(filterValue != null){
netFilterValueList.add(filterValue);
}
}
break;
case "switchModule":
resultMap.get("moduleOID").put(oid, metricKey);
if(filterValue != null){
moduleFilterValueList.add(filterValue);
}
break;
case "switchFan":
resultMap.get("fanOID").put(oid, metricKey);
if(filterValue != null){
fanFilterValueList.add(filterValue);
}
break;
default:
break;
@@ -422,15 +448,22 @@ public class RmMonitorPolicyServiceImpl implements IRmMonitorPolicyService
}
}
}
Map<String, List<String>> filtersMap = new HashMap();
filtersMap.put("otherOID", otherFilterValueList);
filtersMap.put("netOID", netFilterValueList);
filtersMap.put("moduleOID", moduleFilterValueList);
filtersMap.put("mpuOID", mpuFilterValueList);
filtersMap.put("pwrOID", pwrFilterValueList);
filtersMap.put("fanOID", fanFilterValueList);
SwitchOidVo switchOidVo = new SwitchOidVo();
// 将Map转换为字符串格式
switchOidVo.setOtherOID(mapToString(resultMap.get("otherOID")));
switchOidVo.setNetOID(mapToString(resultMap.get("netOID")));
switchOidVo.setModuleOID(mapToString(resultMap.get("moduleOID")));
switchOidVo.setMpuOID(mapToString(resultMap.get("mpuOID")));
switchOidVo.setPwrOID(mapToString(resultMap.get("pwrOID")));
switchOidVo.setFanOID(mapToString(resultMap.get("fanOID")));
switchOidVo.setOtherOID(resultMap.get("otherOID"));
switchOidVo.setNetOID(resultMap.get("netOID"));
switchOidVo.setModuleOID(resultMap.get("moduleOID"));
switchOidVo.setMpuOID(resultMap.get("mpuOID"));
switchOidVo.setPwrOID(resultMap.get("pwrOID"));
switchOidVo.setFanOID(resultMap.get("fanOID"));
switchOidVo.setFilters(filtersMap);
return switchOidVo;
}
@@ -508,7 +541,7 @@ public class RmMonitorPolicyServiceImpl implements IRmMonitorPolicyService
RegisterSwitchVo registerSwitchVo = new RegisterSwitchVo();
registerSwitchVo.setClientIp(clientIp);
registerSwitchVo.setClientPort(Integer.valueOf(clientPort));
registerSwitchVo.setSwitchBoard(JSONObject.toJSONString(switchOidVo));
registerSwitchVo.setSwitchBoard(switchOidVo);
DeviceMessage registerMessage = new DeviceMessage();
registerMessage.setDataType(MsgEnum.注册.getValue());
registerMessage.setData(JSONObject.toJSONString(registerSwitchVo));
@@ -525,8 +558,8 @@ public class RmMonitorPolicyServiceImpl implements IRmMonitorPolicyService
message.setClientId(device.getHardwareSn());
message.setData(configJson);
message.setDataType(MsgEnum.开启交换机采集.getValue());
messageProducer.sendAsyncProducerMessage(
// 待注册后下发策略1秒延迟
messageProducer.sendDelayMessage(
producerMode.getAgentTopic(),
"",
"",

View File

@@ -119,10 +119,10 @@ public class RmResourceRemoteServiceImpl implements IRmResourceRemoteService
JSONObject jsonObject = JSONObject.parseObject(resourceRemote.getDescription());
String command = jsonObject.getString("command");
String resOut = jsonObject.getString("resOut");
String sucOrFail = (!"".equals(resOut) && !"脚本执行失败".equals(resOut)) ? "执行成功":"执行失败";
String sucOrFail = (!"".equals(resOut) && !"脚本执行失败".equals(resOut)) ? "\n执行成功\n":"\n执行失败\n";
StringBuilder resultSb = new StringBuilder();
resultSb.append("").append(resourceRemote.getResourceName()).append("】脚本执行命令:")
.append(command).append(sucOrFail).append(",\n执行结果如下:\n").append(resOut);
resultSb.append("").append(resourceRemote.getResourceName()).append("】脚本执行命令:\n")
.append(command).append(sucOrFail).append(",执行结果如下:\n").append(resOut);
Map<String,Object> map = new HashMap<>();
Date createTime = resourceRemote.getCreateTime();
String createTimeStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", createTime);

View File

@@ -43,6 +43,7 @@
<if test="fileDirectory != null and fileDirectory != ''"> and file_directory = #{fileDirectory}</if>
<if test="lastUpdateResult != null and lastUpdateResult != ''"> and last_update_result = #{lastUpdateResult}</if>
<if test="lastUpdateTime != null "> and last_update_time = #{lastUpdateTime}</if>
<if test="queryName != null and queryName != '' "> and (resource_name like concat('%', #{resourceName}, '%') or internal_ip = #{internalIp})</if>
</where>
</select>
@@ -135,6 +136,7 @@
where hardware_sn = #{hardwareSn}
</update>
<delete id="deleteRmAgentManagementById" parameterType="Long">
delete from rm_agent_management where id = #{id}
</delete>