Compare commits

...

6 commits

Author SHA1 Message Date
michel_929
d63b65f21a
Merge 1fbe6b7ff4 into 8a432ac937 2024-11-12 18:00:27 +00:00
Ionys
8a432ac937
fix(status page): Make sure the group deletion is correctly handled when groupIDList is empty (#5340)
Some checks failed
Auto Test / check-linters (push) Has been cancelled
Auto Test / armv7-simple-test (18, ARMv7) (push) Has been cancelled
Auto Test / armv7-simple-test (20, ARMv7) (push) Has been cancelled
Auto Test / e2e-test (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
Merge Conflict Labeler / Labeling (push) Has been cancelled
validate / json-yaml-validate (push) Has been cancelled
validate / validate (push) Has been cancelled
Auto Test / auto-test (18, ARM64) (push) Has been cancelled
Auto Test / auto-test (18, macos-latest) (push) Has been cancelled
Auto Test / auto-test (18, ubuntu-latest) (push) Has been cancelled
Auto Test / auto-test (18, windows-latest) (push) Has been cancelled
Auto Test / auto-test (20, ARM64) (push) Has been cancelled
Auto Test / auto-test (20, macos-latest) (push) Has been cancelled
Auto Test / auto-test (20, ubuntu-latest) (push) Has been cancelled
Auto Test / auto-test (20, windows-latest) (push) Has been cancelled
2024-11-12 19:00:09 +01:00
michel_929
1fbe6b7ff4 Update Webhook.vue 2024-11-10 20:45:50 +01:00
michel_929
34d7ec3386 Update Webhook.vue 2024-11-10 20:44:47 +01:00
michel_929
ae0d07737e Edit webhook.js and Webhook.vue
Check linters
2024-11-10 20:41:19 +01:00
michel_929
4c79cf1186 Create Webhook Option Completly Custom
An option that allows you to send two different post requests depending on the status (UP and DOWN)
2024-11-10 20:30:27 +01:00
4 changed files with 123 additions and 12 deletions

View file

@ -21,6 +21,7 @@ class Webhook extends NotificationProvider {
let config = { let config = {
headers: {} headers: {}
}; };
let url = notification.webhookURL;
if (notification.webhookContentType === "form-data") { if (notification.webhookContentType === "form-data") {
const formData = new FormData(); const formData = new FormData();
@ -28,6 +29,8 @@ class Webhook extends NotificationProvider {
config.headers = formData.getHeaders(); config.headers = formData.getHeaders();
data = formData; data = formData;
} else if (notification.webhookContentType === "custom") { } else if (notification.webhookContentType === "custom") {
console.log(msg);
// Initialize LiquidJS and parse the custom Body Template // Initialize LiquidJS and parse the custom Body Template
const engine = new Liquid(); const engine = new Liquid();
const tpl = engine.parse(notification.webhookCustomBody); const tpl = engine.parse(notification.webhookCustomBody);
@ -39,9 +42,44 @@ class Webhook extends NotificationProvider {
heartbeatJSON, heartbeatJSON,
monitorJSON 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) { 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 && notification.webhookContentType !== "CompletlyCustom") {
try { try {
config.headers = { config.headers = {
...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; return okMsg;
} catch (error) { } catch (error) {

View file

@ -220,6 +220,9 @@ module.exports.statusPageSocketHandler = (socket) => {
// Delete groups that are not in the list // Delete groups that are not in the list
log.debug("socket", "Delete groups that are not in the list"); log.debug("socket", "Delete groups that are not in the list");
if (groupIDList.length === 0) {
await R.exec("DELETE FROM `group` WHERE status_page_id = ?", [ statusPage.id ]);
} else {
const slots = groupIDList.map(() => "?").join(","); const slots = groupIDList.map(() => "?").join(",");
const data = [ const data = [
@ -227,6 +230,7 @@ module.exports.statusPageSocketHandler = (socket) => {
statusPage.id statusPage.id
]; ];
await R.exec(`DELETE FROM \`group\` WHERE id NOT IN (${slots}) AND status_page_id = ?`, data); await R.exec(`DELETE FROM \`group\` WHERE id NOT IN (${slots}) AND status_page_id = ?`, data);
}
const server = UptimeKumaServer.getInstance(); const server = UptimeKumaServer.getInstance();

View file

@ -1,5 +1,5 @@
<template> <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> <label for="webhook-url" class="form-label">{{ $t("Post URL") }}</label>
<input <input
id="webhook-url" id="webhook-url"
@ -10,7 +10,28 @@
required required
/> />
</div> </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"> <div class="mb-3">
<label for="webhook-request-body" class="form-label">{{ $t("Request Body") }}</label> <label for="webhook-request-body" class="form-label">{{ $t("Request Body") }}</label>
<select <select
@ -22,6 +43,7 @@
<option value="json">{{ $t("webhookBodyPresetOption", ["application/json"]) }}</option> <option value="json">{{ $t("webhookBodyPresetOption", ["application/json"]) }}</option>
<option value="form-data">{{ $t("webhookBodyPresetOption", ["multipart/form-data"]) }}</option> <option value="form-data">{{ $t("webhookBodyPresetOption", ["multipart/form-data"]) }}</option>
<option value="custom">{{ $t("webhookBodyCustomOption") }}</option> <option value="custom">{{ $t("webhookBodyCustomOption") }}</option>
<option value="CompletlyCustom">{{ $t("Completly Custom") }}</option>
</select> </select>
<div v-if="$parent.notification.webhookContentType == 'json'" class="form-text">{{ $t("webhookJsonDesc", ['"application/json"']) }}</div> <div v-if="$parent.notification.webhookContentType == 'json'" class="form-text">{{ $t("webhookJsonDesc", ['"application/json"']) }}</div>
@ -47,6 +69,27 @@
required required
></textarea> ></textarea>
</template> </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>
<div class="mb-3"> <div class="mb-3">
@ -56,13 +99,32 @@
</div> </div>
<div class="form-text">{{ $t("webhookAdditionalHeadersDesc") }}</div> <div class="form-text">{{ $t("webhookAdditionalHeadersDesc") }}</div>
<textarea <textarea
v-if="showAdditionalHeadersField" v-if="showAdditionalHeadersField && $parent.notification.webhookContentType != 'CompletlyCustom'"
id="additionalHeaders" id="additionalHeaders"
v-model="$parent.notification.webhookAdditionalHeaders" v-model="$parent.notification.webhookAdditionalHeaders"
class="form-control" class="form-control"
:placeholder="headersPlaceholder" :placeholder="headersPlaceholder"
:required="showAdditionalHeadersField" :required="showAdditionalHeadersField"
></textarea> ></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> </div>
</template> </template>

View file

@ -1051,5 +1051,12 @@
"RabbitMQ Password": "RabbitMQ Password", "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}.", "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", "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"
} }