feat: notification source line in agent alerts (1.2.11-SAC)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+24
-1
@@ -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 '[]')"
|
||||
|
||||
|
||||
+1
-2
@@ -1,2 +1 @@
|
||||
1.2.10-SAC
|
||||
|
||||
1.2.11-SAC
|
||||
|
||||
Reference in New Issue
Block a user