|
|
@@ -1,7 +1,9 @@
|
|
|
package com.xunmei.system.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.http.HttpException;
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.http.HttpResponse;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
@@ -93,9 +95,6 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|
|
public List<CheckListVo> getServerList(Long serverId) {
|
|
|
try {
|
|
|
SysServer server = this.selectSysServerById(serverId);
|
|
|
- server.setServerToken("d033e22ae348aeb5660fc2140aec35850c4da997");
|
|
|
- server.setServerIp("10.87.10.196");
|
|
|
- server.setServerPort(8091);
|
|
|
String baseUrl = String.format("http://%s:%d", server.getServerIp(), server.getServerPort());
|
|
|
String getServicesApi = "/result/list?size=10000¤t=1";
|
|
|
HttpResponse response = HttpUtil.createPost(baseUrl + getServicesApi)
|
|
|
@@ -112,13 +111,8 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|
|
|
|
|
@Override
|
|
|
public Object getLogList(Long serverId, Long checkId) {
|
|
|
- // http://10.87.10.196:8091/index1.html?token=d033e22ae348aeb5660fc2140aec35850c4da997
|
|
|
SysServer server = this.selectSysServerById(serverId);
|
|
|
|
|
|
- server.setServerToken("d033e22ae348aeb5660fc2140aec35850c4da997");
|
|
|
- server.setServerIp("10.87.10.196");
|
|
|
- server.setServerPort(8091);
|
|
|
-
|
|
|
String baseUrl = String.format("http://%s:%d", server.getServerIp(), server.getServerPort());
|
|
|
String getLogs = "/result/fileList?checkId=" + checkId;
|
|
|
//获取服务器列表
|
|
|
@@ -132,6 +126,31 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|
|
return checks;
|
|
|
}
|
|
|
|
|
|
+ public static void saveRemoteLogToLocal() {
|
|
|
+ String path = "your_path";
|
|
|
+ String parentPath = "your_parent_path";
|
|
|
+ String rootDir = "your_root_dir";
|
|
|
+ String downloadUrl = "http://your_server/fileDownload?path=" + path + "&parentPath=" + parentPath + "&rootDir=" + rootDir;
|
|
|
+
|
|
|
+ try {
|
|
|
+ final HttpRequest request = HttpUtil.createGet(downloadUrl);
|
|
|
+ HttpResponse response = request.execute();
|
|
|
+
|
|
|
+ // Check if the request was successful
|
|
|
+ if (response.getStatus() == 200) {
|
|
|
+ String fileName = response.header("Content-Disposition");
|
|
|
+ fileName = fileName.substring(fileName.indexOf("filename=") + 10, fileName.length() - 1);
|
|
|
+
|
|
|
+ // Save the file
|
|
|
+ FileUtil.writeBytes(response.bodyBytes(), fileName);
|
|
|
+ System.out.println("File downloaded successfully: " + fileName);
|
|
|
+ } else {
|
|
|
+ System.out.println("No file to download. Server replied HTTP code: " + response.getStatus());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 查询服务器维护
|