From 2395f536cd98936c4ef4d8405431e96459cd938e Mon Sep 17 00:00:00 2001 From: PTah Date: Sun, 31 May 2026 11:51:55 +1000 Subject: [PATCH] feat: notification source line in agent alerts (1.2.29-SAC) Co-authored-by: Cursor --- Login_Monitor.ps1 | 28 +++++++++++++++++++++++++++- Sac-Client.ps1 | 12 +++++++++++- version.txt | 2 +- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/Login_Monitor.ps1 b/Login_Monitor.ps1 index 99e9afa..47f8b87 100644 --- a/Login_Monitor.ps1 +++ b/Login_Monitor.ps1 @@ -80,7 +80,7 @@ $script:MonitorLoopInitialized = $false # строки ниже, если правки «мелкие» и вы не хотите менять отображаемую версию в логах). # Рекомендация: при значимых релизах меняйте и $ScriptVersion, и version.txt одинаково; при только # исправлениях на шаре — достаточно поднять patch в version.txt (например 1.3.0.1). -$ScriptVersion = "1.2.28-SAC" +$ScriptVersion = "1.2.29-SAC" # Логи (все под InstallRoot) $LogFile = Join-Path $script:InstallRoot "Logs\login_monitor.log" @@ -737,6 +737,28 @@ function Get-NotifyChainHuman { return ($labels -join ' → ') } +function Get-AgentNotificationSourcePlainLine { + $ver = if ($ScriptVersion) { [string]$ScriptVersion } else { 'unknown' } + return "📡 Оповещение: агент (rdp-login-monitor $ver)" +} + +function Get-AgentNotificationSourceHtmlLine { + return [System.Net.WebUtility]::HtmlEncode((Get-AgentNotificationSourcePlainLine)) +} + +function Add-NotificationSourceLine { + param([string]$Message) + + if ($Message -match 'Оповещение:\s*(агент|SAC)') { + return $Message + } + $line = Get-AgentNotificationSourceHtmlLine + if ([string]::IsNullOrWhiteSpace($Message)) { + return $line + } + return ($Message.TrimEnd() + "`r`n`r`n" + $line) +} + function ConvertTo-TelegramHtml { param([string]$Text) if ($null -eq $Text) { return '' } @@ -751,6 +773,8 @@ function Send-TelegramMessage { return $false } + $Message = Add-NotificationSourceLine -Message $Message + $uri = "https://api.telegram.org/bot$TelegramBotToken/sendMessage" $body = @{ chat_id = $TelegramChatID @@ -1713,6 +1737,8 @@ function Build-DailyReportPlainBodyWindows { } else { [void]$sb.AppendLine(' (нет данных)') } + [void]$sb.AppendLine('') + [void]$sb.AppendLine((Get-AgentNotificationSourcePlainLine)) return $sb.ToString().TrimEnd() } diff --git a/Sac-Client.ps1 b/Sac-Client.ps1 index 2a1d12f..ffd52bf 100644 --- a/Sac-Client.ps1 +++ b/Sac-Client.ps1 @@ -624,7 +624,17 @@ function Send-SacEvent { return $false } - $payload = $(New-SacEventPayload -EventType $EventType -Severity $Severity -Title $Title -Summary $Summary -Details $Details) + $mergedDetails = @{} + if ($null -ne $Details) { + foreach ($k in $Details.Keys) { + $mergedDetails[$k] = $Details[$k] + } + } + if (-not $mergedDetails.ContainsKey('generated_by')) { + $mergedDetails['generated_by'] = 'agent' + } + + $payload = $(New-SacEventPayload -EventType $EventType -Severity $Severity -Title $Title -Summary $Summary -Details $mergedDetails) if ($payload -is [System.Array]) { $payload = $payload[-1] } diff --git a/version.txt b/version.txt index 54c18bf..5f1de29 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.2.28-SAC +1.2.29-SAC