Compare commits
10
Commits
b07abc881d
...
e58137c319
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e58137c319 | ||
|
|
6bae49ee3b | ||
|
|
110932509a | ||
|
|
394e6b807c | ||
|
|
26daf92261 | ||
|
|
da16318bf5 | ||
|
|
321235fc23 | ||
|
|
179e29d9a5 | ||
|
|
72626c2b69 | ||
|
|
6c098b3950 |
@@ -60,93 +60,118 @@ public class AgentEndpoint {
|
||||
}
|
||||
if(jsonObject.containsKey("netOID")){
|
||||
String netOID = jsonObject.getString("netOID");
|
||||
LinkedHashMap<String, String> map = JSON.parseObject(netOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
||||
GlobalConfig.SWITCH_NET_OID = map;
|
||||
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
||||
if(m.containsKey(GlobalConfig.NET_INDEX_PARAM)){
|
||||
GlobalConfig.NET_INDEX_OID = m.get(GlobalConfig.NET_INDEX_PARAM);
|
||||
if(StringUtils.isNotBlank(netOID)){
|
||||
LinkedHashMap<String, String> map = JSON.parseObject(netOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
||||
GlobalConfig.SWITCH_NET_OID = map;
|
||||
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
||||
if(m.containsKey(GlobalConfig.NET_INDEX_PARAM)){
|
||||
GlobalConfig.NET_INDEX_OID = m.get(GlobalConfig.NET_INDEX_PARAM);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(jsonObject.containsKey("moduleOID")){
|
||||
String moduleOID = jsonObject.getString("moduleOID");
|
||||
LinkedHashMap<String, String> map = JSON.parseObject(moduleOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
||||
GlobalConfig.SWITCH_MODULE_OID = map;
|
||||
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
||||
if(m.containsKey(GlobalConfig.MODULE_INDEX_PARAM)){
|
||||
GlobalConfig.MODULE_INDEX_OID = m.get(GlobalConfig.MODULE_INDEX_PARAM);
|
||||
if(StringUtils.isNotBlank(moduleOID)){
|
||||
LinkedHashMap<String, String> map = JSON.parseObject(moduleOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
||||
GlobalConfig.SWITCH_MODULE_OID = map;
|
||||
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
||||
if(m.containsKey(GlobalConfig.MODULE_INDEX_PARAM)){
|
||||
GlobalConfig.MODULE_INDEX_OID = m.get(GlobalConfig.MODULE_INDEX_PARAM);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if(jsonObject.containsKey("mpuOID")){
|
||||
String mpuOID = jsonObject.getString("mpuOID");
|
||||
LinkedHashMap<String, String> map = JSON.parseObject(mpuOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
||||
GlobalConfig.SWITCH_MPU_OID = map;
|
||||
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
||||
if(m.containsKey(GlobalConfig.MPU_INDEX_PARAM)){
|
||||
GlobalConfig.MPU_INDEX_OID = m.get(GlobalConfig.MPU_INDEX_PARAM);
|
||||
if(StringUtils.isNotBlank(mpuOID)){
|
||||
LinkedHashMap<String, String> map = JSON.parseObject(mpuOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
||||
GlobalConfig.SWITCH_MPU_OID = map;
|
||||
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
||||
if(m.containsKey(GlobalConfig.MPU_INDEX_PARAM)){
|
||||
GlobalConfig.MPU_INDEX_OID = m.get(GlobalConfig.MPU_INDEX_PARAM);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(jsonObject.containsKey("pwrOID")){
|
||||
String pwrOID = jsonObject.getString("pwrOID");
|
||||
LinkedHashMap<String, String> map = JSON.parseObject(pwrOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
||||
GlobalConfig.SWITCH_PWR_OID = map;
|
||||
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
||||
if(m.containsKey(GlobalConfig.PWR_INDEX_PARAM)){
|
||||
GlobalConfig.PWR_INDEX_OID = m.get(GlobalConfig.PWR_INDEX_PARAM);
|
||||
if(StringUtils.isNotBlank(pwrOID)){
|
||||
LinkedHashMap<String, String> map = JSON.parseObject(pwrOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
||||
GlobalConfig.SWITCH_PWR_OID = map;
|
||||
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
||||
if(m.containsKey(GlobalConfig.PWR_INDEX_PARAM)){
|
||||
GlobalConfig.PWR_INDEX_OID = m.get(GlobalConfig.PWR_INDEX_PARAM);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(jsonObject.containsKey("fanOID")){
|
||||
String fanOID = jsonObject.getString("fanOID");
|
||||
LinkedHashMap<String, String> map = JSON.parseObject(fanOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
||||
GlobalConfig.SWITCH_FAN_OID = map;
|
||||
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
||||
if(m.containsKey(GlobalConfig.FAN_INDEX_PARAM)){
|
||||
GlobalConfig.FAN_INDEX_OID = m.get(GlobalConfig.FAN_INDEX_PARAM);
|
||||
if(StringUtils.isNotBlank(fanOID)){
|
||||
LinkedHashMap<String, String> map = JSON.parseObject(fanOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
||||
GlobalConfig.SWITCH_FAN_OID = map;
|
||||
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
||||
if(m.containsKey(GlobalConfig.FAN_INDEX_PARAM)){
|
||||
GlobalConfig.FAN_INDEX_OID = m.get(GlobalConfig.FAN_INDEX_PARAM);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(jsonObject.containsKey("otherOID")){
|
||||
String otherOID = jsonObject.getString("otherOID");
|
||||
LinkedHashMap<String, String> map = JSON.parseObject(otherOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
||||
GlobalConfig.SWITCH_OTHER_OID = map;
|
||||
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
||||
if(m.containsKey(GlobalConfig.OTHER_INDEX_PARAM)){
|
||||
GlobalConfig.OTHER_INDEX_OID = m.get(GlobalConfig.OTHER_INDEX_PARAM);
|
||||
if(StringUtils.isNotBlank(otherOID)){
|
||||
LinkedHashMap<String, String> map = JSON.parseObject(otherOID, new TypeReference<LinkedHashMap<String, String>>() {});
|
||||
GlobalConfig.SWITCH_OTHER_OID = map;
|
||||
LinkedHashMap<String,String> m = AgentUtil.swapMap(map);
|
||||
if(m.containsKey(GlobalConfig.OTHER_INDEX_PARAM)){
|
||||
GlobalConfig.OTHER_INDEX_OID = m.get(GlobalConfig.OTHER_INDEX_PARAM);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(jsonObject.containsKey("filters")){
|
||||
String filters = jsonObject.getString("filters");
|
||||
JSONObject object = JSONObject.parseObject(filters);
|
||||
|
||||
if(object.containsKey("netOID")){
|
||||
String netOID = object.getString("netOID");
|
||||
List<String> list = JSON.parseObject(netOID, new TypeReference<List<String>>() {});
|
||||
GlobalConfig.NET_FILTER = list;
|
||||
if(StringUtils.isNotBlank(filters)){
|
||||
JSONObject object = JSONObject.parseObject(filters);
|
||||
if(object.containsKey("netOID")){
|
||||
String netOID = object.getString("netOID");
|
||||
if(StringUtils.isNotBlank(netOID)){
|
||||
List<String> list = JSON.parseObject(netOID, new TypeReference<List<String>>() {});
|
||||
GlobalConfig.NET_FILTER = list;
|
||||
}
|
||||
}
|
||||
if(object.containsKey("moduleOID")){
|
||||
String moduleOID = object.getString("moduleOID");
|
||||
if(StringUtils.isNotBlank(moduleOID)){
|
||||
List<String> list = JSON.parseObject(moduleOID, new TypeReference<List<String>>() {});
|
||||
GlobalConfig.MODULE_FILTER = list;
|
||||
}
|
||||
}
|
||||
if(object.containsKey("mpuOID")){
|
||||
String mpuOID = object.getString("mpuOID");
|
||||
if(StringUtils.isNotBlank(mpuOID)){
|
||||
List<String> list = JSON.parseObject(mpuOID, new TypeReference<List<String>>() {});
|
||||
GlobalConfig.MPU_FILTER = list;
|
||||
}
|
||||
}
|
||||
if(object.containsKey("pwrOID")){
|
||||
String pwrOID = object.getString("pwrOID");
|
||||
if(StringUtils.isNotBlank(pwrOID)){
|
||||
List<String> list = JSON.parseObject(pwrOID, new TypeReference<List<String>>() {});
|
||||
GlobalConfig.PWR_FILTER = list;
|
||||
}
|
||||
}
|
||||
if(object.containsKey("fanOID")){
|
||||
String fanOID = object.getString("fanOID");
|
||||
if(StringUtils.isNotBlank(fanOID)){
|
||||
List<String> list = JSON.parseObject(fanOID, new TypeReference<List<String>>() {});
|
||||
GlobalConfig.FAN_FILTER = list;
|
||||
}
|
||||
}
|
||||
if(object.containsKey("otherOID")){
|
||||
String otherOID = object.getString("otherOID");
|
||||
if(StringUtils.isNotBlank(otherOID)){
|
||||
List<String> list = JSON.parseObject(otherOID, new TypeReference<List<String>>() {});
|
||||
GlobalConfig.OTHER_FILTER = list;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(object.containsKey("moduleOID")){
|
||||
String moduleOID = object.getString("moduleOID");
|
||||
List<String> list = JSON.parseObject(moduleOID, new TypeReference<List<String>>() {});
|
||||
GlobalConfig.MODULE_FILTER = list;
|
||||
}
|
||||
if(object.containsKey("mpuOID")){
|
||||
String mpuOID = object.getString("mpuOID");
|
||||
List<String> list = JSON.parseObject(mpuOID, new TypeReference<List<String>>() {});
|
||||
GlobalConfig.MPU_FILTER = list;
|
||||
}
|
||||
if(object.containsKey("pwrOID")){
|
||||
String pwrOID = object.getString("pwrOID");
|
||||
List<String> list = JSON.parseObject(pwrOID, new TypeReference<List<String>>() {});
|
||||
GlobalConfig.PWR_FILTER = list;
|
||||
}
|
||||
if(object.containsKey("fanOID")){
|
||||
String fanOID = object.getString("fanOID");
|
||||
List<String> list = JSON.parseObject(fanOID, new TypeReference<List<String>>() {});
|
||||
GlobalConfig.FAN_FILTER = list;
|
||||
}
|
||||
if(object.containsKey("otherOID")){
|
||||
String otherOID = object.getString("otherOID");
|
||||
List<String> list = JSON.parseObject(otherOID, new TypeReference<List<String>>() {});
|
||||
GlobalConfig.OTHER_FILTER = list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -266,12 +291,14 @@ public class AgentEndpoint {
|
||||
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||
if(jsonObject.containsKey("alarms")){
|
||||
String alarms = jsonObject.getString("alarms");
|
||||
AssertLog.info("告警设置,alarms={}", alarms);
|
||||
GlobalConfig.ALARM_LIST = JSON.parseObject(alarms, new TypeReference<List<AlarmEO>>() {});
|
||||
AssertLog.info("告警设置,监控项={}", JSON.toJSONString(GlobalConfig.ALARM_LIST));
|
||||
if(CollectionUtil.isNotEmpty(GlobalConfig.ALARM_LIST)){
|
||||
AssertLog.info("告警设置,is_alarm={}", AgentDataUtil.hasAnyActiveAlarm(GlobalConfig.ALARM_LIST));
|
||||
GlobalConfig.IS_ALARM = AgentDataUtil.hasAnyActiveAlarm(GlobalConfig.ALARM_LIST);
|
||||
if(StringUtils.isNotBlank(alarms)){
|
||||
AssertLog.info("告警设置,alarms={}", alarms);
|
||||
GlobalConfig.ALARM_LIST = JSON.parseObject(alarms, new TypeReference<List<AlarmEO>>() {});
|
||||
AssertLog.info("告警设置,监控项={}", JSON.toJSONString(GlobalConfig.ALARM_LIST));
|
||||
if(CollectionUtil.isNotEmpty(GlobalConfig.ALARM_LIST)){
|
||||
AssertLog.info("告警设置,is_alarm={}", AgentDataUtil.hasAnyActiveAlarm(GlobalConfig.ALARM_LIST));
|
||||
GlobalConfig.IS_ALARM = AgentDataUtil.hasAnyActiveAlarm(GlobalConfig.ALARM_LIST);
|
||||
}
|
||||
}
|
||||
}
|
||||
agentService.alarmMonitor();
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.tongran.agent.client.netty.handler;
|
||||
import com.tongran.agent.client.core.config.GlobalConfig;
|
||||
import com.tongran.agent.client.core.session.SessionManager;
|
||||
import com.tongran.agent.client.scheduler.service.AppInitializer;
|
||||
import com.tongran.agent.client.service.AgentService;
|
||||
import com.tongran.agent.client.utils.AssertLog;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
@@ -26,6 +27,9 @@ public class TCPListenHandler extends ChannelInboundHandlerAdapter {
|
||||
|
||||
private final SessionManager sessionManager;
|
||||
|
||||
@Resource
|
||||
private AgentService agentService;
|
||||
|
||||
public TCPListenHandler() {
|
||||
this.sessionManager = SessionManager.getInstance();
|
||||
}
|
||||
@@ -41,6 +45,7 @@ public class TCPListenHandler extends ChannelInboundHandlerAdapter {
|
||||
sessionManager.remove(ctx.channel());
|
||||
try {
|
||||
GlobalConfig.isCollect = false;
|
||||
agentService.cancelCollect();
|
||||
appInitializer.run();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -51,6 +56,7 @@ public class TCPListenHandler extends ChannelInboundHandlerAdapter {
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) {
|
||||
if (e instanceof IOException) {
|
||||
AssertLog.info("<<<<<<[终端断开连接]{} {}", sessionManager.client(ctx), e.getMessage());
|
||||
agentService.cancelCollect();
|
||||
} else {
|
||||
AssertLog.info(">>>>>>[消息处理异常]" + sessionManager.client(ctx), e);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
@@ -16,7 +17,7 @@ public class SchedulerConfig {
|
||||
@Bean
|
||||
public ThreadPoolTaskScheduler taskScheduler() {
|
||||
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
||||
scheduler.setPoolSize(10); // 核心线程数
|
||||
scheduler.setPoolSize(50); // 核心线程数
|
||||
scheduler.setThreadNamePrefix("dynamic-scheduler-");
|
||||
scheduler.setAwaitTerminationSeconds(60);
|
||||
scheduler.setWaitForTasksToCompleteOnShutdown(true);
|
||||
@@ -24,14 +25,31 @@ public class SchedulerConfig {
|
||||
scheduler.setRemoveOnCancelPolicy(true);
|
||||
return scheduler;
|
||||
}
|
||||
// @Bean("taskExecutor")
|
||||
// public ThreadPoolTaskScheduler taskExecutor() {
|
||||
// ThreadPoolTaskScheduler executor = new ThreadPoolTaskScheduler();
|
||||
// executor.setPoolSize(50); // 工作线程数
|
||||
// executor.setThreadNamePrefix("task-worker-");
|
||||
// executor.setAwaitTerminationSeconds(30);
|
||||
// executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
// return executor;
|
||||
// }
|
||||
|
||||
@Bean("taskExecutor")
|
||||
public ThreadPoolTaskScheduler taskExecutor() {
|
||||
ThreadPoolTaskScheduler executor = new ThreadPoolTaskScheduler();
|
||||
executor.setPoolSize(11); // 工作线程数
|
||||
public ThreadPoolTaskExecutor taskExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
// 核心配置
|
||||
executor.setCorePoolSize(44);
|
||||
executor.setMaxPoolSize(60);
|
||||
executor.setQueueCapacity(100);
|
||||
executor.setKeepAliveSeconds(60);
|
||||
// 线程配置
|
||||
executor.setThreadNamePrefix("task-worker-");
|
||||
executor.setAwaitTerminationSeconds(30);
|
||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
// 拒绝策略
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.initialize(); // 重要:必须调用initialize()
|
||||
return executor;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -55,16 +55,25 @@ public class DynamicTaskService {
|
||||
lastExecutionTimes.put(taskId, startTime);
|
||||
|
||||
try {
|
||||
System.out.printf("开始执行任务: %s, 线程: %s%n",
|
||||
taskId, Thread.currentThread().getName());
|
||||
// 添加前置检查
|
||||
if (originalTask == null) {
|
||||
throw new IllegalArgumentException("原始任务不能为null");
|
||||
}
|
||||
originalTask.run();
|
||||
System.out.printf("任务 %s 执行成功%n", taskId);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Task " + taskId + " execution failed: " + e.getMessage());
|
||||
System.err.printf("任务 %s 执行失败: %s%n", taskId, e.getMessage());
|
||||
// System.err.println("Task " + taskId + " execution failed: " + e.getMessage());
|
||||
} finally {
|
||||
long endTime = System.currentTimeMillis();
|
||||
long executionTime = endTime - startTime;
|
||||
taskExecutions.get(taskId).incrementAndGet();
|
||||
|
||||
System.out.printf("Task %s executed in %dms, total executions: %d%n",
|
||||
taskId, executionTime, taskExecutions.get(taskId).get());
|
||||
// System.out.printf("Task %s executed in %dms, total executions: %d%n",
|
||||
// taskId, executionTime, taskExecutions.get(taskId).get());
|
||||
System.out.printf("任务 %s 执行耗时: %dms, 总执行次数: %d%n",
|
||||
taskId, executionTime, taskExecutions.get(taskId).get());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+27
-29
@@ -1,19 +1,20 @@
|
||||
package com.tongran.agent.client.scheduler.task;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
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.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -72,10 +73,8 @@ public class SpecificTimeTaskService {
|
||||
// 实现你的业务逻辑
|
||||
try {
|
||||
System.out.println("处理业务: " + request.getTaskData());
|
||||
|
||||
List<Map<String,String>> list = new ArrayList<>();
|
||||
String key = request.getTaskName()+"-"+System.currentTimeMillis();
|
||||
for (String command : request.getTaskData()) {
|
||||
Map<String,String> map = new HashMap<>();
|
||||
if(StringUtils.equals(request.getDataType(), MsgEnum.Agent版本更新应答.getValue())){
|
||||
try {
|
||||
System.out.println("重启进程已启动,当前服务退出");
|
||||
@@ -94,34 +93,33 @@ public class SpecificTimeTaskService {
|
||||
cmd,
|
||||
100, TimeUnit.SECONDS);
|
||||
future.thenAccept(result -> {
|
||||
if (result.isSuccess()) {
|
||||
System.out.println("脚本执行成功");
|
||||
System.out.println("[成功resOut] " + result.getOutput());
|
||||
map.put("command",command);
|
||||
map.put("resOut",result.getOutput());
|
||||
} else {
|
||||
System.out.println("脚本执行失败");
|
||||
System.out.println("[失败resOut] " + result.getOutput());
|
||||
map.put("command",command);
|
||||
map.put("resOut",result.getOutput());
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("command", command);
|
||||
jsonObject.put("resOut", result.getOutput());
|
||||
System.out.println("JSON: " + jsonObject.toJSONString()); // 注意:toJSONString()
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("resCode",1);
|
||||
json.put("resMsg", "");
|
||||
json.put("result", jsonObject.toJSONString());
|
||||
json.put("timestamp", Instant.now().getEpochSecond());
|
||||
Message message = Message.builder().clientId(request.getClientId()).dataType(request.getDataType()).data(json.toJSONString()).build();
|
||||
if (Objects.nonNull(sessionManager.getSessionById(request.getClientId()))) {
|
||||
System.out.println("发送执行结果: " + json.toJSONString()); // 注意:toJSONString()
|
||||
sessionManager.writeAndFlush(sessionManager.getSessionById(request.getClientId()).getChannel(), message);
|
||||
}
|
||||
}).exceptionally(ex -> {
|
||||
System.err.println("执行失败: " + ex.getMessage());
|
||||
map.put("command",command);
|
||||
map.put("resOut","Policy execute filed");
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("resCode",0);
|
||||
json.put("resMsg", "执行失败:Policy execute filed");
|
||||
json.put("result", "");
|
||||
Message message = Message.builder().clientId(request.getClientId()).dataType(request.getDataType()).data(json.toJSONString()).build();
|
||||
if (Objects.nonNull(sessionManager.getSessionById(request.getClientId()))) {
|
||||
sessionManager.writeAndFlush(sessionManager.getSessionById(request.getClientId()).getChannel(), message);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
list.add(map);
|
||||
}
|
||||
}
|
||||
if(CollectionUtil.isNotEmpty(list)){
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("resCode",1);
|
||||
json.put("resMsg", "");
|
||||
json.put("result", AgentUtil.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);
|
||||
}
|
||||
}
|
||||
// 调用其他服务等
|
||||
|
||||
@@ -106,7 +106,7 @@ public class AgentServiceImpl implements AgentService {
|
||||
if(GlobalConfig.netCollect != collect || GlobalConfig.netInterval != interval){
|
||||
GlobalConfig.netCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.netInterval = interval;
|
||||
// GlobalConfig.netInterval = interval;
|
||||
long milli = AgentUtil.millisecondsToNext5Minute();
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::netTask, milli, GlobalConfig.netInterval*1000L);
|
||||
@@ -144,187 +144,241 @@ public class AgentServiceImpl implements AgentService {
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: //系统其他采集
|
||||
boolean flag = false;
|
||||
if(StringUtils.equals(type, "systemSwapSizeFreeCollect")){
|
||||
if(GlobalConfig.systemSwapSizeFreeCollect != collect || GlobalConfig.systemSwapSizeFreeInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemSwapSizeFreeCollect = collect;
|
||||
GlobalConfig.systemSwapSizeFreeInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.systemSwapSizeFreeInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "memoryUtilizationCollect")){
|
||||
if(GlobalConfig.memoryUtilizationCollect != collect || GlobalConfig.memoryUtilizationInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.memoryUtilizationCollect = collect;
|
||||
GlobalConfig.memoryUtilizationInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.memoryUtilizationInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "systemSwapSizePercentCollect")){
|
||||
if(GlobalConfig.systemSwapSizePercentCollect != collect || GlobalConfig.systemSwapSizePercentInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemSwapSizePercentCollect = collect;
|
||||
GlobalConfig.systemSwapSizePercentInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.systemSwapSizePercentInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "memorySizeAvailableCollect")){
|
||||
if(GlobalConfig.memorySizeAvailableCollect != collect || GlobalConfig.memorySizeAvailableInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.memorySizeAvailableCollect = collect;
|
||||
GlobalConfig.memorySizeAvailableInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.memorySizeAvailableInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "memorySizePercentCollect")){
|
||||
if(GlobalConfig.memorySizePercentCollect != collect || GlobalConfig.memorySizePercentInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.memorySizePercentCollect = collect;
|
||||
GlobalConfig.memorySizePercentInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.memorySizePercentInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "memorySizeTotalCollect")){
|
||||
if(GlobalConfig.memorySizeTotalCollect != collect || GlobalConfig.memorySizeTotalInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.memorySizeTotalCollect = collect;
|
||||
GlobalConfig.memorySizeTotalInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.memorySizeTotalInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "systemSwOsCollect")){
|
||||
if(GlobalConfig.systemSwOsCollect != collect || GlobalConfig.systemSwOsInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemSwOsCollect = collect;
|
||||
GlobalConfig.systemSwOsInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.systemSwOsInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "systemSwArchCollect")){
|
||||
if(GlobalConfig.systemSwArchCollect != collect || GlobalConfig.systemSwArchInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemSwArchCollect = collect;
|
||||
GlobalConfig.systemSwArchInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.systemSwArchInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "kernelMaxprocCollect")){
|
||||
if(GlobalConfig.kernelMaxprocCollect != collect || GlobalConfig.kernelMaxprocInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.kernelMaxprocCollect = collect;
|
||||
GlobalConfig.kernelMaxprocInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.kernelMaxprocInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "procNumRunCollect")){
|
||||
if(GlobalConfig.procNumRunCollect != collect || GlobalConfig.procNumRunInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.procNumRunCollect = collect;
|
||||
GlobalConfig.procNumRunInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.procNumRunInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "systemUsersNumCollect")){
|
||||
if(GlobalConfig.systemUsersNumCollect != collect || GlobalConfig.systemUsersNumInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemUsersNumCollect = collect;
|
||||
GlobalConfig.systemUsersNumInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.systemUsersNumInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "systemDiskSizeTotalCollect")){
|
||||
if(GlobalConfig.systemDiskSizeTotalCollect != collect || GlobalConfig.systemDiskSizeTotalInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemDiskSizeTotalCollect = collect;
|
||||
GlobalConfig.systemDiskSizeTotalInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.systemDiskSizeTotalInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "systemBoottimeCollect")){
|
||||
if(GlobalConfig.systemBoottimeCollect != collect || GlobalConfig.systemBoottimeInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemBoottimeCollect = collect;
|
||||
GlobalConfig.systemBoottimeInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.systemBoottimeInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "systemUnameCollect")){
|
||||
if(GlobalConfig.systemUnameCollect != collect || GlobalConfig.systemUnameInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemUnameCollect = collect;
|
||||
GlobalConfig.systemUnameInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.systemUnameInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "systemLocaltimeCollect")){
|
||||
if(GlobalConfig.systemLocaltimeCollect != collect || GlobalConfig.systemLocaltimeInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemLocaltimeCollect = collect;
|
||||
GlobalConfig.systemLocaltimeInterval = interval;
|
||||
if(!collect){
|
||||
GlobalConfig.systemLocaltimeInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "systemUptimeCollect")){
|
||||
if(GlobalConfig.systemUptimeCollect != collect || GlobalConfig.systemUptimeInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.systemUptimeCollect = collect;
|
||||
GlobalConfig.systemUptimeInterval = c.getInterval();
|
||||
if(!collect){
|
||||
GlobalConfig.systemUptimeInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.equals(type, "procNumCollect")){
|
||||
if(GlobalConfig.procNumCollect != collect || GlobalConfig.procNumInterval != c.getInterval()){
|
||||
flag = true;
|
||||
GlobalConfig.procNumCollect = collect;
|
||||
GlobalConfig.procNumInterval = c.getInterval();
|
||||
if(!collect){
|
||||
GlobalConfig.procNumInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
case "systemSwapSizeFreeCollect": //交换卷/文件的可用空间(字节)采集
|
||||
if(GlobalConfig.systemSwapSizeFreeCollect != collect || GlobalConfig.systemSwapSizeFreeInterval != interval){
|
||||
GlobalConfig.systemSwapSizeFreeCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.systemSwapSizeFreeInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
() -> businessTasks.systemTask(type), milli, c.getInterval()*1000L);
|
||||
businessTasks::systemSwapSizeFreeTask, milli, GlobalConfig.systemSwapSizeFreeInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.systemSwapSizeFreeInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "memoryUtilizationCollect": //内存利用率采集
|
||||
if(GlobalConfig.memoryUtilizationCollect != collect || GlobalConfig.memoryUtilizationInterval != interval){
|
||||
GlobalConfig.memoryUtilizationCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.memoryUtilizationInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::memoryUtilizationTask, milli, GlobalConfig.memoryUtilizationInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.memoryUtilizationInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "systemSwapSizePercentCollect": //可用交换空间百分比采集
|
||||
if(GlobalConfig.systemSwapSizePercentCollect != collect || GlobalConfig.systemSwapSizePercentInterval != interval){
|
||||
GlobalConfig.systemSwapSizePercentCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.systemSwapSizePercentInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::systemSwapSizePercentTask, milli, GlobalConfig.systemSwapSizePercentInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.systemSwapSizePercentInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "memorySizeAvailableCollect": //可用内存采集
|
||||
if(GlobalConfig.memorySizeAvailableCollect != collect || GlobalConfig.memorySizeAvailableInterval != interval){
|
||||
GlobalConfig.memorySizeAvailableCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.memorySizeAvailableInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::memorySizeAvailableTask, milli, GlobalConfig.memorySizeAvailableInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.memorySizeAvailableInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "memorySizePercentCollect": //可用内存百分比采集
|
||||
if(GlobalConfig.memorySizePercentCollect != collect || GlobalConfig.memorySizePercentInterval != interval){
|
||||
GlobalConfig.memorySizePercentCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.memorySizePercentInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::memorySizePercentTask, milli, GlobalConfig.memorySizePercentInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.memorySizePercentInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "memorySizeTotalCollect": //总内存采集
|
||||
if(GlobalConfig.memorySizeTotalCollect != collect || GlobalConfig.memorySizeTotalInterval != interval){
|
||||
GlobalConfig.memorySizeTotalCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.memorySizeTotalInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::memorySizeTotalTask, milli, GlobalConfig.memorySizeTotalInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.memorySizeTotalInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "systemSwOsCollect": //操作系统采集
|
||||
if(GlobalConfig.systemSwOsCollect != collect || GlobalConfig.systemSwOsInterval != interval){
|
||||
GlobalConfig.systemSwOsCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.systemSwOsInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::systemSwOsTask, milli, GlobalConfig.systemSwOsInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.systemSwOsInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "systemSwArchCollect": //操作系统架构采集
|
||||
if(GlobalConfig.systemSwArchCollect != collect || GlobalConfig.systemSwArchInterval != interval){
|
||||
GlobalConfig.systemSwArchCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.systemSwArchInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::systemSwArchTask, milli, GlobalConfig.systemSwArchInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.systemSwArchInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "kernelMaxprocCollect": //最大进程数采集
|
||||
if(GlobalConfig.kernelMaxprocCollect != collect || GlobalConfig.kernelMaxprocInterval != interval){
|
||||
GlobalConfig.kernelMaxprocCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.kernelMaxprocInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::kernelMaxprocTask, milli, GlobalConfig.kernelMaxprocInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.kernelMaxprocInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "procNumRunCollect": //正在运行的进程数采集
|
||||
if(GlobalConfig.procNumRunCollect != collect || GlobalConfig.procNumRunInterval != interval){
|
||||
GlobalConfig.procNumRunCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.procNumRunInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::procNumRunTask, milli, GlobalConfig.procNumRunInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.procNumRunInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "systemUsersNumCollect": //登录用户数采集
|
||||
if(GlobalConfig.systemUsersNumCollect != collect || GlobalConfig.systemUsersNumInterval != interval){
|
||||
GlobalConfig.systemUsersNumCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.systemUsersNumInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::systemUsersNumTask, milli, GlobalConfig.systemUsersNumInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.systemUsersNumInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "systemDiskSizeTotalCollect": //硬盘总可用空间采集
|
||||
if(GlobalConfig.systemDiskSizeTotalCollect != collect || GlobalConfig.systemDiskSizeTotalInterval != interval){
|
||||
GlobalConfig.systemDiskSizeTotalCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.systemDiskSizeTotalInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::systemDiskSizeTotalTask, milli, GlobalConfig.systemDiskSizeTotalInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.systemDiskSizeTotalInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "systemBoottimeCollect": //系统启动时间采集
|
||||
if(GlobalConfig.systemBoottimeCollect != collect || GlobalConfig.systemBoottimeInterval != interval){
|
||||
GlobalConfig.systemBoottimeCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.systemBoottimeInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::systemBoottimeTask, milli, GlobalConfig.systemBoottimeInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.systemBoottimeInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "systemUnameCollect": //系统描述采集
|
||||
if(GlobalConfig.systemUnameCollect != collect || GlobalConfig.systemUnameInterval != interval){
|
||||
GlobalConfig.systemUnameCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.systemUnameInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::systemUnameTask, milli, GlobalConfig.systemUnameInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.systemUnameInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "systemLocaltimeCollect": //系统本地时间采集
|
||||
if(GlobalConfig.systemLocaltimeCollect != collect || GlobalConfig.systemLocaltimeInterval != interval){
|
||||
GlobalConfig.systemLocaltimeCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.systemLocaltimeInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::systemLocaltimeTask, milli, GlobalConfig.systemLocaltimeInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.systemLocaltimeInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "systemUptimeCollect": //系统正常运行时间采集
|
||||
if(GlobalConfig.systemUptimeCollect != collect || GlobalConfig.systemUptimeInterval != interval){
|
||||
GlobalConfig.systemUptimeCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.systemUptimeInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::systemUptimeTask, milli, GlobalConfig.systemUptimeInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.systemUptimeInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: //系统其他采集
|
||||
GlobalConfig.procNumCollect = collect;
|
||||
if(collect){
|
||||
GlobalConfig.procNumInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::procNumTask, milli, GlobalConfig.procNumInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.procNumInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -408,203 +462,270 @@ public class AgentServiceImpl implements AgentService {
|
||||
switch(type) {
|
||||
case "switchNetCollect": //交换机网络采集
|
||||
if(GlobalConfig.switchNetCollect != collect || GlobalConfig.switchNetInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchNetCollect = collect;
|
||||
GlobalConfig.switchNetInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchNetInterval = 300;
|
||||
long milli = AgentUtil.millisecondsToNext5Minute();
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchNetTask, milli, GlobalConfig.switchNetInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchNetInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchModuleCollect": //光模块采集
|
||||
if(GlobalConfig.switchModuleCollect != collect || GlobalConfig.switchModuleInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchModuleCollect = collect;
|
||||
GlobalConfig.switchModuleInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchModuleInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchModuleTask, milli, GlobalConfig.switchModuleInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchModuleInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchMpuCollect": //MPU采集
|
||||
if(GlobalConfig.switchMpuCollect != collect || GlobalConfig.switchMpuInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchMpuCollect = collect;
|
||||
GlobalConfig.switchMpuInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchMpuInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchMpuTask, milli, GlobalConfig.switchMpuInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchMpuInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchPwrCollect": //电源采集
|
||||
if(GlobalConfig.switchPwrCollect != collect || GlobalConfig.switchPwrInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchPwrCollect = collect;
|
||||
GlobalConfig.switchPwrInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchPwrInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchPwrTask, milli, GlobalConfig.switchPwrInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchPwrInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchFanCollect": //风扇采集
|
||||
if(GlobalConfig.switchFanCollect != collect || GlobalConfig.switchFanInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchFanCollect = collect;
|
||||
GlobalConfig.switchFanInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchFanInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchFanTask, milli, GlobalConfig.switchFanInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchFanInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchSysDescrCollect":
|
||||
if(GlobalConfig.switchSysDescrCollect != collect || GlobalConfig.switchSysDescrInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchSysDescrCollect = collect;
|
||||
GlobalConfig.switchSysDescrInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchSysDescrInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchSysDescrTask, milli, GlobalConfig.switchSysDescrInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchSysDescrInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchSysObjectIDCollect":
|
||||
if(GlobalConfig.switchSysObjectIDCollect != collect || GlobalConfig.switchSysObjectIDInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchSysObjectIDCollect = collect;
|
||||
GlobalConfig.switchSysObjectIDInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchSysObjectIDInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchSysObjectIDTask, milli, GlobalConfig.switchSysObjectIDInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchSysObjectIDInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchSysUpTimeCollect":
|
||||
if(GlobalConfig.switchSysUpTimeCollect != collect || GlobalConfig.switchSysUpTimeInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchSysUpTimeCollect = collect;
|
||||
GlobalConfig.switchSysUpTimeInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchSysUpTimeInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchSysUpTimeTask, milli, GlobalConfig.switchSysUpTimeInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchSysUpTimeInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchSysContactCollect":
|
||||
if(GlobalConfig.switchSysContactCollect != collect || GlobalConfig.switchSysContactInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchSysContactCollect = collect;
|
||||
GlobalConfig.switchSysContactInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchSysContactInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchSysContactTask, milli, GlobalConfig.switchSysContactInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchSysContactInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchSysNameCollect":
|
||||
if(GlobalConfig.switchSysNameCollect != collect || GlobalConfig.switchSysNameInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchSysNameCollect = collect;
|
||||
GlobalConfig.switchSysNameInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchSysNameInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchSysNameTask, milli, GlobalConfig.switchSysNameInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchSysNameInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchSysLocationCollect":
|
||||
if(GlobalConfig.switchSysLocationCollect != collect || GlobalConfig.switchSysLocationInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchSysLocationCollect = collect;
|
||||
GlobalConfig.switchSysLocationInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchSysLocationInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchSysLocationTask, milli, GlobalConfig.switchSysLocationInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchSysLocationInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchHwStackSystemMacCollect":
|
||||
if(GlobalConfig.switchHwStackSystemMacCollect != collect || GlobalConfig.switchHwStackSystemMacInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchHwStackSystemMacCollect = collect;
|
||||
GlobalConfig.switchHwStackSystemMacInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchHwStackSystemMacInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchHwStackSystemMacTask, milli, GlobalConfig.switchHwStackSystemMacInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchHwStackSystemMacInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchEntIndexCollect":
|
||||
if(GlobalConfig.switchEntIndexCollect != collect || GlobalConfig.switchEntIndexInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchEntIndexCollect = collect;
|
||||
GlobalConfig.switchEntIndexInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchEntIndexInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchEntIndexTask, milli, GlobalConfig.switchEntIndexInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchEntIndexInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchEntPhysicalNameCollect":
|
||||
if(GlobalConfig.switchEntPhysicalNameCollect != collect || GlobalConfig.switchEntPhysicalNameInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchEntPhysicalNameCollect = collect;
|
||||
GlobalConfig.switchEntPhysicalNameInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchEntPhysicalNameInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchEntPhysicalNameTask, milli, GlobalConfig.switchEntPhysicalNameInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchEntPhysicalNameInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchEntPhysicalSoftwareRevCollect":
|
||||
if(GlobalConfig.switchEntPhysicalSoftwareRevCollect != collect || GlobalConfig.switchEntPhysicalSoftwareRevInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchEntPhysicalSoftwareRevCollect = collect;
|
||||
GlobalConfig.switchEntPhysicalSoftwareRevInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchEntPhysicalSoftwareRevInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchEntPhysicalSoftwareRevTask, milli, GlobalConfig.switchEntPhysicalSoftwareRevInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchEntPhysicalSoftwareRevInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchHwEntityCpuUsageCollect":
|
||||
if(GlobalConfig.switchHwEntityCpuUsageCollect != collect || GlobalConfig.switchHwEntityCpuUsageInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchHwEntityCpuUsageCollect = collect;
|
||||
GlobalConfig.switchHwEntityCpuUsageInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchHwEntityCpuUsageInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchHwEntityCpuUsageTask, milli, GlobalConfig.switchHwEntityCpuUsageInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchHwEntityCpuUsageInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchHwEntityMemUsageCollect":
|
||||
if(GlobalConfig.switchHwEntityMemUsageCollect != collect || GlobalConfig.switchHwEntityMemUsageInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchHwEntityMemUsageCollect = collect;
|
||||
GlobalConfig.switchHwEntityMemUsageInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchHwEntityMemUsageInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchHwEntityMemUsageTask, milli, GlobalConfig.switchHwEntityMemUsageInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchHwEntityMemUsageInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "switchHwAveragePowerCollect":
|
||||
if(GlobalConfig.switchHwAveragePowerCollect != collect || GlobalConfig.switchHwAveragePowerInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchHwAveragePowerCollect = collect;
|
||||
GlobalConfig.switchHwAveragePowerInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchHwAveragePowerInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchHwAveragePowerTask, milli, GlobalConfig.switchHwAveragePowerInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchHwAveragePowerInterval = 300;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: //系统其他采集
|
||||
if(GlobalConfig.switchHwCurrentPowerCollect != collect || GlobalConfig.switchHwCurrentPowerInterval != interval){
|
||||
flag = true;
|
||||
GlobalConfig.switchHwCurrentPowerCollect = collect;
|
||||
GlobalConfig.switchHwCurrentPowerInterval = interval;
|
||||
if(!collect){
|
||||
if(collect){
|
||||
GlobalConfig.switchHwCurrentPowerInterval = interval;
|
||||
long milli = AgentUtil.getMillisToNextMinute() + 60000;
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
businessTasks::switchHwCurrentPowerTask, milli, GlobalConfig.switchHwCurrentPowerInterval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
GlobalConfig.switchHwCurrentPowerInterval = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
if(collect){
|
||||
long milli = AgentUtil.millisecondsToNext5Minute();
|
||||
dynamicTaskService.scheduleTask(type,
|
||||
() -> businessTasks.switchBoardTask(type), milli, interval*1000L);
|
||||
}else{
|
||||
dynamicTaskService.cancelTask(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -686,7 +807,7 @@ public class AgentServiceImpl implements AgentService {
|
||||
if(policy.getMethod() == 1){
|
||||
SpecificTimeRequest request = SpecificTimeRequest.builder()
|
||||
.taskId("")
|
||||
.taskName("")
|
||||
.taskName(policy.getPolicyName())
|
||||
.taskData(policy.getCommands())
|
||||
.specificDateTime(AgentUtil.toLocalDateTime(policy.getPolicyTime(),true))
|
||||
.clientId(clientId)
|
||||
|
||||
@@ -23,13 +23,14 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
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();
|
||||
@@ -85,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()){
|
||||
@@ -111,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()){
|
||||
@@ -137,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()){
|
||||
@@ -163,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()){
|
||||
@@ -189,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()){
|
||||
@@ -215,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()){
|
||||
@@ -258,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()),
|
||||
@@ -404,6 +405,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
||||
ifNumberOID = GlobalConfig.OTHER_INDEX_OID;
|
||||
filter_value = GlobalConfig.OTHER_FILTER;
|
||||
}
|
||||
AssertLog.info("交换机采集type={},筛选端口={}",type,JSON.toJSONString(filter_value));
|
||||
if(StringUtils.isBlank(ifNumberOID)){
|
||||
System.err.println("未初始化索引OID");
|
||||
return "";
|
||||
@@ -437,19 +439,28 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
||||
}
|
||||
// 提取最后一个值:就是 ifIndex 编号
|
||||
int ifIndex = returnedOid.get(returnedOid.size() - 1);
|
||||
// System.out.println("Found port index: " + ifIndex);
|
||||
if(!filter_value.contains(String.valueOf(ifIndex))){
|
||||
int value = vb.getVariable().toInt();
|
||||
if(CollectionUtil.isEmpty(filter_value)){
|
||||
// AssertLog.info("交换机采集type={},索引返回:值={}",type,vb);
|
||||
indexes.add(ifIndex);
|
||||
}else{
|
||||
if(filter_value.contains(String.valueOf(value))){
|
||||
// AssertLog.info("交换机采集type={},索引返回:值={}",type,vb);
|
||||
indexes.add(ifIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 更新下一次请求的起始 OID(SNMP Walk)
|
||||
pdu.set(0, new VariableBinding(responsePdu.getVariableBindings().get(0).getOid()));
|
||||
}
|
||||
System.out.println("\n=== 接口数量: " + indexes.size() + " ===");
|
||||
if(CollectionUtil.isEmpty(indexes)){
|
||||
System.err.println("返回获取索引列表为空");
|
||||
return "";
|
||||
}
|
||||
//去重
|
||||
indexes = indexes.stream().distinct().collect(Collectors.toList());
|
||||
// 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")
|
||||
@@ -514,7 +525,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
||||
if (event != null && event.getResponse() != null) {
|
||||
VariableBinding[] vbs = event.getResponse().getVariableBindings().toArray(new VariableBinding[0]);
|
||||
for (int m = 0; m < params.length; m++) {
|
||||
AssertLog.info("参数名:{},值={}", params[m],vbs[m]);
|
||||
// AssertLog.info("参数名:{},值={}", params[m],vbs[m]);
|
||||
json.put(params[m],vbs[m].getVariable().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,15 +200,14 @@ public class AgentUtil {
|
||||
|
||||
public static long roundMinutes(){
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 四舍五入到最近的5分钟
|
||||
LocalDateTime roundedTime = now
|
||||
.truncatedTo(ChronoUnit.MINUTES) // 先去掉秒和纳秒
|
||||
.withMinute((int) (Math.round(now.getMinute() / 5.0) * 5))
|
||||
.withSecond(0)
|
||||
.withNano(0);
|
||||
// 处理分钟进位的情况
|
||||
if (roundedTime.getMinute() == 60) {
|
||||
roundedTime = roundedTime.plusHours(1).withMinute(0);
|
||||
int minute = now.getMinute();
|
||||
int roundedMinute = (int) (Math.round(minute / 5.0) * 5);
|
||||
|
||||
LocalDateTime roundedTime ;
|
||||
if (roundedMinute == 60) {
|
||||
roundedTime = now.plusHours(1).withMinute(0).withSecond(0).withNano(0);
|
||||
} else {
|
||||
roundedTime = now.withMinute(roundedMinute).withSecond(0).withNano(0);
|
||||
}
|
||||
// 转换为10位时间戳
|
||||
long timestamp = roundedTime.atZone(ZoneId.systemDefault()).toEpochSecond();
|
||||
|
||||
Reference in New Issue
Block a user