main
py 39 lines 1.21 KB
Raw
1 from fastapi import APIRouter
2 from fastapi import Security
3 from loguru import logger
4
5 from app.auth.routes.auth import AuthHandler
6 from app.integrations.utils.event_shipper import event_shipper
7 from app.integrations.utils.schema import EventShipperPayload
8
9 # App specific imports
10
11
12 graylog_receiver_router = APIRouter()
13
14
15 ################## ! GRAYLOG FORWARDER ! ##################
16 # ! This function is meant to receive a JSON payload from Shuffle (or another tool)
17 # ! and forward it to a Graylog server.
18 # ! Payload must include `customer_code` and `integration` fields.
19 @graylog_receiver_router.post(
20 "/receiver",
21 description="Forward a message to Graylog",
22 dependencies=[Security(AuthHandler().require_any_scope("admin"))],
23 )
24 async def forward_to_graylog(payload: dict) -> dict:
25 """
26 Forward a message to Graylog.
27
28 This endpoint forwards a message to Graylog.
29
30 Returns:
31 ConfiguredInputsResponse: The response containing the configured inputs.
32 """
33 logger.info("Forwarding message to Graylog")
34 logger.info(f"Payload: {payload}")
35 message = EventShipperPayload(
36 **payload,
37 )
38 await event_shipper(message)
39 return {"message": "Message forwarded to Graylog", "success": True}