feat: watchdog Telegram shows server name (2.1.9-SAC)
Add shared server label helpers in ssh-monitor-perms.sh; roadmap marks phase 1 done and phase 2.2.0 as next release. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -132,3 +132,42 @@ ssh_monitor_check_config_file_perms() {
|
||||
esac
|
||||
return 0
|
||||
}
|
||||
|
||||
# Подпись сервера в Telegram/webhook (как в ssh-monitor: SERVER_DISPLAY_NAME или hostname + IPv4).
|
||||
ssh_monitor_server_display_name_with_ip() {
|
||||
local hn ip
|
||||
hn="${SERVER_DISPLAY_NAME:-}"
|
||||
if [ -z "$hn" ]; then
|
||||
hn="$(hostname 2>/dev/null | tr -d '\r\n')"
|
||||
[ -z "$hn" ] && hn="(unknown)"
|
||||
fi
|
||||
ip="${SERVER_IPV4:-}"
|
||||
if [ -z "$ip" ] && command -v ip >/dev/null 2>&1; then
|
||||
ip="$(ip -4 route get 1.1.1.1 2>/dev/null | awk '/\bsrc\b/ {for (i = 1; i < NF; i++) if ($i == "src") { print $(i + 1); exit }}')"
|
||||
[ -z "$ip" ] && ip="$(ip -4 route get 8.8.8.8 2>/dev/null | awk '/\bsrc\b/ {for (i = 1; i < NF; i++) if ($i == "src") { print $(i + 1); exit }}')"
|
||||
fi
|
||||
if [ -z "$ip" ] && command -v hostname >/dev/null 2>&1 && hostname -I >/dev/null 2>&1; then
|
||||
ip="$(hostname -I 2>/dev/null | tr ' ' '\n' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' | grep -Ev '^(127\.|0\.0\.0\.0)$' | head -n1)"
|
||||
fi
|
||||
if [ -n "$ip" ]; then
|
||||
printf '%s (%s)' "$hn" "$ip"
|
||||
else
|
||||
printf '%s' "$hn"
|
||||
fi
|
||||
}
|
||||
|
||||
ssh_monitor_message_ensure_server_line() {
|
||||
local msg="$1"
|
||||
if [[ "$msg" == *'🖥️ Сервер:'* ]]; then
|
||||
printf '%s' "$msg"
|
||||
return 0
|
||||
fi
|
||||
local first rest
|
||||
first="${msg%%$'\n'*}"
|
||||
if [ "$first" = "$msg" ]; then
|
||||
printf '%s\n🖥️ Сервер: %s' "$first" "$(ssh_monitor_server_display_name_with_ip)"
|
||||
else
|
||||
rest="${msg#*$'\n'}"
|
||||
printf '%s\n🖥️ Сервер: %s\n%s' "$first" "$(ssh_monitor_server_display_name_with_ip)" "$rest"
|
||||
fi
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user