From 9fa62124e6f030c560a1106c3e79b7ffa2fce041 Mon Sep 17 00:00:00 2001 From: gaoyutao Date: Sun, 28 Sep 2025 09:36:24 +0800 Subject: [PATCH] =?UTF-8?q?rocktmqjson=E4=B8=B2=E5=87=8F=E5=B0=91=E8=BD=AC?= =?UTF-8?q?=E4=B9=89=E6=AC=A1=E6=95=B0=EF=BC=8C=E6=95=B0=E6=8D=AE=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=B8=8E=E6=8E=A5=E6=94=B6=E6=95=B0=E6=8D=AE=E9=80=82?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/InitialSwitchInfoDetails.java | 12 +- .../ruoyi/system/domain/RmResourceGroup.java | 4 + .../system/domain/RmResourceRegistration.java | 2 + .../impl/RmResourceGroupServiceImpl.java | 2 + .../system/RmResourceRegistrationMapper.xml | 1 + .../RmAgentManagementController.java | 30 +---- .../rocketmq/domain/InitialSwitchInfo.java | 12 +- .../domain/InitialSwitchInfoTemp.java | 12 +- .../rocketmq/domain/RmAgentManagement.java | 5 +- .../rocketmq/domain/vo/AgentUpdateVo.java | 5 +- .../rocketmq/domain/vo/RegisterSwitchVo.java | 2 +- .../ruoyi/rocketmq/domain/vo/SwitchOidVo.java | 17 ++- .../handler/DeviceMessageHandler.java | 44 +++++-- .../rocketmq/producer/MessageProducer.java | 3 +- .../service/IRmAgentManagementService.java | 8 ++ .../impl/RmAgentManagementServiceImpl.java | 122 ++++++++++-------- .../impl/RmInitialMonitorItemServiceImpl.java | 8 +- .../impl/RmMonitorPolicyServiceImpl.java | 61 +++++++-- .../impl/RmResourceRemoteServiceImpl.java | 6 +- .../rocketmq/RmAgentManagementMapper.xml | 2 + 20 files changed, 214 insertions(+), 144 deletions(-) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/InitialSwitchInfoDetails.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/InitialSwitchInfoDetails.java index a27a4f0..e7a490b 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/InitialSwitchInfoDetails.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/InitialSwitchInfoDetails.java @@ -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; } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/RmResourceGroup.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/RmResourceGroup.java index c86ed4f..249850b 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/RmResourceGroup.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/RmResourceGroup.java @@ -62,5 +62,9 @@ public class RmResourceGroup extends BaseEntity private String discoveryRules; /** 资源id */ private String resourceIds; + /** 资源类型 */ + private String resourceType; + /** 查询条件名称 */ + private String queryName; } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/RmResourceRegistration.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/RmResourceRegistration.java index 2def466..958c077 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/RmResourceRegistration.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/RmResourceRegistration.java @@ -127,5 +127,7 @@ public class RmResourceRegistration extends BaseEntity private String monitorItems; /** 自动发现项 */ private String discoveryRules; + /** 查询名称 */ + private String queryName; } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RmResourceGroupServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RmResourceGroupServiceImpl.java index b7f31ae..221d9b3 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RmResourceGroupServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RmResourceGroupServiceImpl.java @@ -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 rmResourceRegistrationList = rmResourceRegistrationMapper.selectRmResourceRegistrationList(queryParam); diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/RmResourceRegistrationMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/RmResourceRegistrationMapper.xml index 690db31..9b875b6 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/RmResourceRegistrationMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/RmResourceRegistrationMapper.xml @@ -75,6 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and creator_name like concat('%', #{creatorName}, '%') and updater_id = #{updaterId} and updater_name like concat('%', #{updaterName}, '%') + and (hardware_sn = #{queryName} or resource_name like concat('%', #{queryName}, '%')) order by create_time desc diff --git a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/controller/RmAgentManagementController.java b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/controller/RmAgentManagementController.java index f83f8f9..90971d7 100644 --- a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/controller/RmAgentManagementController.java +++ b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/controller/RmAgentManagementController.java @@ -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 list = rmAgentManagementService.selectRmAgentManagementList(rmAgentManagement); - ExcelUtil util = new ExcelUtil(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)); - } } diff --git a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/InitialSwitchInfo.java b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/InitialSwitchInfo.java index 6f7e3fb..de89f80 100644 --- a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/InitialSwitchInfo.java +++ b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/InitialSwitchInfo.java @@ -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; } diff --git a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/InitialSwitchInfoTemp.java b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/InitialSwitchInfoTemp.java index 80afcc3..02f68ba 100644 --- a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/InitialSwitchInfoTemp.java +++ b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/InitialSwitchInfoTemp.java @@ -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; } diff --git a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/RmAgentManagement.java b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/RmAgentManagement.java index 45a38a6..b2532fa 100644 --- a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/RmAgentManagement.java +++ b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/RmAgentManagement.java @@ -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; } diff --git a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/vo/AgentUpdateVo.java b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/vo/AgentUpdateVo.java index 7db17f9..a3ba97f 100644 --- a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/vo/AgentUpdateVo.java +++ b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/vo/AgentUpdateVo.java @@ -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(); } diff --git a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/vo/RegisterSwitchVo.java b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/vo/RegisterSwitchVo.java index f2389e8..6521078 100644 --- a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/vo/RegisterSwitchVo.java +++ b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/vo/RegisterSwitchVo.java @@ -11,7 +11,7 @@ public class RegisterSwitchVo { /** 服务器端口 */ private Integer clientPort; /** 交换机信息 */ - private String switchBoard; + private SwitchOidVo switchBoard; /** 时间戳(秒) */ private long timestamp = Instant.now().getEpochSecond(); diff --git a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/vo/SwitchOidVo.java b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/vo/SwitchOidVo.java index c987536..af20041 100644 --- a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/vo/SwitchOidVo.java +++ b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/vo/SwitchOidVo.java @@ -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 netOID; + private Map moduleOID; + private Map mpuOID; + private Map pwrOID; + private Map fanOID; + private Map otherOID; /** 团体名 */ private String community; /** ip地址 */ private String ip; /** 端口 */ private Integer port; + /** 过滤值 */ + private Map> filters; } diff --git a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/handler/DeviceMessageHandler.java b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/handler/DeviceMessageHandler.java index ef20060..6bf4272 100644 --- a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/handler/DeviceMessageHandler.java +++ b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/handler/DeviceMessageHandler.java @@ -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 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 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 powerSupplyList = JsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchPowerSupply.class); + List 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 moduleList = JsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchOpticalModule.class); + List 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 mpuList = JsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchMpuInfo.class); + List 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 fanList = JsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchFanInfo.class); + List 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 switchInfos = JsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchInfo.class); + private void handleSwitchNetMessage(CollectDataVo switchDataVo, String clientId) { + List switchInfos = SwitchJsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchInfo.class); if(!switchInfos.isEmpty()){ // 时间戳转换 long timestamp = switchDataVo.getTimestamp(); diff --git a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/producer/MessageProducer.java b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/producer/MessageProducer.java index 3156f69..1fd82ff 100644 --- a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/producer/MessageProducer.java +++ b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/producer/MessageProducer.java @@ -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返回消息是否成功送达 diff --git a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/IRmAgentManagementService.java b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/IRmAgentManagementService.java index 5b6f56f..8e19ae0 100644 --- a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/IRmAgentManagementService.java +++ b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/IRmAgentManagementService.java @@ -44,6 +44,14 @@ public interface IRmAgentManagementService */ public int updateRmAgentManagement(RmAgentManagement rmAgentManagement); + /** + * 保存最后更新结果 + * + * @param rmAgentManagement Agent管理 + * @return 结果 + */ + public void updateRmAgentManagementByHardwareSn(RmAgentManagement rmAgentManagement); + /** * 批量删除Agent管理 * diff --git a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/impl/RmAgentManagementServiceImpl.java b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/impl/RmAgentManagementServiceImpl.java index 7c87995..7fe98ba 100644 --- a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/impl/RmAgentManagementServiceImpl.java +++ b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/impl/RmAgentManagementServiceImpl.java @@ -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 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 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 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 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 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); + } + } } diff --git a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/impl/RmInitialMonitorItemServiceImpl.java b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/impl/RmInitialMonitorItemServiceImpl.java index 44786b5..0da9836 100644 --- a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/impl/RmInitialMonitorItemServiceImpl.java +++ b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/impl/RmInitialMonitorItemServiceImpl.java @@ -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")); } } diff --git a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/impl/RmMonitorPolicyServiceImpl.java b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/impl/RmMonitorPolicyServiceImpl.java index 7c71863..2aff2b9 100644 --- a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/impl/RmMonitorPolicyServiceImpl.java +++ b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/impl/RmMonitorPolicyServiceImpl.java @@ -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 SwitchOidVo processSwitchOids(Map> configs, String[] types) { + // oid集合 Map> resultMap = new HashMap<>(); + // 过滤值集合 + List otherFilterValueList = new ArrayList<>(); + List netFilterValueList = new ArrayList<>(); + List moduleFilterValueList = new ArrayList<>(); + List mpuFilterValueList = new ArrayList<>(); + List pwrFilterValueList = new ArrayList<>(); + List 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> 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(), "", "", diff --git a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/impl/RmResourceRemoteServiceImpl.java b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/impl/RmResourceRemoteServiceImpl.java index 931a619..ad932aa 100644 --- a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/impl/RmResourceRemoteServiceImpl.java +++ b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/service/impl/RmResourceRemoteServiceImpl.java @@ -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 map = new HashMap<>(); Date createTime = resourceRemote.getCreateTime(); String createTimeStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", createTime); diff --git a/ruoyi-rocketmq/src/main/resources/mapper/rocketmq/RmAgentManagementMapper.xml b/ruoyi-rocketmq/src/main/resources/mapper/rocketmq/RmAgentManagementMapper.xml index c99a7b6..c4ba740 100644 --- a/ruoyi-rocketmq/src/main/resources/mapper/rocketmq/RmAgentManagementMapper.xml +++ b/ruoyi-rocketmq/src/main/resources/mapper/rocketmq/RmAgentManagementMapper.xml @@ -43,6 +43,7 @@ and file_directory = #{fileDirectory} and last_update_result = #{lastUpdateResult} and last_update_time = #{lastUpdateTime} + and (resource_name like concat('%', #{resourceName}, '%') or internal_ip = #{internalIp}) @@ -135,6 +136,7 @@ where hardware_sn = #{hardwareSn} + delete from rm_agent_management where id = #{id}