fix: (active triggers) add additional error message when zabbix server is unreachable, add error logging to console
Build and Push Docker Images / build (push) Successful in 1m18s

Signed-off-by: UdoChudo <stream@udochudo.ru>
This commit is contained in:
2025-06-25 16:05:54 +05:00
parent a1c36de342
commit 2b65d11622
2 changed files with 50 additions and 25 deletions
+40 -14
View File
@@ -1,3 +1,4 @@
from telebot import logger
from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton
from app.bot.keyboards.groups import create_groups_keyboard
@@ -12,10 +13,14 @@ from app.bot.utils.zabbix_alt import (
def process_region_selection(bot, chat_id, region_id):
try:
groups = get_region_groups(region_id)
if groups is None:
return bot.send_message(chat_id, "❌ Сервер Zabbix временно недоступен. Попробуйте позже.", reply_markup=get_main_menu())
if not groups:
return bot.send_message(chat_id, "Нет групп хостов для этого региона.")
return bot.send_message(chat_id, "Нет групп хостов для этого региона.", reply_markup=get_main_menu())
markup = create_groups_keyboard(groups, region_id)
bot.send_message(chat_id, "Выберите группу хостов:", reply_markup=markup)
except Exception as e:
bot.send_message(chat_id, f"Ошибка при получении групп: {str(e)}", reply_markup=get_main_menu())
@@ -23,40 +28,61 @@ def process_region_selection(bot, chat_id, region_id):
def process_group_selection(bot, chat_id, group_id):
try:
triggers = fetch_triggers_data(group_id)
if triggers is None:
return bot.send_message(chat_id, "❌ Сервер Zabbix временно недоступен. Попробуйте позже.")
if not triggers:
bot.send_message(chat_id, "Нет активных событий.")
return
return bot.send_message(chat_id, "Нет активных событий.")
for trigger in triggers:
text, url = format_trigger_for_tg(trigger)
markup = InlineKeyboardMarkup()
markup.add(InlineKeyboardButton(text="Открыть график", url=url))
bot.send_message(chat_id, text, reply_markup=markup, parse_mode="HTML")
try:
text, url = format_trigger_for_tg(trigger)
markup = InlineKeyboardMarkup()
markup.add(InlineKeyboardButton(text="Открыть график", url=url))
bot.send_message(chat_id, text, reply_markup=markup, parse_mode="HTML")
except Exception as e:
logger.error(f"[Bot] Ошибка при отправке сообщения о триггере: {e}")
continue
except Exception as e:
bot.send_message(chat_id, f"Ошибка при получении событий: {str(e)}")
def process_all_groups_request(bot, chat_id, region_id):
try:
all_triggers = []
groups = get_all_groups_for_region(region_id)
zabbix_error = False
for group in groups:
try:
triggers = fetch_triggers_data(group['groupid'])
if triggers is None:
zabbix_error = True
continue
if triggers:
all_triggers.extend(triggers)
except Exception:
except Exception as e:
logger.error(f"[Bot] Ошибка при обработке группы {group['name']}: {e}")
continue
if zabbix_error and not all_triggers:
return bot.send_message(chat_id, "❌ Сервер Zabbix временно недоступен. Попробуйте позже.")
if not all_triggers:
bot.send_message(chat_id, "Нет активных событий.")
return
return bot.send_message(chat_id, "Нет активных событий.")
for trigger in all_triggers:
text, url = format_trigger_for_tg(trigger)
markup = InlineKeyboardMarkup()
markup.add(InlineKeyboardButton(text="Открыть график", url=url))
bot.send_message(chat_id, text, reply_markup=markup, parse_mode="HTML")
try:
text, url = format_trigger_for_tg(trigger)
markup = InlineKeyboardMarkup()
markup.add(InlineKeyboardButton(text="Открыть график", url=url))
bot.send_message(chat_id, text, reply_markup=markup, parse_mode="HTML")
except Exception as e:
logger.error(f"[Bot] Ошибка при отправке события: {e}")
continue
except Exception as e:
bot.send_message(chat_id, f"Ошибка при получении данных: {str(e)}")