diff --git a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/handler/host/exec/command/handler/BaseExecCommandHandler.java b/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/handler/host/exec/command/handler/BaseExecCommandHandler.java index 79c5d078..adf682bb 100644 --- a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/handler/host/exec/command/handler/BaseExecCommandHandler.java +++ b/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/handler/host/exec/command/handler/BaseExecCommandHandler.java @@ -167,21 +167,12 @@ public abstract class BaseExecCommandHandler implements IExecCommandHandler { Valid.eq(this.status, ExecHostStatusEnum.WAITING, ErrorMessage.TASK_ABSENT, ErrorMessage.ILLEGAL_STATUS); // 获取主机会话 this.connect = terminalService.getTerminalConnectInfo(execHostLog.getHostId(), execLog.getUserId()); - // 获取内置参数 - Map commandParams = this.getCommandParams(); - // 获取实际命令 - String command = ExecUtils.format(execLog.getCommand(), commandParams); - // 获取日志路径 - String logPath = fileClient.getReturnPath(EndpointDefine.EXEC_LOG.format(execHostLog.getLogId(), execHostLog.getHostId())); - // 获取脚本路径 - String scriptPath = null; - if (BooleanBit.toBoolean(execLog.getScriptExec())) { - scriptPath = this.buildScriptPath(); - } - execHostLog.setCommand(command); - execHostLog.setParameter(JSON.toJSONString(commandParams)); - execHostLog.setLogPath(logPath); - execHostLog.setScriptPath(scriptPath); + // 设置日志路径 + this.setLogPath(); + // 设置脚本路径 + this.setScriptPath(); + // 设置执行的命令以及参数 + this.setExecCommand(); } catch (Exception e) { log.error("BaseExecCommandHandler.initData error id: {}", id, e); ex = e; @@ -191,6 +182,9 @@ public abstract class BaseExecCommandHandler implements IExecCommandHandler { this.updateStatus(passed ? ExecHostStatusEnum.RUNNING : ExecHostStatusEnum.FAILED, ex, (s) -> { // 修改其他参数 s.setCommand(execHostLog.getCommand()); + s.setParameter(execHostLog.getParameter()); + s.setLogPath(execHostLog.getLogPath()); + s.setScriptPath(execHostLog.getScriptPath()); }); return passed; } @@ -371,7 +365,59 @@ public abstract class BaseExecCommandHandler implements IExecCommandHandler { Streams.close(logOutputStream); Streams.close(executor); Streams.close(sessionStore); - execLogManager.asyncCloseTailFile(execHostLog.getLogPath()); + execLogManager.asyncCloseTailFile(id); + } + + /** + * 设置日志路径 + */ + private void setLogPath() { + // 构建日志路径 + String logPath = fileClient.getReturnPath(EndpointDefine.EXEC_LOG.format(execHostLog.getLogId(), id)); + execHostLog.setLogPath(logPath); + } + + /** + * 设置脚本路径 + */ + private void setScriptPath() { + String scriptPath = null; + // 获取脚本路径 + if (BooleanBit.toBoolean(execLog.getScriptExec())) { + HostOsTypeEnum os = HostOsTypeEnum.of(connect.getOsType()); + String name = FileConst.EXEC + + "/" + execHostLog.getLogId() + + "/" + id + + os.getScriptSuffix(); + scriptPath = PathUtils.buildAppPath(HostOsTypeEnum.WINDOWS.equals(os), connect.getUsername(), FileConst.SCRIPT, name); + } + execHostLog.setScriptPath(scriptPath); + } + + /** + * 设置实际执行的命令以及参数 + */ + private void setExecCommand() { + String uuid = UUIds.random(); + // 参数列表 + Map params = Maps.newMap(builtParams); + params.put("execHostId", id); + params.put("hostId", connect.getHostId()); + params.put("hostName", connect.getHostName()); + params.put("hostCode", connect.getHostCode()); + params.put("hostAddress", connect.getHostAddress()); + params.put("hostPort", connect.getHostPort()); + params.put("hostUsername", connect.getUsername()); + params.put("hostUuid", uuid); + params.put("hostUuidShort", uuid.replace("-", Strings.EMPTY)); + params.put("osType", connect.getOsType()); + params.put("charset", connect.getCharset()); + params.put("scriptPath", execHostLog.getScriptPath()); + // 获取实际命令 + String paramsJson = JSON.toJSONString(params); + String command = ExecUtils.format(execLog.getCommand(), paramsJson); + execHostLog.setCommand(command); + execHostLog.setParameter(paramsJson); } /** @@ -404,40 +450,4 @@ public abstract class BaseExecCommandHandler implements IExecCommandHandler { return Strings.retain(message, 250); } - /** - * 获取命令实际参数 - * - * @return params - */ - private Map getCommandParams() { - String uuid = UUIds.random(); - Map params = Maps.newMap(builtParams); - params.put("hostId", connect.getHostId()); - params.put("hostName", connect.getHostName()); - params.put("hostCode", connect.getHostCode()); - params.put("hostAddress", connect.getHostAddress()); - params.put("hostPort", connect.getHostPort()); - params.put("hostUsername", connect.getUsername()); - params.put("hostUuid", uuid); - params.put("hostUuidShort", uuid.replace("-", Strings.EMPTY)); - params.put("osType", connect.getOsType()); - params.put("charset", connect.getCharset()); - params.put("scriptPath", execHostLog.getScriptPath()); - return params; - } - - /** - * 构建脚本路径 - * - * @return scriptPath - */ - private String buildScriptPath() { - HostOsTypeEnum os = HostOsTypeEnum.of(connect.getOsType()); - String name = FileConst.EXEC - + "/" + execHostLog.getLogId() - + "/" + id - + os.getScriptSuffix(); - return PathUtils.buildAppPath(HostOsTypeEnum.WINDOWS.equals(os), connect.getUsername(), FileConst.SCRIPT, name); - } - } diff --git a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/handler/host/exec/command/handler/ExecTaskHandler.java b/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/handler/host/exec/command/handler/ExecTaskHandler.java index 358baa92..382f60c0 100644 --- a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/handler/host/exec/command/handler/ExecTaskHandler.java +++ b/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/handler/host/exec/command/handler/ExecTaskHandler.java @@ -193,12 +193,12 @@ public class ExecTaskHandler implements IExecTaskHandler { * @return handler */ private IExecCommandHandler createCommandHandler(Long execHostId) { - if (Booleans.isTrue(appLogConfig.getExecAppendAnsi())) { + if (Booleans.isTrue(appLogConfig.getExecDetailLog())) { // 详细日志 - return new ExecCommandDetailHandler(id, execLog, builtParams, timeoutChecker); + return new ExecCommandDetailHandler(execHostId, execLog, builtParams, timeoutChecker); } else { // 原始日志 - return new ExecCommandOriginHandler(id, execLog, builtParams, timeoutChecker); + return new ExecCommandOriginHandler(execHostId, execLog, builtParams, timeoutChecker); } } diff --git a/orion-visor-ui/src/components/view/exec-editor/const.ts b/orion-visor-ui/src/components/view/exec-editor/const.ts index 71807639..900613df 100644 --- a/orion-visor-ui/src/components/view/exec-editor/const.ts +++ b/orion-visor-ui/src/components/view/exec-editor/const.ts @@ -28,6 +28,9 @@ export const builtinParams: Array = [ }, { name: 'execId', desc: '执行记录id' + }, { + name: 'execHostId', + desc: '执行记录主机id' }, { name: 'hostId', desc: '执行主机id'