🔨 优化安装逻辑.
This commit is contained in:
@@ -45,6 +45,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主机探针端点 api
|
* 主机探针端点 api
|
||||||
@@ -90,9 +91,8 @@ public class HostAgentController {
|
|||||||
@PostMapping("/install")
|
@PostMapping("/install")
|
||||||
@Operation(summary = "安装主机探针")
|
@Operation(summary = "安装主机探针")
|
||||||
@PreAuthorize("@ss.hasPermission('asset:host:install-agent')")
|
@PreAuthorize("@ss.hasPermission('asset:host:install-agent')")
|
||||||
public Boolean installAgent(@Validated @RequestBody HostAgentInstallRequest request) {
|
public Map<String, Long> installAgent(@Validated @RequestBody HostAgentInstallRequest request) {
|
||||||
hostAgentService.installAgent(request);
|
return hostAgentService.installAgent(request);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@DemoDisableApi
|
@DemoDisableApi
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import org.dromara.visor.module.asset.entity.vo.HostAgentStatusVO;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主机探针 服务类
|
* 主机探针 服务类
|
||||||
@@ -49,8 +50,9 @@ public interface HostAgentService {
|
|||||||
* 安装探针
|
* 安装探针
|
||||||
*
|
*
|
||||||
* @param request request
|
* @param request request
|
||||||
|
* @return agentKey:installId
|
||||||
*/
|
*/
|
||||||
void installAgent(HostAgentInstallRequest request);
|
Map<String, Long> installAgent(HostAgentInstallRequest request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传探针发布包
|
* 上传探针发布包
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.dromara.visor.module.asset.service.impl;
|
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.Exceptions;
|
||||||
import cn.orionsec.kit.lang.utils.Strings;
|
import cn.orionsec.kit.lang.utils.Strings;
|
||||||
import cn.orionsec.kit.lang.utils.collect.Lists;
|
import cn.orionsec.kit.lang.utils.collect.Lists;
|
||||||
@@ -133,7 +134,7 @@ public class HostAgentServiceImpl implements HostAgentService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void installAgent(HostAgentInstallRequest request) {
|
public Map<String, Long> installAgent(HostAgentInstallRequest request) {
|
||||||
// 查询主机信息
|
// 查询主机信息
|
||||||
List<Long> idList = request.getIdList();
|
List<Long> idList = request.getIdList();
|
||||||
List<HostDO> hosts = hostDAO.selectBatchIds(idList);
|
List<HostDO> hosts = hostDAO.selectBatchIds(idList);
|
||||||
@@ -181,6 +182,12 @@ public class HostAgentServiceImpl implements HostAgentService {
|
|||||||
// 执行任务
|
// 执行任务
|
||||||
AgentInstaller.start(params);
|
AgentInstaller.start(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 返回
|
||||||
|
return agentLogs.stream()
|
||||||
|
.collect(Collectors.toMap(HostAgentLogDO::getAgentKey,
|
||||||
|
HostAgentLogDO::getId,
|
||||||
|
Functions.right()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export interface HostAgentInstallStatusUpdateRequest {
|
|||||||
* 安装主机探针
|
* 安装主机探针
|
||||||
*/
|
*/
|
||||||
export function installHostAgent(request: HostInstallAgentRequest) {
|
export function installHostAgent(request: HostInstallAgentRequest) {
|
||||||
return axios.post('/asset/host-agent/install', request);
|
return axios.post<Record<string, number>>('/asset/host-agent/install', request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -405,7 +405,6 @@
|
|||||||
} = useMonitorHostList({
|
} = useMonitorHostList({
|
||||||
hosts: renderList,
|
hosts: renderList,
|
||||||
setLoading,
|
setLoading,
|
||||||
reload,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 重置条件
|
// 重置条件
|
||||||
|
|||||||
@@ -456,7 +456,6 @@
|
|||||||
} = useMonitorHostList({
|
} = useMonitorHostList({
|
||||||
hosts: tableRenderData,
|
hosts: tableRenderData,
|
||||||
setLoading,
|
setLoading,
|
||||||
reload,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 获取行样式
|
// 获取行样式
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ export interface UseMonitorHostListOptions {
|
|||||||
hosts: Ref<Array<MonitorHostQueryResponse>>;
|
hosts: Ref<Array<MonitorHostQueryResponse>>;
|
||||||
// 设置加载中
|
// 设置加载中
|
||||||
setLoading: (loading: boolean) => void;
|
setLoading: (loading: boolean) => void;
|
||||||
// 重新加载
|
|
||||||
reload: () => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用监控主机列表
|
// 使用监控主机列表
|
||||||
@@ -29,7 +27,7 @@ export default function useMonitorHostList(options: UseMonitorHostListOptions) {
|
|||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { toggleDict } = useDictStore();
|
const { toggleDict } = useDictStore();
|
||||||
const { hosts, setLoading, reload } = options;
|
const { hosts, setLoading } = options;
|
||||||
|
|
||||||
// 打开详情
|
// 打开详情
|
||||||
const openDetail = (hostId: number, name: string) => {
|
const openDetail = (hostId: number, name: string) => {
|
||||||
@@ -65,10 +63,18 @@ export default function useMonitorHostList(options: UseMonitorHostListOptions) {
|
|||||||
onOk: async () => {
|
onOk: async () => {
|
||||||
try {
|
try {
|
||||||
// 调用安装
|
// 调用安装
|
||||||
await installHostAgent({ idList: hostIdList });
|
const { data } = await installHostAgent({ idList: hostIdList });
|
||||||
Message.success('开始安装');
|
Message.success('开始安装');
|
||||||
// 重新加载
|
// 设置状态
|
||||||
reload();
|
installHosts.forEach(host => {
|
||||||
|
const installId = data[host.agentKey];
|
||||||
|
if (installId) {
|
||||||
|
host.installLog = {
|
||||||
|
id: installId,
|
||||||
|
eventStatus: AgentLogStatus.WAIT,
|
||||||
|
} as any;
|
||||||
|
}
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user