策略脚本执行返回数据优化
This commit is contained in:
+15
-12
@@ -1,19 +1,22 @@
|
||||
package com.tongran.agent.client.scheduler.task;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.tongran.agent.client.core.enums.MsgEnum;
|
||||
import com.tongran.agent.client.core.session.SessionManager;
|
||||
import com.tongran.agent.client.netty.model.Message;
|
||||
import com.tongran.agent.client.scheduler.service.AsyncCommandExecutor;
|
||||
import com.tongran.agent.client.utils.AgentUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -73,9 +76,9 @@ public class SpecificTimeTaskService {
|
||||
try {
|
||||
System.out.println("处理业务: " + request.getTaskData());
|
||||
|
||||
List<Map<String,String>> list = new ArrayList<>();
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String command : request.getTaskData()) {
|
||||
Map<String,String> map = new HashMap<>();
|
||||
JSONObject json = new JSONObject();
|
||||
if(StringUtils.equals(request.getDataType(), MsgEnum.Agent版本更新应答.getValue())){
|
||||
try {
|
||||
System.out.println("重启进程已启动,当前服务退出");
|
||||
@@ -97,28 +100,28 @@ public class SpecificTimeTaskService {
|
||||
if (result.isSuccess()) {
|
||||
System.out.println("脚本执行成功");
|
||||
System.out.println("[成功resOut] " + result.getOutput());
|
||||
map.put("command",command);
|
||||
map.put("resOut",result.getOutput());
|
||||
json.put("command",command);
|
||||
json.put("resOut",result.getOutput());
|
||||
} else {
|
||||
System.out.println("脚本执行失败");
|
||||
System.out.println("[失败resOut] " + result.getOutput());
|
||||
map.put("command",command);
|
||||
map.put("resOut",result.getOutput());
|
||||
json.put("command",command);
|
||||
json.put("resOut",result.getOutput());
|
||||
}
|
||||
}).exceptionally(ex -> {
|
||||
System.err.println("执行失败: " + ex.getMessage());
|
||||
map.put("command",command);
|
||||
map.put("resOut","Policy execute filed");
|
||||
json.put("command",command);
|
||||
json.put("resOut","Policy execute filed");
|
||||
return null;
|
||||
});
|
||||
list.add(map);
|
||||
list.add(json.toString());
|
||||
}
|
||||
}
|
||||
if(CollectionUtil.isNotEmpty(list)){
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("resCode",1);
|
||||
json.put("resMsg", "");
|
||||
json.put("result", AgentUtil.toJsonString(list));
|
||||
json.put("result", JSON.toJSONString(list));
|
||||
Message message = Message.builder().clientId(request.getClientId()).dataType(request.getDataType()).data(json.toString()).build();
|
||||
if (Objects.nonNull(sessionManager.getSessionById(request.getClientId()))) {
|
||||
sessionManager.writeAndFlush(sessionManager.getSessionById(request.getClientId()).getChannel(), message);
|
||||
|
||||
@@ -30,7 +30,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
||||
@Override
|
||||
public List<SwitchBoardVO> switchBoardList(long timestamp) {
|
||||
List<SwitchBoardVO> list = new ArrayList<>();
|
||||
System.out.println("==================== 交换机流量信息 ====================");
|
||||
// System.out.println("==================== 交换机流量信息 ====================");
|
||||
try {
|
||||
// 1. 创建传输映射
|
||||
TransportMapping transport = new DefaultUdpTransportMapping();
|
||||
@@ -86,7 +86,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
||||
}
|
||||
|
||||
private String handleSwitchNet(){
|
||||
System.out.println("==================== 交换机网络信息 ====================");
|
||||
// System.out.println("==================== 交换机网络信息 ====================");
|
||||
String result = "";
|
||||
try {
|
||||
if(GlobalConfig.SWITCH_NET_OID.isEmpty()){
|
||||
@@ -112,7 +112,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
||||
}
|
||||
|
||||
private String handleSwitchModule(){
|
||||
System.out.println("==================== 交换机光模块信息 ====================");
|
||||
// System.out.println("==================== 交换机光模块信息 ====================");
|
||||
String result = "";
|
||||
try {
|
||||
if(GlobalConfig.SWITCH_MODULE_OID.isEmpty()){
|
||||
@@ -138,7 +138,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
||||
}
|
||||
|
||||
private String handleSwitchMpu(){
|
||||
System.out.println("==================== 交换机MPU信息 ====================");
|
||||
// System.out.println("==================== 交换机MPU信息 ====================");
|
||||
String result = "";
|
||||
try {
|
||||
if(GlobalConfig.SWITCH_MPU_OID.isEmpty()){
|
||||
@@ -164,7 +164,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
||||
}
|
||||
|
||||
private String handleSwitchPwr(){
|
||||
System.out.println("==================== 交换机电源信息 ====================");
|
||||
// System.out.println("==================== 交换机电源信息 ====================");
|
||||
String result = "";
|
||||
try {
|
||||
if(GlobalConfig.SWITCH_PWR_OID.isEmpty()){
|
||||
@@ -190,7 +190,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
||||
}
|
||||
|
||||
private String handleSwitchFan(){
|
||||
System.out.println("==================== 交换机风扇信息 ====================");
|
||||
// System.out.println("==================== 交换机风扇信息 ====================");
|
||||
String result = "";
|
||||
try {
|
||||
if(GlobalConfig.SWITCH_FAN_OID.isEmpty()){
|
||||
@@ -216,7 +216,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
||||
}
|
||||
|
||||
private String handleSwitchOther(String type){
|
||||
System.out.println("==================== 交换机系统其他信息 ====================");
|
||||
// System.out.println("==================== 交换机系统其他信息 ====================");
|
||||
String result = "";
|
||||
try {
|
||||
if(GlobalConfig.SWITCH_OTHER_OID.isEmpty()){
|
||||
@@ -259,7 +259,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
||||
|
||||
ResponseEvent event = snmp.send(pdu, target);
|
||||
if (event != null && event.getResponse() != null) {
|
||||
System.out.println("\n=== 交换机基本信息 ===");
|
||||
// System.out.println("\n=== 交换机基本信息 ===");
|
||||
for (VariableBinding vb : event.getResponse().getVariableBindings()) {
|
||||
System.out.printf("%-30s: %s%n",
|
||||
getOIDDescription(vb.getOid().toString()),
|
||||
@@ -459,8 +459,8 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
||||
}
|
||||
//去重
|
||||
indexes = indexes.stream().distinct().collect(Collectors.toList());
|
||||
System.out.println("\n=== 接口数量: " + indexes.size() + " ===");
|
||||
System.out.println("\n=== 接口列表: " + JSON.toJSONString(indexes));
|
||||
// System.out.println("\n=== 接口数量: " + indexes.size() + " ===");
|
||||
// System.out.println("\n=== 接口列表: " + JSON.toJSONString(indexes));
|
||||
String[] ifOIDs = oidParams.keySet().toArray(new String[0]);
|
||||
String[] params = oidParams.values().toArray(new String[0]);
|
||||
if(!StringUtils.equals(type,"switchNet") && !StringUtils.equals(type,"switchModule")
|
||||
|
||||
Reference in New Issue
Block a user