完善资源监控策略内容,新增脚本执行结果查看接口。
This commit is contained in:
+12
-4
@@ -76,11 +76,10 @@ public class RmMonitorPolicyController extends BaseController
|
||||
public AjaxResult add(@RequestBody RmMonitorPolicy rmMonitorPolicy)
|
||||
{
|
||||
int rows = rmMonitorPolicyService.addRmMonitorPolicy(rmMonitorPolicy);
|
||||
if(rows>0){
|
||||
return toAjax(rows);
|
||||
}else{
|
||||
if(rows == -1){
|
||||
return AjaxResult.error("资源监控策略新增失败,该资源组已绑定其他策略");
|
||||
}
|
||||
return toAjax(rows);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,5 +102,14 @@ public class RmMonitorPolicyController extends BaseController
|
||||
{
|
||||
return toAjax(rmMonitorPolicyService.issuePolicy(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除监控模板
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:policy:remove")
|
||||
@Log(title = "资源监控策略", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(rmMonitorPolicyService.deleteRmMonitorPolicyByIds(ids));
|
||||
}
|
||||
}
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.ruoyi.rocketmq.controller;
|
||||
|
||||
import com.ruoyi.common.core.web.controller.BaseController;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||
import com.ruoyi.rocketmq.domain.RmResourceRemote;
|
||||
import com.ruoyi.rocketmq.service.IRmResourceRemoteService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 资源远程管理Controller
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-15
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/remote")
|
||||
public class RmResourceRemoteController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IRmResourceRemoteService rmResourceRemoteService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取资源远程管理详细信息
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:remote:query")
|
||||
@PostMapping(value = "/getScriptResultBySn")
|
||||
public AjaxResult getScriptResultBySn(@RequestBody RmResourceRemote rmResourceRemote)
|
||||
{
|
||||
return success(rmResourceRemoteService.getScriptResultBySn(rmResourceRemote));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -24,8 +24,10 @@ public class RmMonitorPolicy extends BaseEntity
|
||||
private Long id;
|
||||
|
||||
/** 模板ID */
|
||||
@Excel(name = "模板ID")
|
||||
private Long templateId;
|
||||
/** 模板名称 */
|
||||
@Excel(name = "关联监控模板")
|
||||
private String templateName;
|
||||
|
||||
/** 资源组ID */
|
||||
@Excel(name = "资源组ID")
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.ruoyi.rocketmq.domain;
|
||||
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 资源远程管理对象 rm_resource_remote
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-15
|
||||
*/
|
||||
@Data
|
||||
public class RmResourceRemote extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 资源ID */
|
||||
private Long id;
|
||||
|
||||
/** 硬件SN码 */
|
||||
@Excel(name = "硬件SN码")
|
||||
private String hardwareSn;
|
||||
|
||||
/** 资源类型 */
|
||||
@Excel(name = "资源类型")
|
||||
private String resourceType;
|
||||
|
||||
/** 资源名称 */
|
||||
@Excel(name = "资源名称")
|
||||
private String resourceName;
|
||||
|
||||
/** 资源描述 */
|
||||
@Excel(name = "资源描述")
|
||||
private String description;
|
||||
|
||||
/** 内网IP地址 */
|
||||
@Excel(name = "内网IP地址")
|
||||
private String internalIp;
|
||||
|
||||
/** 外网IP地址 */
|
||||
@Excel(name = "外网IP地址")
|
||||
private String externalIp;
|
||||
|
||||
/** 管理端口号 */
|
||||
@Excel(name = "管理端口号")
|
||||
private Integer managementPort;
|
||||
|
||||
/** 在线状态:0-离线,1-在线 */
|
||||
@Excel(name = "在线状态:0-离线,1-在线")
|
||||
private String onlineStatus;
|
||||
|
||||
/** 连接方式(SSH/Telnet/RDP等) */
|
||||
@Excel(name = "连接方式", readConverterExp = "S=SH/Telnet/RDP等")
|
||||
private String connectionMethod;
|
||||
/** 脚本执行结果 */
|
||||
private String commandResult;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.ruoyi.rocketmq.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.rocketmq.domain.RmResourceRemote;
|
||||
|
||||
/**
|
||||
* 资源远程管理Mapper接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-15
|
||||
*/
|
||||
public interface RmResourceRemoteMapper
|
||||
{
|
||||
/**
|
||||
* 查询资源远程管理
|
||||
*
|
||||
* @param id 资源远程管理主键
|
||||
* @return 资源远程管理
|
||||
*/
|
||||
public RmResourceRemote selectRmResourceRemoteById(Long id);
|
||||
|
||||
/**
|
||||
* 查询资源远程管理列表
|
||||
*
|
||||
* @param rmResourceRemote 资源远程管理
|
||||
* @return 资源远程管理集合
|
||||
*/
|
||||
public List<RmResourceRemote> selectRmResourceRemoteList(RmResourceRemote rmResourceRemote);
|
||||
|
||||
/**
|
||||
* 新增资源远程管理
|
||||
*
|
||||
* @param rmResourceRemote 资源远程管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmResourceRemote(RmResourceRemote rmResourceRemote);
|
||||
|
||||
/**
|
||||
* 修改资源远程管理
|
||||
*
|
||||
* @param rmResourceRemote 资源远程管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmResourceRemote(RmResourceRemote rmResourceRemote);
|
||||
|
||||
/**
|
||||
* 删除资源远程管理
|
||||
*
|
||||
* @param id 资源远程管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmResourceRemoteById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除资源远程管理
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmResourceRemoteByIds(Long[] ids);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.ruoyi.rocketmq.service;
|
||||
|
||||
import com.ruoyi.rocketmq.domain.RmResourceRemote;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 资源远程管理Service接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-15
|
||||
*/
|
||||
public interface IRmResourceRemoteService
|
||||
{
|
||||
/**
|
||||
* 查询资源远程管理
|
||||
*
|
||||
* @param id 资源远程管理主键
|
||||
* @return 资源远程管理
|
||||
*/
|
||||
public RmResourceRemote selectRmResourceRemoteById(Long id);
|
||||
|
||||
/**
|
||||
* 查询资源远程管理列表
|
||||
*
|
||||
* @param rmResourceRemote 资源远程管理
|
||||
* @return 资源远程管理集合
|
||||
*/
|
||||
public List<RmResourceRemote> selectRmResourceRemoteList(RmResourceRemote rmResourceRemote);
|
||||
|
||||
/**
|
||||
* 新增资源远程管理
|
||||
*
|
||||
* @param rmResourceRemote 资源远程管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmResourceRemote(RmResourceRemote rmResourceRemote);
|
||||
|
||||
/**
|
||||
* 修改资源远程管理
|
||||
*
|
||||
* @param rmResourceRemote 资源远程管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmResourceRemote(RmResourceRemote rmResourceRemote);
|
||||
|
||||
/**
|
||||
* 批量删除资源远程管理
|
||||
*
|
||||
* @param ids 需要删除的资源远程管理主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmResourceRemoteByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除资源远程管理信息
|
||||
*
|
||||
* @param id 资源远程管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmResourceRemoteById(Long id);
|
||||
|
||||
Map<String,Object> getScriptResultBySn(RmResourceRemote rmResourceRemote);
|
||||
}
|
||||
+10
-1
@@ -78,7 +78,16 @@ public class RmMonitorPolicyServiceImpl implements IRmMonitorPolicyService
|
||||
@Override
|
||||
public List<RmMonitorPolicy> selectRmMonitorPolicyList(RmMonitorPolicy rmMonitorPolicy)
|
||||
{
|
||||
return rmMonitorPolicyMapper.selectRmMonitorPolicyList(rmMonitorPolicy);
|
||||
List<RmMonitorPolicy> list = rmMonitorPolicyMapper.selectRmMonitorPolicyList(rmMonitorPolicy);
|
||||
for (RmMonitorPolicy monitorPolicy : list) {
|
||||
// 资源组名称
|
||||
monitorPolicy.setResourceGroupName(dataProcessUtil.getResourceGroupNameById(monitorPolicy.getResourceGroupId()));
|
||||
// 模板名称
|
||||
Long templateId = monitorPolicy.getTemplateId();
|
||||
RmMonitorTemplate rmMonitorTemplate = rmMonitorTemplateMapper.selectRmMonitorTemplateById(templateId);
|
||||
monitorPolicy.setTemplateName(rmMonitorTemplate.getTemplateName());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
package com.ruoyi.rocketmq.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.rocketmq.domain.RmResourceRemote;
|
||||
import com.ruoyi.rocketmq.mapper.RmResourceRemoteMapper;
|
||||
import com.ruoyi.rocketmq.service.IRmResourceRemoteService;
|
||||
import com.ruoyi.system.api.RemoteRevenueConfigService;
|
||||
import com.ruoyi.system.api.domain.RmResourceRegistrationRemote;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 资源远程管理Service业务层处理
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-15
|
||||
*/
|
||||
@Service
|
||||
public class RmResourceRemoteServiceImpl implements IRmResourceRemoteService
|
||||
{
|
||||
@Autowired
|
||||
private RmResourceRemoteMapper rmResourceRemoteMapper;
|
||||
@Autowired
|
||||
private RemoteRevenueConfigService remoteRevenueConfigService;
|
||||
|
||||
/**
|
||||
* 查询资源远程管理
|
||||
*
|
||||
* @param id 资源远程管理主键
|
||||
* @return 资源远程管理
|
||||
*/
|
||||
@Override
|
||||
public RmResourceRemote selectRmResourceRemoteById(Long id)
|
||||
{
|
||||
return rmResourceRemoteMapper.selectRmResourceRemoteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询资源远程管理列表
|
||||
*
|
||||
* @param rmResourceRemote 资源远程管理
|
||||
* @return 资源远程管理
|
||||
*/
|
||||
@Override
|
||||
public List<RmResourceRemote> selectRmResourceRemoteList(RmResourceRemote rmResourceRemote)
|
||||
{
|
||||
return rmResourceRemoteMapper.selectRmResourceRemoteList(rmResourceRemote);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增资源远程管理
|
||||
*
|
||||
* @param rmResourceRemote 资源远程管理
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertRmResourceRemote(RmResourceRemote rmResourceRemote)
|
||||
{
|
||||
return rmResourceRemoteMapper.insertRmResourceRemote(rmResourceRemote);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改资源远程管理
|
||||
*
|
||||
* @param rmResourceRemote 资源远程管理
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateRmResourceRemote(RmResourceRemote rmResourceRemote)
|
||||
{
|
||||
rmResourceRemote.setUpdateTime(DateUtils.getNowDate());
|
||||
return rmResourceRemoteMapper.updateRmResourceRemote(rmResourceRemote);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除资源远程管理
|
||||
*
|
||||
* @param ids 需要删除的资源远程管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmResourceRemoteByIds(Long[] ids)
|
||||
{
|
||||
return rmResourceRemoteMapper.deleteRmResourceRemoteByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除资源远程管理信息
|
||||
*
|
||||
* @param id 资源远程管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmResourceRemoteById(Long id)
|
||||
{
|
||||
return rmResourceRemoteMapper.deleteRmResourceRemoteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getScriptResultBySn(RmResourceRemote rmResourceRemote) {
|
||||
// 构建返回结果
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
// 资源详情
|
||||
RmResourceRegistrationRemote queryParam = new RmResourceRegistrationRemote();
|
||||
queryParam.setHardwareSn(rmResourceRemote.getHardwareSn());
|
||||
R<RmResourceRegistrationRemote> registrationRemote = remoteRevenueConfigService.getListByHardwareSn(queryParam, SecurityConstants.INNER);
|
||||
RmResourceRegistrationRemote resourceMsg = registrationRemote.getData();
|
||||
resultMap.put("resourceMsg", resourceMsg);
|
||||
// 脚本执行结果构建
|
||||
List<Map<String, Object>> scriptList = new ArrayList<>();
|
||||
List<RmResourceRemote> reslutList = rmResourceRemoteMapper.selectRmResourceRemoteList(rmResourceRemote);
|
||||
for (RmResourceRemote resourceRemote : reslutList) {
|
||||
// 脚本执行返回结果
|
||||
JSONObject jsonObject = JSONObject.parseObject(resourceRemote.getDescription());
|
||||
String command = jsonObject.getString("command");
|
||||
String resOut = jsonObject.getString("resOut");
|
||||
String sucOrFail = (!"".equals(resOut) && !"脚本执行失败".equals(resOut)) ? "执行成功":"执行失败";
|
||||
StringBuilder resultSb = new StringBuilder();
|
||||
resultSb.append("【").append(resourceRemote.getResourceName()).append("】脚本执行命令:")
|
||||
.append(command).append(sucOrFail).append(",\n执行结果如下:\n").append(resOut);
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
Date createTime = resourceRemote.getCreateTime();
|
||||
String createTimeStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", createTime);
|
||||
map.put("createTime", createTimeStr);
|
||||
map.put("content", resultSb);
|
||||
scriptList.add(map);
|
||||
}
|
||||
resultMap.put("scriptResult", scriptList);
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,7 @@ public class DataProcessUtil {
|
||||
linuxData.put("docker", filterItemsByDataType(linuxItems, "DOCKER"));
|
||||
|
||||
result.put("linux", linuxData);
|
||||
result.put("resourceType", "linux");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +102,7 @@ public class DataProcessUtil {
|
||||
switchData.put("switchFan", filterItemsByDataType(switchItems, "FAN"));
|
||||
|
||||
result.put("switch", switchData);
|
||||
result.put("resourceType", "switch");
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user