mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-23 14:54:05 +00:00
Compare commits
6 commits
c4f80058d0
...
d63b65f21a
Author | SHA1 | Date | |
---|---|---|---|
|
d63b65f21a | ||
|
8a432ac937 | ||
|
1fbe6b7ff4 | ||
|
34d7ec3386 | ||
|
ae0d07737e | ||
|
4c79cf1186 |
4 changed files with 123 additions and 12 deletions
|
@ -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) {
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
|
|
@ -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>
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue