update verify event shipper to send a test payload
Taylor committed
Jun 20, 2024 at 13:24 UTC
76319feb9ff4e8b004094c7e5f768dc31b5ebb2c
1 file changed
+27
-1
backend/app/integrations/utils/event_shipper.py
+27
-1
@@ -44,6 +44,25 @@ async def event_shipper(message: EventShipperPayload) -> EventShipperPayloadResp
44
message="Successfully sent test message to log shipper.",
45
)
46
47
+async def send_json_test_message_to_event_shipper(message: EventShipperPayload) -> EventShipperPayloadResponse:
48
+ """
49
+ Sends a test message to the Graylog Input.
50
+ """
51
+ gelf_logger = await get_gelf_logger()
52
+
53
+ try:
54
+ await gelf_logger.tcp_handler(message=message)
55
+ except Exception as e:
56
+ logger.error(f"Failed to send test message to log shipper: {e}")
57
+ raise HTTPException(
58
+ status_code=500,
59
+ detail=f"Failed to send test message to log shipper: {e}",
60
+ )
61
+
62
+ return EventShipperPayloadResponse(
63
+ success=True,
64
+ message="Successfully sent test message to log shipper.",
65
+ )
66
67
async def verify_event_shipper_healtcheck(attributes: Dict[str, Any]) -> Dict[str, Any]:
68
"""
@@ -56,7 +75,7 @@ async def verify_event_shipper_healtcheck(attributes: Dict[str, Any]) -> Dict[st
75
f"Verifying the event shipper connection to {attributes['connector_url']}",
76
)
77
59
- # MAke a TCP connection to the Graylog Input
78
+ # Make a TCP connection to the Graylog Input
79
try:
80
reader, writer = await asyncio.open_connection(
81
attributes["connector_url"],
@@ -64,6 +83,13 @@ async def verify_event_shipper_healtcheck(attributes: Dict[str, Any]) -> Dict[st
83
)
84
writer.close()
85
await writer.wait_closed()
86
+ await send_json_test_message_to_event_shipper(
87
+ EventShipperPayload(
88
+ message="Healthcheck successful",
89
+ integration="event_shipper",
90
+ customer_code='n/a',
91
+ ),
92
+ )
93
return {
94
"connectionSuccessful": True,
95
"message": "Event shipper healthcheck successful",