add message
This commit is contained in:
		
							parent
							
								
									91d6b2045f
								
							
						
					
					
						commit
						be081cebfe
					
				| 
						 | 
				
			
			@ -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"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue