✨ 清空主机连接日志.
This commit is contained in:
@@ -26,7 +26,7 @@ public class HostConnectLogOperatorType extends InitializingOperatorTypes {
|
||||
public OperatorType[] types() {
|
||||
return new OperatorType[]{
|
||||
new OperatorType(H, DELETE, "删除主机连接记录 <sb>${count}</sb>条"),
|
||||
new OperatorType(H, CLEAR, "清理主机连接记录 <sb>${count}</sb>条"),
|
||||
new OperatorType(H, CLEAR, "清空主机连接记录 <sb>${count}</sb>条"),
|
||||
new OperatorType(M, FORCE_OFFLINE, "强制下线主机连接 <sb>${hostName}</sb>"),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 主机连接日志 视图响应对象
|
||||
@@ -56,12 +57,6 @@ public class HostConnectLogVO implements Serializable {
|
||||
private Date endTime;
|
||||
|
||||
@Schema(description = "额外信息")
|
||||
private String extraInfo;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@Schema(description = "修改时间")
|
||||
private Date updateTime;
|
||||
private Map<String, Object> extra;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.orion.ops.module.asset.handler.host.terminal.session;
|
||||
|
||||
import com.orion.lang.utils.ansi.AnsiAppender;
|
||||
import com.orion.lang.utils.ansi.style.color.AnsiForeground;
|
||||
import com.orion.lang.utils.io.Streams;
|
||||
import com.orion.net.host.SessionStore;
|
||||
import com.orion.net.host.ssh.shell.ShellExecutor;
|
||||
@@ -99,26 +97,6 @@ public class SshSession extends TerminalSession implements ISshSession {
|
||||
Streams.close(sessionStore);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forceOffline() {
|
||||
if (this.close) {
|
||||
return;
|
||||
}
|
||||
// 发送消息
|
||||
String body = AnsiAppender.create()
|
||||
.newLine()
|
||||
.append(AnsiForeground.BRIGHT_RED, TerminalMessage.FORCED_OFFLINE)
|
||||
.toString();
|
||||
SshOutputResponse resp = SshOutputResponse.builder()
|
||||
.type(OutputTypeEnum.SSH_OUTPUT.getType())
|
||||
.sessionId(sessionId)
|
||||
.body(body)
|
||||
.build();
|
||||
WebSockets.sendText(channel, OutputTypeEnum.SSH_OUTPUT.format(resp));
|
||||
// 强制下线
|
||||
super.forceOffline();
|
||||
}
|
||||
|
||||
/**
|
||||
* 标准输出处理
|
||||
*
|
||||
@@ -148,12 +126,12 @@ public class SshSession extends TerminalSession implements ISshSession {
|
||||
* eof 回调
|
||||
*/
|
||||
private void eofCallback() {
|
||||
log.info("terminal eof回调 {}, forClose: {}", sessionId, this.close);
|
||||
log.info("terminal eof回调 {}, forClose: {}, forceOffline: {}", sessionId, this.close, this.forceOffline);
|
||||
// 发送关闭信息
|
||||
TerminalCloseResponse resp = TerminalCloseResponse.builder()
|
||||
.type(OutputTypeEnum.CLOSE.getType())
|
||||
.sessionId(this.sessionId)
|
||||
.msg(TerminalMessage.CLOSED_CONNECTION)
|
||||
.msg(this.forceOffline ? TerminalMessage.FORCED_OFFLINE : TerminalMessage.CLOSED_CONNECTION)
|
||||
.build();
|
||||
WebSockets.sendText(channel, OutputTypeEnum.CLOSE.format(resp));
|
||||
// 需要调用关闭 - 可能是 logout 需要手动触发
|
||||
|
||||
@@ -28,6 +28,8 @@ public abstract class TerminalSession implements ITerminalSession {
|
||||
|
||||
protected volatile boolean close;
|
||||
|
||||
protected volatile boolean forceOffline;
|
||||
|
||||
public TerminalSession(String sessionId, WebSocketSession channel, TerminalConfig config) {
|
||||
this.sessionId = sessionId;
|
||||
this.channel = channel;
|
||||
@@ -41,6 +43,7 @@ public abstract class TerminalSession implements ITerminalSession {
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
log.info("terminal close {}", sessionId);
|
||||
// 检查并且关闭
|
||||
if (this.checkAndClose()) {
|
||||
// 修改状态
|
||||
@@ -50,6 +53,8 @@ public abstract class TerminalSession implements ITerminalSession {
|
||||
|
||||
@Override
|
||||
public void forceOffline() {
|
||||
log.info("terminal forceOffline {}", sessionId);
|
||||
this.forceOffline = true;
|
||||
this.checkAndClose();
|
||||
}
|
||||
|
||||
@@ -59,7 +64,6 @@ public abstract class TerminalSession implements ITerminalSession {
|
||||
* @return close
|
||||
*/
|
||||
private boolean checkAndClose() {
|
||||
log.info("terminal close {}", sessionId);
|
||||
if (close) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public interface HostConnectLogService {
|
||||
Long getHostConnectLogCount(HostConnectLogQueryRequest request);
|
||||
|
||||
/**
|
||||
* 清理主机连接日志
|
||||
* 清空主机连接日志
|
||||
*
|
||||
* @param request request
|
||||
* @return effect
|
||||
|
||||
@@ -71,7 +71,11 @@ public class HostConnectLogServiceImpl implements HostConnectLogService {
|
||||
// 查询
|
||||
return hostConnectLogDAO.of(wrapper)
|
||||
.page(request)
|
||||
.dataGrid(HostConnectLogConvert.MAPPER::to);
|
||||
.dataGrid(s -> {
|
||||
HostConnectLogVO vo = HostConnectLogConvert.MAPPER.to(s);
|
||||
vo.setExtra(JSON.parseObject(s.getExtraInfo()));
|
||||
return vo;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,7 +101,6 @@ public class HostConnectLogServiceImpl implements HostConnectLogService {
|
||||
|
||||
@Override
|
||||
public Integer deleteHostConnectLog(List<Long> idList) {
|
||||
// TODO 测试一下参数
|
||||
log.info("HostConnectLogService.deleteHostConnectLog start {}", JSON.toJSONString(idList));
|
||||
int effect = hostConnectLogDAO.deleteBatchIds(idList);
|
||||
log.info("HostConnectLogService.deleteHostConnectLog finish {}", effect);
|
||||
|
||||
Reference in New Issue
Block a user