Compare commits
4
Commits
3d5a237d4d
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
085be262b0 | ||
|
|
9fd69cc3a6 | ||
|
|
161ad3eaa3 | ||
|
|
ab33329e31 |
@@ -1,8 +1,12 @@
|
||||
# composer.py
|
||||
|
||||
import time
|
||||
from datetime import datetime
|
||||
from typing import Optional, Tuple
|
||||
from app.bot.utils.tg_escape_chars import escape_telegram_chars # или твоя функция, если кастомная
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from app.bot.utils.tg_escape_chars import escape_telegram_chars # или твоя функция, если кастомная
|
||||
from config import ZABBIX_TZ
|
||||
|
||||
|
||||
def compose_telegram_message(data: dict) -> Tuple[str, Optional[str]]:
|
||||
"""
|
||||
@@ -19,6 +23,12 @@ def compose_telegram_message(data: dict) -> Tuple[str, Optional[str]]:
|
||||
'High': '⚠️',
|
||||
'Disaster': '⛔️'
|
||||
}
|
||||
convert_time_format = {
|
||||
"h": "ч",
|
||||
"m": "м",
|
||||
"s": "с"
|
||||
}
|
||||
|
||||
priority = priority_map.get(data.get('severity', ''), '')
|
||||
msg = escape_telegram_chars(data.get('msg', ''))
|
||||
host = escape_telegram_chars(data.get('host', ''))
|
||||
@@ -26,7 +36,8 @@ def compose_telegram_message(data: dict) -> Tuple[str, Optional[str]]:
|
||||
severity = escape_telegram_chars(data.get('severity', ''))
|
||||
status = data.get('status', '').upper()
|
||||
timestamp = int(data.get('date_reception', 0))
|
||||
time_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp))
|
||||
dt = datetime.fromtimestamp(timestamp, tz=ZoneInfo(ZABBIX_TZ))
|
||||
time_str = dt.strftime('%d.%m.%Y %H:%M:%S')
|
||||
|
||||
if status == "PROBLEM":
|
||||
message = (
|
||||
@@ -36,12 +47,32 @@ def compose_telegram_message(data: dict) -> Tuple[str, Optional[str]]:
|
||||
f"<b>Время возникновения</b>: {time_str} Мск\n"
|
||||
)
|
||||
else:
|
||||
event_duration = data.get('event_duration', '')
|
||||
duration = ' '.join(
|
||||
f"{part[:-1]}{convert_time_format.get(part[-1], part[-1])}"
|
||||
for part in event_duration.split()
|
||||
)
|
||||
|
||||
# Переформатируем event_date из '2025.06.27 16:46:04' в '27.06.2025 16:46:04'
|
||||
event_date_str = data.get('event_date', '')
|
||||
if event_date_str:
|
||||
try:
|
||||
dt_start = datetime.strptime(event_date_str, "%Y.%m.%d %H:%M:%S")
|
||||
# не меняем timezone, просто меняем формат
|
||||
time_start = dt_start.strftime('%d.%m.%Y %H:%M:%S')
|
||||
except Exception:
|
||||
time_start = event_date_str # fallback — оставляем как есть
|
||||
else:
|
||||
time_start = ''
|
||||
|
||||
message = (
|
||||
f"✅ {host} ({ip})\n"
|
||||
f"<b>Описание</b>: {msg}\n"
|
||||
f"<b>Критичность</b>: {severity}\n"
|
||||
f"<b>Проблема устранена!</b>\n"
|
||||
f"<b>Время начала</b>: {time_start} Мск\n"
|
||||
f"<b>Время устранения</b>: {time_str} Мск\n"
|
||||
f"<b>Длительность проблемы</b>: {duration}\n"
|
||||
)
|
||||
|
||||
link = data.get("link")
|
||||
|
||||
@@ -12,6 +12,6 @@ def create_link_button(link: Optional[str]) -> Optional[InlineKeyboardMarkup]:
|
||||
return None
|
||||
|
||||
markup = InlineKeyboardMarkup()
|
||||
button = InlineKeyboardButton(text="График", url=link)
|
||||
button = InlineKeyboardButton(text="Открыть график", url=link)
|
||||
markup.add(button)
|
||||
return markup
|
||||
|
||||
@@ -10,5 +10,7 @@ Werkzeug~=3.1.3
|
||||
aio-pika~=9.5.5
|
||||
pika~=1.3.2
|
||||
pytz~=2025.2
|
||||
tzdata~=2025.2
|
||||
concurrent-log-handler~=0.9.26
|
||||
requests~=2.32.3
|
||||
gunicorn~=23.0.0
|
||||
Reference in New Issue
Block a user