收紧测服日志监视脚本过滤,减少 health 探活刷屏,便于排查企微回调。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
linmianxun
2026-09-13 21:19:38 +08:00
co-authored by Cursor
parent 8103b3b651
commit 4d90bba99d
+17 -19
View File
@@ -17,19 +17,21 @@ param(
)
$ErrorActionPreference = 'Stop'
$Key = Join-Path $env:USERPROFILE '.ssh\id_ed25519_ytd'
$Remote = 'ytd_extdev_0903@129.211.181.80'
$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'
# 企微回调 / 出站 / 注入 / 常见失败码;-All 时不使用
$Pattern = 'wecom|callback|inject|outbox|inbox|errcode|errmsg|60020|ERROR|WARNING|Traceback|Exception|health|sender|touser|crypto'
# 企微回调 / 出站 / 注入 / 失败;故意不含纯 /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 $Key)) {
throw "缺少 SSH 密钥: $Key"
if (-not (Test-Path $SshKey)) {
throw "缺少 SSH 密钥: $SshKey"
}
Write-Host "目标: ${Remote}"
Write-Host "目标: $SshHost"
Write-Host "日志: $LogOut"
Write-Host " $LogErr"
if ($All) {
@@ -39,11 +41,11 @@ if ($All) {
}
Write-Host '---'
# 远程脚本:先打 health,再 Tail;-Wait 仅在非 Once 时启用
$waitLiteral = if ($Once) { '$false' } else { '$true' }
$allLiteral = if ($All) { '$true' } else { '$false' }
$remote = @"
# 远程执行体:先 health,再 Tail;持续模式用 -Wait
$remoteScript = @"
`$ErrorActionPreference = 'Continue'
`$out = '$LogOut'
`$err = '$LogErr'
@@ -88,16 +90,12 @@ Write-Output 'following... (Ctrl+C to stop)'
Get-Content -Path `$files -Tail `$tail -Wait -ErrorAction SilentlyContinue | ForEach-Object { Show-Line `$_ }
"@
$remoteFile = Join-Path $env:TEMP 'ytd-watch-agent8910-remote.ps1'
Set-Content -Path $remoteFile -Value $remote -Encoding UTF8
$localTemp = Join-Path $env:TEMP 'ytd-watch-agent8910-remote.ps1'
Set-Content -Path $localTemp -Value $remoteScript -Encoding UTF8
$incoming = 'C:/Users/ytd_extdev_0903/incoming/_watch_agent8910.ps1'
& scp -o BatchMode=yes -o ConnectTimeout=12 -i $Key $remoteFile "${Remote}:${incoming}"
& scp.exe -o BatchMode=yes -o ConnectTimeout=12 -i $SshKey $localTemp "${SshHost}:${IncomingRemotePath}"
if ($LASTEXITCODE -ne 0) { throw "scp failed: $LASTEXITCODE" }
& ssh -o BatchMode=yes -o ConnectTimeout=12 -i $Key $Remote `
"powershell -NoProfile -ExecutionPolicy Bypass -File C:\Users\ytd_extdev_0903\incoming\_watch_agent8910.ps1"
if ($LASTEXITCODE -ne 0 -and -not $Once) {
# Ctrl+C 常非 0,不当作部署失败
exit $LASTEXITCODE
}
& ssh.exe -o BatchMode=yes -o ConnectTimeout=12 -i $SshKey $SshHost `
"powershell -NoProfile -ExecutionPolicy Bypass -File `"$IncomingLocalRun`""
exit $LASTEXITCODE