Compare commits
No commits in common. "161ad3eaa32e8e8ca55cecff0180cf91de5dac3d" and "3d5a237d4dcce9437c4e04de68a170dfe4dfeaa4" have entirely different histories.
161ad3eaa3
...
3d5a237d4d
@ -1,12 +1,8 @@
|
|||||||
# composer.py
|
# composer.py
|
||||||
|
|
||||||
from datetime import datetime
|
import time
|
||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
from zoneinfo import ZoneInfo
|
from app.bot.utils.tg_escape_chars import escape_telegram_chars # или твоя функция, если кастомная
|
||||||
|
|
||||||
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]]:
|
def compose_telegram_message(data: dict) -> Tuple[str, Optional[str]]:
|
||||||
"""
|
"""
|
||||||
@ -23,12 +19,6 @@ def compose_telegram_message(data: dict) -> Tuple[str, Optional[str]]:
|
|||||||
'High': '⚠️',
|
'High': '⚠️',
|
||||||
'Disaster': '⛔️'
|
'Disaster': '⛔️'
|
||||||
}
|
}
|
||||||
convert_time_format = {
|
|
||||||
"h": "ч",
|
|
||||||
"m": "м",
|
|
||||||
"s": "с"
|
|
||||||
}
|
|
||||||
|
|
||||||
priority = priority_map.get(data.get('severity', ''), '')
|
priority = priority_map.get(data.get('severity', ''), '')
|
||||||
msg = escape_telegram_chars(data.get('msg', ''))
|
msg = escape_telegram_chars(data.get('msg', ''))
|
||||||
host = escape_telegram_chars(data.get('host', ''))
|
host = escape_telegram_chars(data.get('host', ''))
|
||||||
@ -36,8 +26,7 @@ def compose_telegram_message(data: dict) -> Tuple[str, Optional[str]]:
|
|||||||
severity = escape_telegram_chars(data.get('severity', ''))
|
severity = escape_telegram_chars(data.get('severity', ''))
|
||||||
status = data.get('status', '').upper()
|
status = data.get('status', '').upper()
|
||||||
timestamp = int(data.get('date_reception', 0))
|
timestamp = int(data.get('date_reception', 0))
|
||||||
dt = datetime.fromtimestamp(timestamp, tz=ZoneInfo(ZABBIX_TZ))
|
time_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp))
|
||||||
time_str = dt.strftime('%d.%m.%Y %H:%M:%S')
|
|
||||||
|
|
||||||
if status == "PROBLEM":
|
if status == "PROBLEM":
|
||||||
message = (
|
message = (
|
||||||
@ -47,36 +36,16 @@ def compose_telegram_message(data: dict) -> Tuple[str, Optional[str]]:
|
|||||||
f"<b>Время возникновения</b>: {time_str} Мск\n"
|
f"<b>Время возникновения</b>: {time_str} Мск\n"
|
||||||
)
|
)
|
||||||
else:
|
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 = (
|
message = (
|
||||||
f"✅ {host} ({ip})\n"
|
f"✅ {host} ({ip})\n"
|
||||||
f"<b>Описание</b>: {msg}\n"
|
f"<b>Описание</b>: {msg}\n"
|
||||||
f"<b>Критичность</b>: {severity}\n"
|
f"<b>Критичность</b>: {severity}\n"
|
||||||
f"<b>Проблема устранена!</b>\n"
|
f"<b>Проблема устранена!</b>\n"
|
||||||
f"<b>Время начала</b>: {time_start} Мск\n"
|
|
||||||
f"<b>Время устранения</b>: {time_str} Мск\n"
|
f"<b>Время устранения</b>: {time_str} Мск\n"
|
||||||
f"<b>Длительность проблемы</b>: {duration}\n"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
link = data.get("link")
|
link = data.get("link")
|
||||||
return message, link
|
return message, link
|
||||||
|
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
raise ValueError(f"Missing key in data: {e}")
|
raise ValueError(f"Missing key in data: {e}")
|
||||||
|
|||||||
@ -12,6 +12,6 @@ def create_link_button(link: Optional[str]) -> Optional[InlineKeyboardMarkup]:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
markup = InlineKeyboardMarkup()
|
markup = InlineKeyboardMarkup()
|
||||||
button = InlineKeyboardButton(text="Открыть график", url=link)
|
button = InlineKeyboardButton(text="График", url=link)
|
||||||
markup.add(button)
|
markup.add(button)
|
||||||
return markup
|
return markup
|
||||||
|
|||||||
@ -1,42 +1,14 @@
|
|||||||
aio-pika==9.5.5
|
telebot~=0.0.5
|
||||||
aiormq==6.8.1
|
pyTelegramBotAPI~=4.27.0
|
||||||
blinker==1.9.0
|
pyzabbix~=1.3.1
|
||||||
certifi==2025.4.26
|
SQLAlchemy~=2.0.40
|
||||||
charset-normalizer==3.4.2
|
Flask~=3.1.0
|
||||||
click==8.1.8
|
Flask-Login~=0.6.3
|
||||||
colorama==0.4.6
|
Flask-SQLAlchemy~=3.1.1
|
||||||
concurrent-log-handler==0.9.26
|
Flask-ldap3-login~=1.0.2
|
||||||
exceptiongroup==1.2.2
|
Werkzeug~=3.1.3
|
||||||
Flask==3.1.0
|
aio-pika~=9.5.5
|
||||||
flask-ldap3-login==1.0.2
|
pika~=1.3.2
|
||||||
Flask-Login==0.6.3
|
pytz~=2025.2
|
||||||
Flask-SQLAlchemy==3.1.1
|
requests~=2.32.3
|
||||||
Flask-WTF==1.2.2
|
gunicorn~=23.0.0
|
||||||
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