修改配置.

This commit is contained in:
lijiahang
2024-05-07 11:35:08 +08:00
parent 908c4a3345
commit 1379150369
9 changed files with 48 additions and 42 deletions

View File

@@ -34,7 +34,7 @@ public class AppExecLogConfig {
public AppExecLogConfig() {
this.appendAnsi = true;
this.autoClear = true;
this.keepPeriod = 60;
this.keepPeriod = 30;
}
}

View File

@@ -31,16 +31,16 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
super.initLogOutputStream();
// 拼接启动日志
AnsiAppender appender = AnsiAppender.create()
.append(AnsiForeground.BRIGHT_GREEN.and(AnsiFont.BOLD), "> 准备执行命令 ")
.append(AnsiForeground.GREEN.and(AnsiFont.BOLD), "> 准备执行命令 ")
.append(Dates.current())
.newLine()
.append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "执行记录: ")
.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "执行记录: ")
.append(execCommand.getLogId())
.newLine()
.append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "执行描述: ")
.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "执行描述: ")
.append(execCommand.getDescription())
.newLine()
.append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "执行用户: ")
.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "执行用户: ")
.append(execCommand.getUsername());
// 非系统用户执行添加 userId
if (Const.SYSTEM_USER_ID.equals(execCommand.getUserId())) {
@@ -53,35 +53,35 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
}
// 执行序列
if (execCommand.getExecSeq() != null) {
appender.append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "执行序列: ")
appender.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "执行序列: ")
.append('#')
.append(execCommand.getExecSeq())
.newLine();
}
appender.append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "执行主机: ")
appender.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "执行主机: ")
.append(execHostCommand.getHostName())
.append(" (")
.append(execHostCommand.getHostId())
.append(")")
.newLine()
.append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "主机地址: ")
.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "主机地址: ")
.append(execHostCommand.getHostAddress())
.newLine()
.append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "超时时间: ")
.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "超时时间: ")
.append(execCommand.getTimeout())
.newLine()
.append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "脚本执行: ")
.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "脚本执行: ")
.append(execCommand.getScriptExec())
.newLine()
.newLine()
.append(AnsiForeground.BRIGHT_GREEN.and(AnsiFont.BOLD), "> 执行命令 ")
.append(AnsiForeground.GREEN.and(AnsiFont.BOLD), "> 执行命令 ")
.newLine()
.append(execHostCommand.getCommand())
.newLine()
.newLine();
// 非脚本执行拼接开始执行日志
if (!Booleans.isTrue(execCommand.getScriptExec())) {
appender.append(AnsiForeground.BRIGHT_GREEN.and(AnsiFont.BOLD), "> 开始执行命令 ")
appender.append(AnsiForeground.GREEN.and(AnsiFont.BOLD), "> 开始执行命令 ")
.append(Dates.current())
.newLine();
}
@@ -94,10 +94,10 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
// 拼接上传日志
AnsiAppender startAppender = AnsiAppender.create()
.newLine()
.append(AnsiForeground.BRIGHT_GREEN.and(AnsiFont.BOLD), "> 准备上传脚本 ")
.append(AnsiForeground.GREEN.and(AnsiFont.BOLD), "> 准备上传脚本 ")
.append(Dates.current())
.newLine()
.append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "文件路径: ")
.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "文件路径: ")
.append(execHostCommand.getScriptPath())
.newLine();
this.appendLog(startAppender);
@@ -105,18 +105,18 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
super.uploadScriptFile();
// 拼接完成日志
AnsiAppender finishAppender = AnsiAppender.create()
.append(AnsiForeground.BRIGHT_GREEN.and(AnsiFont.BOLD), "< 脚本上传成功 ")
.append(AnsiForeground.GREEN.and(AnsiFont.BOLD), "< 脚本上传成功 ")
.append(Dates.current())
.newLine()
.newLine()
.append(AnsiForeground.BRIGHT_GREEN.and(AnsiFont.BOLD), "> 开始执行脚本 ")
.append(AnsiForeground.GREEN.and(AnsiFont.BOLD), "> 开始执行脚本 ")
.append(Dates.current())
.newLine();
this.appendLog(finishAppender);
} catch (Exception e) {
// 拼接失败日志
AnsiAppender errorAppender = AnsiAppender.create()
.append(AnsiForeground.BRIGHT_RED.and(AnsiFont.BOLD), "< 脚本上传失败 ")
.append(AnsiForeground.RED.and(AnsiFont.BOLD), "< 脚本上传失败 ")
.append(Dates.current())
.newLine();
this.appendLog(errorAppender);
@@ -133,37 +133,37 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
.newLine();
if (this.status == ExecHostStatusEnum.INTERRUPTED) {
// 中断执行
appender.append(AnsiForeground.BRIGHT_YELLOW.and(AnsiFont.BOLD), "< 命令执行中断 ")
appender.append(AnsiForeground.YELLOW.and(AnsiFont.BOLD), "< 命令执行中断 ")
.append(Dates.current())
.newLine();
} else if (this.status == ExecHostStatusEnum.FAILED) {
// 执行失败
appender.append(AnsiForeground.BRIGHT_RED.and(AnsiFont.BOLD), "< 命令执行失败 ")
appender.append(AnsiForeground.RED.and(AnsiFont.BOLD), "< 命令执行失败 ")
.append(Dates.current())
.newLine()
.append(AnsiForeground.BRIGHT_RED.and(AnsiFont.BOLD), "错误原因: ")
.append(AnsiForeground.RED.and(AnsiFont.BOLD), "错误原因: ")
.append(this.getErrorMessage(e))
.newLine();
} else if (this.status == ExecHostStatusEnum.TIMEOUT) {
// 更新执行超时
appender.append(AnsiForeground.BRIGHT_YELLOW.and(AnsiFont.BOLD), "< 命令执行超时 ")
appender.append(AnsiForeground.YELLOW.and(AnsiFont.BOLD), "< 命令执行超时 ")
.append(Dates.current())
.newLine();
} else {
long ms = this.updateRecord.getFinishTime().getTime() - this.updateRecord.getStartTime().getTime();
Integer exitStatus = this.updateRecord.getExitStatus();
// 执行完成
appender.append(AnsiForeground.BRIGHT_GREEN.and(AnsiFont.BOLD), "< 命令执行完成 ")
appender.append(AnsiForeground.GREEN.and(AnsiFont.BOLD), "< 命令执行完成 ")
.append(Dates.current())
.newLine()
.append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "exit: ");
.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "exit: ");
if (ExitCode.isSuccess(exitStatus)) {
appender.append(AnsiForeground.BRIGHT_GREEN.and(AnsiFont.BOLD), exitStatus);
appender.append(AnsiForeground.GREEN.and(AnsiFont.BOLD), exitStatus);
} else {
appender.append(AnsiForeground.BRIGHT_RED.and(AnsiFont.BOLD), exitStatus);
appender.append(AnsiForeground.RED.and(AnsiFont.BOLD), exitStatus);
}
appender.newLine()
.append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "used: ")
.append(AnsiForeground.BLUE.and(AnsiFont.BOLD), "used: ")
.append(Dates.interval(ms, false, "d ", "h ", "m ", "s"))
.append(" (")
.append(ms)

View File

@@ -113,7 +113,7 @@ public class HostConnectLogServiceImpl implements HostConnectLogService {
@Override
public Integer updateStatusById(Long id, HostConnectStatusEnum status, Map<String, Object> partial) {
log.info("HostConnectLogService-updateStatusByToken start id: {}, status: {}", id, status);
log.info("HostConnectLogService-updateStatusById start id: {}, status: {}", id, status);
// 查询
HostConnectLogDO record = hostConnectLogDAO.of()
.createWrapper()
@@ -122,7 +122,7 @@ public class HostConnectLogServiceImpl implements HostConnectLogService {
.then()
.getOne();
if (record == null) {
log.info("HostConnectLogService-updateStatusByToken no record id: {}", id);
log.info("HostConnectLogService-updateStatusById no record id: {}", id);
return Const.N_0;
}
return this.updateStatus(record, status, partial);

View File

@@ -63,7 +63,7 @@
"name": "app.exec-log.keep-period",
"type": "java.lang.Integer",
"description": "保留周期 (天)",
"defaultValue": "60"
"defaultValue": "30"
}
]
}