From be081cebfe57b29260a3c8979eae52c23d09ce40 Mon Sep 17 00:00:00 2001 From: "s.mostryukov" Date: Fri, 14 Mar 2025 11:28:11 +0300 Subject: [PATCH] add message --- telegram/bot.py | 17 ++++++++++++++--- zabbix/zabbix_api.py | 12 +++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/telegram/bot.py b/telegram/bot.py index 67695b0..3d911ac 100644 --- a/telegram/bot.py +++ b/telegram/bot.py @@ -13,7 +13,11 @@ dp = Dispatcher(storage=storage) @dp.callback_query(F.data.startswith("h")) async def handle_mute_1h(callback_query: types.CallbackQuery): - if event_acknowledge(int(callback_query.data[1:]), 1): + if event_acknowledge( + int(callback_query.data[1:]), + 1, + callback_query.from_user.username, + ): new_text = ( callback_query.message.text + "\n" @@ -25,7 +29,11 @@ async def handle_mute_1h(callback_query: types.CallbackQuery): @dp.callback_query(F.data.startswith("d")) async def handle_mute_1d(callback_query: types.CallbackQuery): - if event_acknowledge(int(callback_query.data[1:]), 24): + if event_acknowledge( + int(callback_query.data[1:]), + 24, + callback_query.from_user.username, + ): new_text = ( callback_query.message.text + "\n" @@ -37,7 +45,10 @@ async def handle_mute_1d(callback_query: types.CallbackQuery): @dp.callback_query(F.data.startswith("c")) async def handle_close(callback_query: types.CallbackQuery): - if event_close(int(callback_query.data[1:])): + if event_close( + int(callback_query.data[1:]), + callback_query.from_user.username, + ): new_text = ( callback_query.message.text + "\n" diff --git a/zabbix/zabbix_api.py b/zabbix/zabbix_api.py index 180c47b..44c6b2a 100644 --- a/zabbix/zabbix_api.py +++ b/zabbix/zabbix_api.py @@ -1,5 +1,6 @@ import logging as log +from pyexpat.errors import messages from zabbix_utils import ZabbixAPI from config import conf @@ -44,7 +45,7 @@ def get_active_problems() -> dict: log.warning("Get event from zabbix error") -def event_acknowledge(event_id: int, mute_time: int): +def event_acknowledge(event_id: int, mute_time: int, muted_by: str): api = ZabbixAPI(url=conf.zabbix.url, token=conf.zabbix.token) if mute_time == 0: mute_to = 0 @@ -53,8 +54,9 @@ def event_acknowledge(event_id: int, mute_time: int): try: response = api.event.acknowledge( eventids=event_id, - action=34, + action=38, suppress_until=mute_to, + message=muted_by, ) if response: log.info(f"Event {event_id} acknowledged") @@ -64,14 +66,14 @@ def event_acknowledge(event_id: int, mute_time: int): return False -def event_close(event_id: int): +def event_close(event_id: int, closed_by: str): api = ZabbixAPI(url=conf.zabbix.url, token=conf.zabbix.token) try: response = api.event.acknowledge( eventids=event_id, - action=1, + action=5, + message=closed_by, ) - print(response) if response: log.info(f"Event {event_id} closed") return True