From e1a37b8f89ee70353e367cfa637b396b8765d4ee Mon Sep 17 00:00:00 2001 From: PTah Date: Sun, 31 May 2026 11:51:56 +1000 Subject: [PATCH] feat: notification source line in agent alerts (1.2.11-SAC) Co-authored-by: Cursor --- ssh-monitor | 25 ++++++++++++++++++++++++- version.txt | 3 +-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/ssh-monitor b/ssh-monitor index d775576..8f50d6a 100644 --- a/ssh-monitor +++ b/ssh-monitor @@ -7,7 +7,7 @@ IFS=$'\n\t' # ============================================ CONFIG_FILE="/etc/ssh-monitor.conf" -SSH_MONITOR_VERSION="1.2.10-SAC" +SSH_MONITOR_VERSION="1.2.11-SAC" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" if [ -f "$SCRIPT_DIR/sac-client.sh" ]; then @@ -668,6 +668,26 @@ PY return 1 } +notification_source_agent_plain() { + printf '📡 Оповещение: агент (ssh-monitor %s)' "${SSH_MONITOR_VERSION:-unknown}" +} + +append_agent_notification_source() { + local msg="$1" + if printf '%s' "$msg" | grep -Fq '📡 Оповещение:'; then + printf '%s' "$msg" + return 0 + fi + local line + line="$(notification_source_agent_plain)" + if [ -z "$msg" ]; then + printf '%s' "$line" + else + msg="${msg%"${msg##*[![:space:]]}"}" + printf '%s\n\n%s' "$msg" "$line" + fi +} + send_telegram_raw() { local message="$1" if [ -z "$TELEGRAM_BOT_TOKEN" ] || [ -z "$TELEGRAM_CHAT_ID" ]; then @@ -724,6 +744,7 @@ sac_mirror_notify_message() { notify_send() { local message="$1" message="$(message_ensure_server_line "$message")" + message="$(append_agent_notification_source "$message")" if [ "${DRY_RUN:-0}" = "1" ]; then printf '[DRY-RUN notify] %s\n' "$(printf '%s' "$message" | tr '\n' ' ')" >&2 return 0 @@ -1762,6 +1783,8 @@ send_daily_report() { message+=" (нет данных)"$'\n' fi + message="$(append_agent_notification_source "$message")" + local active_users_json active_users_json="$(printf '%s' "$active_sessions" | python3 -c 'import json,sys; print(json.dumps([l.strip() for l in sys.stdin.read().splitlines() if l.strip()]))' 2>/dev/null || echo '[]')" diff --git a/version.txt b/version.txt index 7b102bc..766bd5a 100644 --- a/version.txt +++ b/version.txt @@ -1,2 +1 @@ -1.2.10-SAC - +1.2.11-SAC