add webhook
parent
eb8cdefab4
commit
80891eeda2
@ -0,0 +1,35 @@
|
||||
"""
|
||||
The webhook receiving the alerts from alertmanager.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import aiohttp.web
|
||||
import aiohttp.web_request
|
||||
|
||||
from typing import (
|
||||
Any,
|
||||
NoReturn
|
||||
)
|
||||
|
||||
ENDPOINT = "/webhook"
|
||||
|
||||
async def run_webhook(
|
||||
alert_queue: asyncio.Queue[dict[str, Any]],
|
||||
host: str,
|
||||
port: int
|
||||
)->NoReturn:
|
||||
"""
|
||||
Run the webhook endpoint and put the alerts in the queue.
|
||||
"""
|
||||
|
||||
async def handler(request:aiohttp.web_request.Request):
|
||||
alert = await request.json()
|
||||
await alert_queue.put(alert)
|
||||
return aiohttp.web.Response()
|
||||
|
||||
app = aiohttp.web.Application()
|
||||
app.add_routes([aiohttp.web.post(ENDPOINT, handler)])
|
||||
runner = aiohttp.web.AppRunner(app)
|
||||
await runner.setup()
|
||||
site = aiohttp.web.TCPSite(runner, host, port)
|
||||
await site.start()
|
Loading…
Reference in New Issue