# 只读:拉服务器新系统 8910 智能体日志中的企微相关行与错误行。 # 用法(仓库根或任意目录): # .\deploy\Watch-Agent8910.ps1 # 持续监听(Ctrl+C 结束) # .\deploy\Watch-Agent8910.ps1 -Once # 只看最近一段 # .\deploy\Watch-Agent8910.ps1 -All # 不过滤关键字,整行刷出 # # 说明: # - 盯的是 E:\wwwroot\logs\agent-http.*.log(新系统 8910),不碰现网 8810/8811。 # - 切流前公网 /wecom/callback 仍进现网;本脚本主要看到 inject、出站、本机调 8910 的错误。 # - 依赖本机 SSH 密钥 ~/.ssh/id_ed25519_ytd。 [CmdletBinding()] param( [switch]$Once, [switch]$All, [int]$Tail = 80 ) $ErrorActionPreference = 'Stop' $SshKey = Join-Path $env:USERPROFILE '.ssh\id_ed25519_ytd' $SshHost = 'ytd_extdev_0903@129.211.181.80' $LogOut = 'E:\wwwroot\logs\agent-http.out.log' $LogErr = 'E:\wwwroot\logs\agent-http.err.log' $IncomingRemotePath = 'C:/Users/ytd_extdev_0903/incoming/_watch_agent8910.ps1' $IncomingLocalRun = 'C:\Users\ytd_extdev_0903\incoming\_watch_agent8910.ps1' # 企微回调 / 出站 / 注入 / 失败;故意不含纯 /health 探活行,避免刷屏 $Pattern = '/wecom/callback|inject-text|inject:|outbox|inbox|errcode|errmsg|60020|ERROR|WARNING|Traceback|Exception|ModuleNotFoundError|sender=|touser=|crypto|ChannelRuntime|dispatch intent' if (-not (Test-Path $SshKey)) { throw "缺少 SSH 密钥: $SshKey" } Write-Host "目标: $SshHost" Write-Host "日志: $LogOut" Write-Host " $LogErr" if ($All) { Write-Host '过滤: 关闭(全部输出)' } else { Write-Host "过滤: $Pattern" } Write-Host '---' $waitLiteral = if ($Once) { '$false' } else { '$true' } $allLiteral = if ($All) { '$true' } else { '$false' } # 远程执行体:先 health,再 Tail;持续模式用 -Wait $remoteScript = @" `$ErrorActionPreference = 'Continue' `$out = '$LogOut' `$err = '$LogErr' `$tail = $Tail `$wait = $waitLiteral `$all = $allLiteral `$pat = '$Pattern' Write-Output '=== remote health 8910 ===' try { `$h = Invoke-WebRequest -Uri 'http://127.0.0.1:8910/health' -UseBasicParsing -TimeoutSec 5 Write-Output `$h.Content } catch { Write-Output ('health_fail: ' + `$_.Exception.Message) } Write-Output '=== log tail ===' `$files = @() if (Test-Path `$out) { `$files += `$out } else { Write-Output ('MISSING ' + `$out) } if (Test-Path `$err) { `$files += `$err } else { Write-Output ('MISSING ' + `$err) } if (`$files.Count -eq 0) { throw 'no agent-http log files' } function Show-Line([string]`$line) { if (`$all) { Write-Output `$line return } if (`$line -match `$pat) { Write-Output `$line } } if (-not `$wait) { foreach (`$f in `$files) { Write-Output ('--- ' + `$f + ' ---') Get-Content -Path `$f -Tail `$tail -ErrorAction SilentlyContinue | ForEach-Object { Show-Line `$_ } } exit 0 } Write-Output 'following... (Ctrl+C to stop)' Get-Content -Path `$files -Tail `$tail -Wait -ErrorAction SilentlyContinue | ForEach-Object { Show-Line `$_ } "@ $localTemp = Join-Path $env:TEMP 'ytd-watch-agent8910-remote.ps1' Set-Content -Path $localTemp -Value $remoteScript -Encoding UTF8 & scp.exe -o BatchMode=yes -o ConnectTimeout=12 -i $SshKey $localTemp "${SshHost}:${IncomingRemotePath}" if ($LASTEXITCODE -ne 0) { throw "scp failed: $LASTEXITCODE" } & ssh.exe -o BatchMode=yes -o ConnectTimeout=12 -i $SshKey $SshHost ` "powershell -NoProfile -ExecutionPolicy Bypass -File `"$IncomingLocalRun`"" exit $LASTEXITCODE