Compare commits
2 Commits
3d5a237d4d
...
161ad3eaa3
| Author | SHA1 | Date | |
|---|---|---|---|
| 161ad3eaa3 | |||
| ab33329e31 |
@ -1,8 +1,12 @@
|
||||
# composer.py
|
||||
|
||||
import time
|
||||
from datetime import datetime
|
||||
from typing import Optional, Tuple
|
||||
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
|
||||
|
||||
@ -1,14 +1,42 @@
|
||||
telebot~=0.0.5
|
||||
pyTelegramBotAPI~=4.27.0
|
||||
pyzabbix~=1.3.1
|
||||
SQLAlchemy~=2.0.40
|
||||
Flask~=3.1.0
|
||||
Flask-Login~=0.6.3
|
||||
Flask-SQLAlchemy~=3.1.1
|
||||
Flask-ldap3-login~=1.0.2
|
||||
Werkzeug~=3.1.3
|
||||
aio-pika~=9.5.5
|
||||
pika~=1.3.2
|
||||
pytz~=2025.2
|
||||
requests~=2.32.3
|
||||
gunicorn~=23.0.0
|
||||
aio-pika==9.5.5
|
||||
aiormq==6.8.1
|
||||
blinker==1.9.0
|
||||
certifi==2025.4.26
|
||||
charset-normalizer==3.4.2
|
||||
click==8.1.8
|
||||
colorama==0.4.6
|
||||
concurrent-log-handler==0.9.26
|
||||
exceptiongroup==1.2.2
|
||||
Flask==3.1.0
|
||||
flask-ldap3-login==1.0.2
|
||||
Flask-Login==0.6.3
|
||||
Flask-SQLAlchemy==3.1.1
|
||||
Flask-WTF==1.2.2
|
||||
greenlet==3.2.1
|
||||
gunicorn==23.0.0
|
||||
idna==3.10
|
||||
itsdangerous==2.2.0
|
||||
Jinja2==3.1.6
|
||||
ldap3==2.9.1
|
||||
MarkupSafe==3.0.2
|
||||
multidict==6.4.3
|
||||
packaging==25.0
|
||||
pamqp==3.3.0
|
||||
pika==1.3.2
|
||||
pika-stubs==0.1.3
|
||||
portalocker==3.1.1
|
||||
propcache==0.3.1
|
||||
pyasn1==0.6.1
|
||||
pyTelegramBotAPI==4.27.0
|
||||
pytz==2025.2
|
||||
pywin32==310
|
||||
pyzabbix==1.3.1
|
||||
requests==2.32.3
|
||||
SQLAlchemy==2.0.40
|
||||
telebot==0.0.5
|
||||
typing_extensions==4.13.2
|
||||
tzdata==2025.2
|
||||
urllib3==2.4.0
|
||||
Werkzeug==3.1.3
|
||||
WTForms==3.2.1
|
||||
yarl==1.20.0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user