52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
|
from fastapi import APIRouter, Depends
|
||
|
import logging as log
|
||
|
|
||
|
from schemas import scomNetworkMessage
|
||
|
from auth import verify_token_scom
|
||
|
from redis_db import set_value, pop_value
|
||
|
from config import conf
|
||
|
from telegram import send_message
|
||
|
from telegram import del_message
|
||
|
|
||
|
router = APIRouter()
|
||
|
|
||
|
|
||
|
@router.post("/send-to-dashboard")
|
||
|
async def send_message_to_dashboard(
|
||
|
message: scomNetworkMessage,
|
||
|
token: str = Depends(verify_token_scom),
|
||
|
):
|
||
|
|
||
|
if message.alert_resolution_state == "Closed":
|
||
|
msg_id = await pop_value(f"scom:net:{message.alert_source}")
|
||
|
if msg_id:
|
||
|
msg_id = int(msg_id.decode("utf-8"))
|
||
|
await del_message(message_id=msg_id, chat_id=conf.tg.chat_id)
|
||
|
return
|
||
|
|
||
|
result = await send_message(
|
||
|
text=f"‼️{message.alert_resolution_state} {message.alert_source} is not responding",
|
||
|
chat_id=conf.tg.chat_id,
|
||
|
message_thread_id=conf.tg.dashboard_tred_id,
|
||
|
)
|
||
|
if result and result["status"] == 200:
|
||
|
await set_value(f"scom:net:{message.alert_source}", result["msg_id"])
|
||
|
|
||
|
|
||
|
@router.post("/send-to-net-chat")
|
||
|
async def send_message_to_net_chat(
|
||
|
message: scomNetworkMessage,
|
||
|
token: str = Depends(verify_token_scom),
|
||
|
):
|
||
|
if message.alert_resolution_state == "New":
|
||
|
text = f"‼️{message.alert_resolution_state} {message.alert_source} is not responding"
|
||
|
else:
|
||
|
text = (
|
||
|
f"✅{message.alert_resolution_state} {message.alert_source} is responding"
|
||
|
)
|
||
|
await send_message(
|
||
|
text=text,
|
||
|
chat_id=conf.tg.chat_id,
|
||
|
message_thread_id=conf.tg.net_tred_id,
|
||
|
)
|