From 73362793ad9573c790542f9dedb00830235b926f Mon Sep 17 00:00:00 2001 From: StarFleetCPTN Date: Thu, 20 Mar 2025 18:49:32 -0700 Subject: [PATCH] Add Webhook Notification Testing to Admin Tools - Introduced a new section for testing webhook notifications within the admin tools. - Added a form to input webhook URL, secret, custom headers, and payload for testing. - Implemented backend logic to handle webhook test requests and display results. - Created a toast notification component to show success or failure messages for webhook tests. - Updated the AdminToolsData structure to include fields for webhook test results. --- components/admin_tools.templ | 223 +++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+) diff --git a/components/admin_tools.templ b/components/admin_tools.templ index e5a0a4e..cabe33c 100644 --- a/components/admin_tools.templ +++ b/components/admin_tools.templ @@ -39,6 +39,10 @@ type AdminToolsData struct { EmailTestSuccess *bool EmailTestMessage string SmtpServer string + WebhookTestSuccess *bool + WebhookTestMessage string + WebhookStatusCode int + WebhookResponse string } // Dialog component for confirmation dialogs @@ -561,6 +565,160 @@ templ AdminTools(ctx context.Context, data AdminToolsData) { + +
+
+
+

+ + Webhook Notification Testing +

+
+
+

+ Test webhook notifications by sending a sample job execution payload to your webhook endpoint. +

+ +
+
+
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+

+ + Used to sign webhook payloads (X-Hub-Signature-256 header) +

+
+ +
+ +
+
+ +
+ +
+

+ + Additional HTTP headers as JSON +

+
+ +
+ + +

+ + Leave empty to use default test payload +

+
+ +
+ +
+
+
+ + + + + +
+

+ + Default Webhook Test Payload +

+
+
{
+  "event_type": "job_execution",
+  "job_id": 123,
+  "job_name": "Test Job",
+  "config_id": 456,
+  "config_name": "Test Config",
+  "status": "completed",
+  "start_time": "2023-06-18T15:30:45Z",
+  "end_time": "2023-06-18T15:35:12Z",
+  "duration_seconds": 267,
+  "history_id": 789,
+  "bytes_transferred": 1048576,
+  "files_transferred": 5,
+  "source": {
+    "type": "local",
+    "path": "/path/to/source"
+  },
+  "destination": {
+    "type": "s3",
+    "path": "bucket/path"
+  }
+}
+
+
+
+
+
+
@BackupsList(data) @@ -1169,3 +1327,68 @@ script fadeInAnimation() { document.head.appendChild(style); } } + +// WebhookTestToast is a component for showing webhook test results +templ WebhookTestToast(success bool, message string, statusCode int, responseBody string) { +
+
+
+ if success { + + } else { + + } +
+
+

+ if success { + Webhook Sent Successfully + } else { + Webhook Sending Failed + } +

+
+ { message } +
+ + +
+
Status Code: { fmt.Sprint(statusCode) }
+ if responseBody != "" { +
+
Response:
+
+
{ responseBody }
+
+
+ } +
+
+
+ +
+
+
+}