From 09f1b576bf3c36cda209800c8a5e3fe09a44dce5 Mon Sep 17 00:00:00 2001 From: PTah Date: Fri, 12 Jun 2026 11:51:16 +1000 Subject: [PATCH] feat: send agent.heartbeat on monitor startup (2.0.34-SAC) SAC sees host online immediately after restart; periodic heartbeat every 4h unchanged. Co-authored-by: Cursor --- Login_Monitor.ps1 | 29 +++++++++++++++++++---------- version.txt | 2 +- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Login_Monitor.ps1 b/Login_Monitor.ps1 index f9fc967..93ea78a 100644 --- a/Login_Monitor.ps1 +++ b/Login_Monitor.ps1 @@ -90,7 +90,7 @@ $script:SkipLogDetailLimit = 15 # строки ниже, если правки «мелкие» и вы не хотите менять отображаемую версию в логах). # Рекомендация: при значимых релизах меняйте и $ScriptVersion, и version.txt одинаково; при только # исправлениях на шаре — достаточно поднять patch в version.txt (например 1.3.0.1). -$ScriptVersion = "2.0.33-SAC" +$ScriptVersion = "2.0.34-SAC" # Логи (все под InstallRoot) $LogFile = Join-Path $script:InstallRoot "Logs\login_monitor.log" @@ -2428,6 +2428,22 @@ function Convert-DailyReportPlainToTelegramHtml { return ($out -join "`r`n") } +function Send-RdpMonitorSacHeartbeat { + param( + [Parameter(Mandatory)] + [string]$Timestamp + ) + Write-TextFileUtf8Bom -Path $HeartbeatFile -Text $Timestamp + $script:HeartbeatStaleAlertActive = $false + if ($script:SacClientLoaded -and (Get-SacNormalizedMode) -ne 'off') { + Send-MonitorNotification -Message '' -EmailSubject 'RDP Login Monitor: heartbeat' ` + -SacEventType 'agent.heartbeat' -SacSeverity 'info' ` + -SacTitle 'RDP monitor heartbeat' ` + -SacSummary "Heartbeat $(Get-MonitorServerLabel) $Timestamp" ` + -SacDetails @{ host = $env:COMPUTERNAME } | Out-Null + } +} + function Send-Heartbeat { param([switch]$IsStartup = $false) @@ -2540,16 +2556,9 @@ function Send-Heartbeat { -SacTitle 'RDP login monitor started' ` -SacSummary "Мониторинг запущен на $(Get-MonitorServerLabelWithIp), версия $ScriptVersion" Write-Log "Отправлено уведомление о запуске скрипта (каналы: $notifyChain)" + Send-RdpMonitorSacHeartbeat -Timestamp $timestamp } else { - Write-TextFileUtf8Bom -Path $HeartbeatFile -Text $timestamp - $script:HeartbeatStaleAlertActive = $false - if ($script:SacClientLoaded -and (Get-SacNormalizedMode) -ne 'off') { - Send-MonitorNotification -Message '' -EmailSubject 'RDP Login Monitor: heartbeat' ` - -SacEventType 'agent.heartbeat' -SacSeverity 'info' ` - -SacTitle 'RDP monitor heartbeat' ` - -SacSummary "Heartbeat $(Get-MonitorServerLabel) $timestamp" ` - -SacDetails @{ host = $env:COMPUTERNAME } | Out-Null - } + Send-RdpMonitorSacHeartbeat -Timestamp $timestamp } } diff --git a/version.txt b/version.txt index 18bed85..1f04230 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2.0.33-SAC +2.0.34-SAC