This commit is contained in:
michel_929 2024-11-10 19:46:38 +00:00 committed by GitHub
commit 71db2d342e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 113 additions and 6 deletions

View file

@ -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) {

View file

@ -1,5 +1,5 @@
<template>
<div class="mb-3">
<div v-if="$parent.notification.webhookContentType != 'CompletlyCustom'" class="mb-3">
<label for="webhook-url" class="form-label">{{ $t("Post URL") }}</label>
<input
id="webhook-url"
@ -10,7 +10,28 @@
required
/>
</div>
<div v-if="$parent.notification.webhookContentType == 'CompletlyCustom'" class="mb-3">
<label for="webhook-url" class="form-label">{{ $t("Post URL UP") }}</label>
<input
id="webhook-url"
v-model="$parent.notification.webhookURLUp"
type="url"
pattern="https?://.+"
class="form-control"
required
/>
</div>
<div v-if="$parent.notification.webhookContentType == 'CompletlyCustom'" class="mb-3">
<label for="webhook-url" class="form-label">{{ $t("Post URL DOWN") }}</label>
<input
id="webhook-url"
v-model="$parent.notification.webhookURLDown"
type="url"
pattern="https?://.+"
class="form-control"
required
/>
</div>
<div class="mb-3">
<label for="webhook-request-body" class="form-label">{{ $t("Request Body") }}</label>
<select
@ -22,6 +43,7 @@
<option value="json">{{ $t("webhookBodyPresetOption", ["application/json"]) }}</option>
<option value="form-data">{{ $t("webhookBodyPresetOption", ["multipart/form-data"]) }}</option>
<option value="custom">{{ $t("webhookBodyCustomOption") }}</option>
<option value="CompletlyCustom">{{ $t("Completly Custom") }}</option>
</select>
<div v-if="$parent.notification.webhookContentType == 'json'" class="form-text">{{ $t("webhookJsonDesc", ['"application/json"']) }}</div>
@ -47,6 +69,27 @@
required
></textarea>
</template>
<template v-if="$parent.notification.webhookContentType == 'CompletlyCustom'">
<br>
<label for="customBodyUp" class="form-label">{{ $t("Body UP") }}</label>
<textarea
id="customBodyUp"
v-model="$parent.notification.webhookCustomBodyUp"
class="form-control"
:placeholder="customBodyPlaceholder"
required
></textarea>
</template>
<template v-if="$parent.notification.webhookContentType == 'CompletlyCustom'">
<label for="customBodyDown" class="form-label">{{ $t("Body DOWN") }}</label>
<textarea
id="customBodyDown"
v-model="$parent.notification.webhookCustomBodyDown"
class="form-control"
:placeholder="customBodyPlaceholder"
required
></textarea>
</template>
</div>
<div class="mb-3">
@ -56,13 +99,32 @@
</div>
<div class="form-text">{{ $t("webhookAdditionalHeadersDesc") }}</div>
<textarea
v-if="showAdditionalHeadersField"
v-if="showAdditionalHeadersField && $parent.notification.webhookContentType != 'CompletlyCustom'"
id="additionalHeaders"
v-model="$parent.notification.webhookAdditionalHeaders"
class="form-control"
:placeholder="headersPlaceholder"
:required="showAdditionalHeadersField"
></textarea>
<div v-if="$parent.notification.webhookContentType == 'CompletlyCustom' && showAdditionalHeadersField">
<label for="additionalHeadersUp" class="form-label">{{ $t("Header UP") }}</label>
<textarea
id="additionalHeadersUp"
v-model="$parent.notification.webhookAdditionalHeadersUp"
class="form-control"
:placeholder="headersPlaceholder"
:required="showAdditionalHeadersField"
></textarea>
<label for="additionalHeadersDown" class="form-label">{{ $t("Header DOWN") }}</label>
<textarea
id="additionalHeadersDown"
v-model="$parent.notification.webhookAdditionalHeadersDown"
class="form-control"
:placeholder="headersPlaceholder"
:required="showAdditionalHeadersField"
></textarea>
</div>
</div>
</template>

View file

@ -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"
}