diff --git a/server/notification-providers/webhook.js b/server/notification-providers/webhook.js index 986986d44..156c40cdb 100644 --- a/server/notification-providers/webhook.js +++ b/server/notification-providers/webhook.js @@ -21,6 +21,7 @@ class Webhook extends NotificationProvider { let config = { headers: {} }; + let url = notification.webhookURL; if (notification.webhookContentType === "form-data") { const formData = new FormData(); @@ -28,6 +29,8 @@ class Webhook extends NotificationProvider { config.headers = formData.getHeaders(); data = formData; } else if (notification.webhookContentType === "custom") { + + console.log(msg); // Initialize LiquidJS and parse the custom Body Template const engine = new Liquid(); const tpl = engine.parse(notification.webhookCustomBody); @@ -39,9 +42,44 @@ class Webhook extends NotificationProvider { heartbeatJSON, monitorJSON }); + } else if (notification.webhookContentType === "CompletlyCustom") { + + if (msg.includes("Down")) { + const tpl = JSON.parse(notification.webhookCustomBodyDown); + // Insert templated values into Body + data = tpl; + url = notification.webhookURLDown; + + if (notification.webhookAdditionalHeaders) { + try { + config.headers = { + ...config.headers, + ...JSON.parse(notification.webhookAdditionalHeadersDown) + }; + } catch (err) { + throw "Additional Headers is not a valid JSON"; + } + } + } else { + const tpl = JSON.parse(notification.webhookCustomBodyUp); + // Insert templated values into Body + data = tpl; + url = notification.webhookURLUp; + + if (notification.webhookAdditionalHeaders) { + try { + config.headers = { + ...config.headers, + ...JSON.parse(notification.webhookAdditionalHeadersUp) + }; + } catch (err) { + throw "Additional Headers is not a valid JSON"; + } + } + } } - if (notification.webhookAdditionalHeaders) { + if (notification.webhookAdditionalHeaders && notification.webhookContentType !== "CompletlyCustom") { try { config.headers = { ...config.headers, @@ -52,7 +90,7 @@ class Webhook extends NotificationProvider { } } - await axios.post(notification.webhookURL, data, config); + await axios.post(url, data, config); return okMsg; } catch (error) { diff --git a/src/components/notifications/Webhook.vue b/src/components/notifications/Webhook.vue index 8c67a2745..30ab34e23 100644 --- a/src/components/notifications/Webhook.vue +++ b/src/components/notifications/Webhook.vue @@ -1,5 +1,5 @@ + +
@@ -56,13 +99,32 @@
{{ $t("webhookAdditionalHeadersDesc") }}
+ +
+ + + + +
diff --git a/src/lang/en.json b/src/lang/en.json index e215f1031..170eca7f1 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -1051,5 +1051,12 @@ "RabbitMQ Password": "RabbitMQ Password", "rabbitmqHelpText": "To use the monitor, you will need to enable the Management Plugin in your RabbitMQ setup. For more information, please consult the {rabitmq_documentation}.", "SendGrid API Key": "SendGrid API Key", - "Separate multiple email addresses with commas": "Separate multiple email addresses with commas" + "Separate multiple email addresses with commas": "Separate multiple email addresses with commas", + "Post URL DOWN": "Post URL Status = Down", + "Post URL UP": "Post URL Status = UP", + "Body UP": "Body Status = UP", + "Body DOWN": "Body Status = DOWN", + "Header UP": "Header Status = UP", + "Header DOWN": "Header Status = Down", + "Completly Custom": "Completly Custom Post Request" }