收紧测服日志监视脚本过滤,减少 health 探活刷屏,便于排查企微回调。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+17
-19
@@ -17,19 +17,21 @@ param(
|
|||||||
)
|
)
|
||||||
|
|
||||||
$ErrorActionPreference = 'Stop'
|
$ErrorActionPreference = 'Stop'
|
||||||
$Key = Join-Path $env:USERPROFILE '.ssh\id_ed25519_ytd'
|
$SshKey = Join-Path $env:USERPROFILE '.ssh\id_ed25519_ytd'
|
||||||
$Remote = 'ytd_extdev_0903@129.211.181.80'
|
$SshHost = 'ytd_extdev_0903@129.211.181.80'
|
||||||
$LogOut = 'E:\wwwroot\logs\agent-http.out.log'
|
$LogOut = 'E:\wwwroot\logs\agent-http.out.log'
|
||||||
$LogErr = 'E:\wwwroot\logs\agent-http.err.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 时不使用
|
# 企微回调 / 出站 / 注入 / 失败;故意不含纯 /health 探活行,避免刷屏
|
||||||
$Pattern = 'wecom|callback|inject|outbox|inbox|errcode|errmsg|60020|ERROR|WARNING|Traceback|Exception|health|sender|touser|crypto'
|
$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)) {
|
if (-not (Test-Path $SshKey)) {
|
||||||
throw "缺少 SSH 密钥: $Key"
|
throw "缺少 SSH 密钥: $SshKey"
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "目标: ${Remote}"
|
Write-Host "目标: $SshHost"
|
||||||
Write-Host "日志: $LogOut"
|
Write-Host "日志: $LogOut"
|
||||||
Write-Host " $LogErr"
|
Write-Host " $LogErr"
|
||||||
if ($All) {
|
if ($All) {
|
||||||
@@ -39,11 +41,11 @@ if ($All) {
|
|||||||
}
|
}
|
||||||
Write-Host '---'
|
Write-Host '---'
|
||||||
|
|
||||||
# 远程脚本:先打 health,再 Tail;-Wait 仅在非 Once 时启用
|
|
||||||
$waitLiteral = if ($Once) { '$false' } else { '$true' }
|
$waitLiteral = if ($Once) { '$false' } else { '$true' }
|
||||||
$allLiteral = if ($All) { '$true' } else { '$false' }
|
$allLiteral = if ($All) { '$true' } else { '$false' }
|
||||||
|
|
||||||
$remote = @"
|
# 远程执行体:先 health,再 Tail;持续模式用 -Wait
|
||||||
|
$remoteScript = @"
|
||||||
`$ErrorActionPreference = 'Continue'
|
`$ErrorActionPreference = 'Continue'
|
||||||
`$out = '$LogOut'
|
`$out = '$LogOut'
|
||||||
`$err = '$LogErr'
|
`$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 `$_ }
|
Get-Content -Path `$files -Tail `$tail -Wait -ErrorAction SilentlyContinue | ForEach-Object { Show-Line `$_ }
|
||||||
"@
|
"@
|
||||||
|
|
||||||
$remoteFile = Join-Path $env:TEMP 'ytd-watch-agent8910-remote.ps1'
|
$localTemp = Join-Path $env:TEMP 'ytd-watch-agent8910-remote.ps1'
|
||||||
Set-Content -Path $remoteFile -Value $remote -Encoding UTF8
|
Set-Content -Path $localTemp -Value $remoteScript -Encoding UTF8
|
||||||
|
|
||||||
$incoming = 'C:/Users/ytd_extdev_0903/incoming/_watch_agent8910.ps1'
|
& scp.exe -o BatchMode=yes -o ConnectTimeout=12 -i $SshKey $localTemp "${SshHost}:${IncomingRemotePath}"
|
||||||
& scp -o BatchMode=yes -o ConnectTimeout=12 -i $Key $remoteFile "${Remote}:${incoming}"
|
|
||||||
if ($LASTEXITCODE -ne 0) { throw "scp failed: $LASTEXITCODE" }
|
if ($LASTEXITCODE -ne 0) { throw "scp failed: $LASTEXITCODE" }
|
||||||
|
|
||||||
& ssh -o BatchMode=yes -o ConnectTimeout=12 -i $Key $Remote `
|
& ssh.exe -o BatchMode=yes -o ConnectTimeout=12 -i $SshKey $SshHost `
|
||||||
"powershell -NoProfile -ExecutionPolicy Bypass -File C:\Users\ytd_extdev_0903\incoming\_watch_agent8910.ps1"
|
"powershell -NoProfile -ExecutionPolicy Bypass -File `"$IncomingLocalRun`""
|
||||||
if ($LASTEXITCODE -ne 0 -and -not $Once) {
|
exit $LASTEXITCODE
|
||||||
# Ctrl+C 常非 0,不当作部署失败
|
|
||||||
exit $LASTEXITCODE
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user