🔨 优化安装逻辑.

This commit is contained in:
lijiahangmax
2025-12-19 00:32:53 +08:00
parent 58a1a7abd4
commit 1e74659f15
7 changed files with 27 additions and 14 deletions

View File

@@ -45,6 +45,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* 主机探针端点 api
@@ -90,9 +91,8 @@ public class HostAgentController {
@PostMapping("/install")
@Operation(summary = "安装主机探针")
@PreAuthorize("@ss.hasPermission('asset:host:install-agent')")
public Boolean installAgent(@Validated @RequestBody HostAgentInstallRequest request) {
hostAgentService.installAgent(request);
return true;
public Map<String, Long> installAgent(@Validated @RequestBody HostAgentInstallRequest request) {
return hostAgentService.installAgent(request);
}
@DemoDisableApi

View File

@@ -27,6 +27,7 @@ import org.dromara.visor.module.asset.entity.vo.HostAgentStatusVO;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
/**
* 主机探针 服务类
@@ -49,8 +50,9 @@ public interface HostAgentService {
* 安装探针
*
* @param request request
* @return agentKey:installId
*/
void installAgent(HostAgentInstallRequest request);
Map<String, Long> installAgent(HostAgentInstallRequest request);
/**
* 上传探针发布包

View File

@@ -22,6 +22,7 @@
*/
package org.dromara.visor.module.asset.service.impl;
import cn.orionsec.kit.lang.function.Functions;
import cn.orionsec.kit.lang.utils.Exceptions;
import cn.orionsec.kit.lang.utils.Strings;
import cn.orionsec.kit.lang.utils.collect.Lists;
@@ -133,7 +134,7 @@ public class HostAgentServiceImpl implements HostAgentService {
}
@Override
public void installAgent(HostAgentInstallRequest request) {
public Map<String, Long> installAgent(HostAgentInstallRequest request) {
// 查询主机信息
List<Long> idList = request.getIdList();
List<HostDO> hosts = hostDAO.selectBatchIds(idList);
@@ -181,6 +182,12 @@ public class HostAgentServiceImpl implements HostAgentService {
// 执行任务
AgentInstaller.start(params);
}
// 返回
return agentLogs.stream()
.collect(Collectors.toMap(HostAgentLogDO::getAgentKey,
HostAgentLogDO::getId,
Functions.right()));
}
@Override

View File

@@ -50,7 +50,7 @@ export interface HostAgentInstallStatusUpdateRequest {
* 安装主机探针
*/
export function installHostAgent(request: HostInstallAgentRequest) {
return axios.post('/asset/host-agent/install', request);
return axios.post<Record<string, number>>('/asset/host-agent/install', request);
}
/**

View File

@@ -405,7 +405,6 @@
} = useMonitorHostList({
hosts: renderList,
setLoading,
reload,
});
// 重置条件

View File

@@ -456,7 +456,6 @@
} = useMonitorHostList({
hosts: tableRenderData,
setLoading,
reload,
});
// 获取行样式

View File

@@ -16,8 +16,6 @@ export interface UseMonitorHostListOptions {
hosts: Ref<Array<MonitorHostQueryResponse>>;
// 设置加载中
setLoading: (loading: boolean) => void;
// 重新加载
reload: () => void;
}
// 使用监控主机列表
@@ -29,7 +27,7 @@ export default function useMonitorHostList(options: UseMonitorHostListOptions) {
const router = useRouter();
const { toggleDict } = useDictStore();
const { hosts, setLoading, reload } = options;
const { hosts, setLoading } = options;
// 打开详情
const openDetail = (hostId: number, name: string) => {
@@ -65,10 +63,18 @@ export default function useMonitorHostList(options: UseMonitorHostListOptions) {
onOk: async () => {
try {
// 调用安装
await installHostAgent({ idList: hostIdList });
const { data } = await installHostAgent({ idList: hostIdList });
Message.success('开始安装');
// 重新加载
reload();
// 设置状态
installHosts.forEach(host => {
const installId = data[host.agentKey];
if (installId) {
host.installLog = {
id: installId,
eventStatus: AgentLogStatus.WAIT,
} as any;
}
});
} finally {
setLoading(false);
}