add message

This commit is contained in:
s.mostryukov 2025-03-14 11:28:11 +03:00
parent 91d6b2045f
commit be081cebfe
2 changed files with 21 additions and 8 deletions

View File

@ -13,7 +13,11 @@ dp = Dispatcher(storage=storage)
@dp.callback_query(F.data.startswith("h")) @dp.callback_query(F.data.startswith("h"))
async def handle_mute_1h(callback_query: types.CallbackQuery): 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 = ( new_text = (
callback_query.message.text callback_query.message.text
+ "\n" + "\n"
@ -25,7 +29,11 @@ async def handle_mute_1h(callback_query: types.CallbackQuery):
@dp.callback_query(F.data.startswith("d")) @dp.callback_query(F.data.startswith("d"))
async def handle_mute_1d(callback_query: types.CallbackQuery): 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 = ( new_text = (
callback_query.message.text callback_query.message.text
+ "\n" + "\n"
@ -37,7 +45,10 @@ async def handle_mute_1d(callback_query: types.CallbackQuery):
@dp.callback_query(F.data.startswith("c")) @dp.callback_query(F.data.startswith("c"))
async def handle_close(callback_query: types.CallbackQuery): 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 = ( new_text = (
callback_query.message.text callback_query.message.text
+ "\n" + "\n"

View File

@ -1,5 +1,6 @@
import logging as log import logging as log
from pyexpat.errors import messages
from zabbix_utils import ZabbixAPI from zabbix_utils import ZabbixAPI
from config import conf from config import conf
@ -44,7 +45,7 @@ def get_active_problems() -> dict:
log.warning("Get event from zabbix error") 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) api = ZabbixAPI(url=conf.zabbix.url, token=conf.zabbix.token)
if mute_time == 0: if mute_time == 0:
mute_to = 0 mute_to = 0
@ -53,8 +54,9 @@ def event_acknowledge(event_id: int, mute_time: int):
try: try:
response = api.event.acknowledge( response = api.event.acknowledge(
eventids=event_id, eventids=event_id,
action=34, action=38,
suppress_until=mute_to, suppress_until=mute_to,
message=muted_by,
) )
if response: if response:
log.info(f"Event {event_id} acknowledged") log.info(f"Event {event_id} acknowledged")
@ -64,14 +66,14 @@ def event_acknowledge(event_id: int, mute_time: int):
return False 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) api = ZabbixAPI(url=conf.zabbix.url, token=conf.zabbix.token)
try: try:
response = api.event.acknowledge( response = api.event.acknowledge(
eventids=event_id, eventids=event_id,
action=1, action=5,
message=closed_by,
) )
print(response)
if response: if response:
log.info(f"Event {event_id} closed") log.info(f"Event {event_id} closed")
return True return True