refactor(alerts): improve active problem fetching and message formatting
Reworked the logic for retrieving data from Zabbix API to make it more efficient and filter-aware. Message generation for Telegram bot was refactored and decoupled from data retrieval logic to improve structure, readability, and reuse. Signed-off-by: UdoChudo <stream@udochudo.ru>
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
from telebot.types import Message, CallbackQuery
|
||||
|
||||
from app.bot.keyboards.active_triggers import create_region_keyboard
|
||||
from app.bot.utils.regions import get_sorted_regions_plain
|
||||
from app.bot.processors.active_triggers_processor import (
|
||||
process_region_selection,
|
||||
process_group_selection,
|
||||
process_all_groups_request,
|
||||
)
|
||||
from app.bot.utils.regions import get_sorted_regions_plain
|
||||
|
||||
|
||||
def register_active_triggers(bot, app, state_manager):
|
||||
@@ -22,17 +22,28 @@ def register_callbacks_active_triggers(bot,app,state_manager):
|
||||
@bot.callback_query_handler(func=lambda c: c.data.startswith("region_"))
|
||||
def region_selected(callback_query: CallbackQuery):
|
||||
region_id = callback_query.data.split("_")[1]
|
||||
process_region_selection(callback_query.message.chat.id,bot, region_id)
|
||||
chat_id = callback_query.message.chat.id
|
||||
bot.answer_callback_query(callback_query.id)
|
||||
bot.delete_message(chat_id, callback_query.message.message_id)
|
||||
process_region_selection(bot, chat_id, region_id)
|
||||
|
||||
@bot.callback_query_handler(func=lambda c: c.data.startswith("group_"))
|
||||
def group_selected(callback_query: CallbackQuery):
|
||||
group_id = callback_query.data.split("_")[1]
|
||||
process_group_selection(callback_query.message.chat.id,bot, group_id)
|
||||
chat_id = callback_query.message.chat.id
|
||||
bot.answer_callback_query(callback_query.id)
|
||||
bot.delete_message(chat_id, callback_query.message.message_id)
|
||||
bot.send_message(chat_id, f"Обработка...")
|
||||
process_group_selection(bot, chat_id, group_id)
|
||||
|
||||
@bot.callback_query_handler(func=lambda c: c.data.startswith("all_groups_"))
|
||||
def all_groups_selected(callback_query: CallbackQuery):
|
||||
region_id = callback_query.data.split("_")[2]
|
||||
process_all_groups_request(callback_query.message.chat.id,bot, region_id)
|
||||
chat_id = callback_query.message.chat.id
|
||||
bot.answer_callback_query(callback_query.id)
|
||||
bot.delete_message(chat_id, callback_query.message.message_id)
|
||||
bot.send_message(chat_id, f"Обработка...")
|
||||
process_all_groups_request(bot, chat_id, region_id)
|
||||
|
||||
@bot.callback_query_handler(func=lambda c: c.data.startswith("regions_page_"))
|
||||
def regions_page_selected(callback_query: CallbackQuery):
|
||||
|
||||
Reference in New Issue
Block a user