feat(heartbeat): строка сервера с основным IPv4 в скобках
This commit is contained in:
+23
-1
@@ -1249,6 +1249,28 @@ check_daily_report() {
|
||||
# Heartbeat
|
||||
# ============================================
|
||||
|
||||
# Для уведомлений: «hostname (IPv4)»; без доступного IPv4 — только hostname.
|
||||
server_display_name_with_ip() {
|
||||
local hn ip
|
||||
hn=$(hostname 2>/dev/null | tr -d '\r\n')
|
||||
[ -z "$hn" ] && hn="(unknown)"
|
||||
ip=""
|
||||
if 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; then
|
||||
if 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
|
||||
fi
|
||||
if [ -n "$ip" ]; then
|
||||
printf '%s (%s)' "$hn" "$ip"
|
||||
else
|
||||
printf '%s' "$hn"
|
||||
fi
|
||||
}
|
||||
|
||||
send_heartbeat() {
|
||||
local timestamp
|
||||
timestamp=$(date '+%s')
|
||||
@@ -1256,7 +1278,7 @@ send_heartbeat() {
|
||||
timestamp_human=$(date '+%d.%m.%Y %H:%M:%S')
|
||||
|
||||
local message=" ❤️ Heartbeat - скрипт мониторинга работает "$'\n'
|
||||
message="${message}🖥️ Сервер: $(hostname)"$'\n'
|
||||
message="${message}🖥️ Сервер: $(server_display_name_with_ip)"$'\n'
|
||||
message="${message}🕐 Время: ${timestamp_human}"
|
||||
|
||||
notify_send "$message"
|
||||
|
||||
Reference in New Issue
Block a user