feat: add advanced incidents module (cpu high, network down)

This commit is contained in:
likingcode
2026-03-10 17:17:51 +08:00
parent 2c407efbda
commit a07409af64
2 changed files with 176 additions and 6 deletions

View File

@@ -820,9 +820,15 @@ class LinuxSandbox:
if name == "cat":
stdin = self._simulate_cat(a)
elif name in {"head", "tail"}:
# allow head/tail on stdin (very minimal): if last output exists
# allow head/tail on stdin (minimal)
if stdin:
tmp = "\n".join(stdin.splitlines()[:10]) if name == "head" else "\n".join(stdin.splitlines()[-10:])
n = 10
if "-n" in a:
try:
n = int(a[a.index("-n") + 1])
except Exception:
n = 10
tmp = "\n".join(stdin.splitlines()[:n]) if name == "head" else "\n".join(stdin.splitlines()[-n:])
stdin = tmp
else:
stdin = self._simulate_head_tail(name, a)
@@ -830,6 +836,8 @@ class LinuxSandbox:
stdin = self._simulate_system_text("ss", a)
elif name == "netstat":
stdin = self._simulate_system_text("netstat", a)
elif name == "ps":
stdin = "USER PID %CPU %MEM COMMAND\nroot 1042 12.3 0.6 nginx\nsandbox 2233 95.0 1.2 python3\nroot 102 0.1 0.2 sshd"
# filters/transforms
elif name == "grep":
stdin = self._simulate_grep_stdin(a, stdin)
@@ -897,6 +905,9 @@ class LinuxSandbox:
output = self.user
elif cmd_name == "history":
output = self._simulate_history(args)
elif cmd_name == "ps":
# minimal but useful for CPU incident lessons
output = "USER PID %CPU %MEM COMMAND\nroot 1042 12.3 0.6 nginx\nsandbox 2233 95.0 1.2 python3\nroot 102 0.1 0.2 sshd"
elif cmd_name in {"systemctl", "service", "journalctl", "dig"}:
output = self._simulate_system_text(cmd_name, args)
else: