优化交换机数据采集、脚本策略、agent更新优化、注册增加路由信息
This commit is contained in:
+10
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-1
@@ -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;
|
||||
}
|
||||
|
||||
+29
@@ -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
|
||||
|
||||
-1
@@ -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()));
|
||||
|
||||
Reference in New Issue
Block a user