add formating to the pipeline
This commit is contained in:
parent
d8aff91f6f
commit
d9ef6690fc
2 changed files with 39 additions and 1 deletions
|
@ -3,6 +3,7 @@ import asyncio
|
|||
|
||||
from .config import load_config
|
||||
from .bot import send_messages
|
||||
from .format import format_alerts
|
||||
from .webhook import run_webhook
|
||||
|
||||
async def main():
|
||||
|
@ -12,14 +13,19 @@ async def main():
|
|||
|
||||
config = load_config(args.config)
|
||||
alert_queue = asyncio.Queue()
|
||||
message_queue = asyncio.Queue()
|
||||
|
||||
bot_corout = send_messages(
|
||||
alert_queue, # Will change in the futur
|
||||
message_queue,
|
||||
config.username,
|
||||
config.homeserver,
|
||||
config.password,
|
||||
config.alert_rooms
|
||||
)
|
||||
format_corout = format_alerts(
|
||||
alert_queue,
|
||||
message_queue
|
||||
)
|
||||
webhook_corout = run_webhook(
|
||||
alert_queue,
|
||||
config.host,
|
||||
|
@ -29,6 +35,7 @@ async def main():
|
|||
|
||||
await asyncio.gather(
|
||||
bot_corout,
|
||||
format_corout,
|
||||
webhook_corout
|
||||
)
|
||||
|
||||
|
|
31
src/kassandra/format.py
Normal file
31
src/kassandra/format.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
"""
|
||||
Format the alert message.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from typing import (
|
||||
Any,
|
||||
NoReturn
|
||||
)
|
||||
|
||||
def format_alert(
|
||||
alert: dict[str, Any]
|
||||
)->str:
|
||||
"""
|
||||
Format an alert in json format to a nice string.
|
||||
"""
|
||||
return str(alert)
|
||||
|
||||
async def format_alerts(
|
||||
alert_queue: asyncio.Queue[dict[str,Any]],
|
||||
message_queue: asyncio.Queue[str]
|
||||
)->NoReturn:
|
||||
"""
|
||||
Read alerts from alert_queue, format them, and put them in message_queue.
|
||||
"""
|
||||
while True:
|
||||
alert = await alert_queue.get()
|
||||
message = format_alert(alert)
|
||||
await message_queue.put(message)
|
||||
alert_queue.task_done()
|
||||
|
Loading…
Reference in a new issue