mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-27 16:54:04 +00:00
improved zoho-cliq message format (#4848)
This commit is contained in:
commit
fbf7b77ceb
7 changed files with 40 additions and 108 deletions
|
@ -33,26 +33,6 @@ class Discord extends NotificationProvider {
|
||||||
return okMsg;
|
return okMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
let address;
|
|
||||||
|
|
||||||
switch (monitorJSON["type"]) {
|
|
||||||
case "ping":
|
|
||||||
address = monitorJSON["hostname"];
|
|
||||||
break;
|
|
||||||
case "port":
|
|
||||||
case "dns":
|
|
||||||
case "gamedig":
|
|
||||||
case "steam":
|
|
||||||
address = monitorJSON["hostname"];
|
|
||||||
if (monitorJSON["port"]) {
|
|
||||||
address += ":" + monitorJSON["port"];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
address = monitorJSON["url"];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If heartbeatJSON is not null, we go into the normal alerting loop.
|
// If heartbeatJSON is not null, we go into the normal alerting loop.
|
||||||
if (heartbeatJSON["status"] === DOWN) {
|
if (heartbeatJSON["status"] === DOWN) {
|
||||||
let discorddowndata = {
|
let discorddowndata = {
|
||||||
|
@ -68,7 +48,7 @@ class Discord extends NotificationProvider {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: monitorJSON["type"] === "push" ? "Service Type" : "Service URL",
|
name: monitorJSON["type"] === "push" ? "Service Type" : "Service URL",
|
||||||
value: monitorJSON["type"] === "push" ? "Heartbeat" : address,
|
value: this.extractAdress(monitorJSON),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: `Time (${heartbeatJSON["timezone"]})`,
|
name: `Time (${heartbeatJSON["timezone"]})`,
|
||||||
|
@ -105,7 +85,7 @@ class Discord extends NotificationProvider {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: monitorJSON["type"] === "push" ? "Service Type" : "Service URL",
|
name: monitorJSON["type"] === "push" ? "Service Type" : "Service URL",
|
||||||
value: monitorJSON["type"] === "push" ? "Heartbeat" : address,
|
value: this.extractAdress(monitorJSON),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: `Time (${heartbeatJSON["timezone"]})`,
|
name: `Time (${heartbeatJSON["timezone"]})`,
|
||||||
|
|
|
@ -19,6 +19,36 @@ class NotificationProvider {
|
||||||
throw new Error("Have to override Notification.send(...)");
|
throw new Error("Have to override Notification.send(...)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the address from a monitor JSON object based on its type.
|
||||||
|
* @param {?object} monitorJSON Monitor details (For Up/Down only)
|
||||||
|
* @returns {string} The extracted address based on the monitor type.
|
||||||
|
*/
|
||||||
|
extractAdress(monitorJSON) {
|
||||||
|
if (!monitorJSON) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
switch (monitorJSON["type"]) {
|
||||||
|
case "push":
|
||||||
|
return "Heartbeat";
|
||||||
|
case "ping":
|
||||||
|
return monitorJSON["hostname"];
|
||||||
|
case "port":
|
||||||
|
case "dns":
|
||||||
|
case "gamedig":
|
||||||
|
case "steam":
|
||||||
|
if (monitorJSON["port"]) {
|
||||||
|
return monitorJSON["hostname"] + ":" + monitorJSON["port"];
|
||||||
|
}
|
||||||
|
return monitorJSON["hostname"];
|
||||||
|
default:
|
||||||
|
if (![ "https://", "http://", "" ].includes(monitorJSON["url"])) {
|
||||||
|
return monitorJSON["url"];
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws an error
|
* Throws an error
|
||||||
* @param {any} error The error to throw
|
* @param {any} error The error to throw
|
||||||
|
|
|
@ -32,28 +32,7 @@ class SevenIO extends NotificationProvider {
|
||||||
return okMsg;
|
return okMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
let address = "";
|
let address = this.extractAdress(monitorJSON);
|
||||||
|
|
||||||
switch (monitorJSON["type"]) {
|
|
||||||
case "ping":
|
|
||||||
address = monitorJSON["hostname"];
|
|
||||||
break;
|
|
||||||
case "port":
|
|
||||||
case "dns":
|
|
||||||
case "gamedig":
|
|
||||||
case "steam":
|
|
||||||
address = monitorJSON["hostname"];
|
|
||||||
if (monitorJSON["port"]) {
|
|
||||||
address += ":" + monitorJSON["port"];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (![ "https://", "http://", "" ].includes(monitorJSON["url"])) {
|
|
||||||
address = monitorJSON["url"];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (address !== "") {
|
if (address !== "") {
|
||||||
address = `(${address}) `;
|
address = `(${address}) `;
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,12 +93,7 @@ class SMTP extends NotificationProvider {
|
||||||
|
|
||||||
if (monitorJSON !== null) {
|
if (monitorJSON !== null) {
|
||||||
monitorName = monitorJSON["name"];
|
monitorName = monitorJSON["name"];
|
||||||
|
monitorHostnameOrURL = this.extractAdress(monitorJSON);
|
||||||
if (monitorJSON["type"] === "http" || monitorJSON["type"] === "keyword" || monitorJSON["type"] === "json-query") {
|
|
||||||
monitorHostnameOrURL = monitorJSON["url"];
|
|
||||||
} else {
|
|
||||||
monitorHostnameOrURL = monitorJSON["hostname"];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let serviceStatus = "⚠️ Test";
|
let serviceStatus = "⚠️ Test";
|
||||||
|
|
|
@ -34,25 +34,7 @@ class Squadcast extends NotificationProvider {
|
||||||
data.status = "resolve";
|
data.status = "resolve";
|
||||||
}
|
}
|
||||||
|
|
||||||
let address;
|
data.tags["AlertAddress"] = this.extractAdress(monitorJSON);
|
||||||
switch (monitorJSON["type"]) {
|
|
||||||
case "ping":
|
|
||||||
address = monitorJSON["hostname"];
|
|
||||||
break;
|
|
||||||
case "port":
|
|
||||||
case "dns":
|
|
||||||
case "steam":
|
|
||||||
address = monitorJSON["hostname"];
|
|
||||||
if (monitorJSON["port"]) {
|
|
||||||
address += ":" + monitorJSON["port"];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
address = monitorJSON["url"];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
data.tags["AlertAddress"] = address;
|
|
||||||
|
|
||||||
monitorJSON["tags"].forEach(tag => {
|
monitorJSON["tags"].forEach(tag => {
|
||||||
data.tags[tag["name"]] = {
|
data.tags[tag["name"]] = {
|
||||||
|
|
|
@ -216,21 +216,6 @@ class Teams extends NotificationProvider {
|
||||||
return okMsg;
|
return okMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
let monitorUrl;
|
|
||||||
|
|
||||||
switch (monitorJSON["type"]) {
|
|
||||||
case "http":
|
|
||||||
case "keywork":
|
|
||||||
monitorUrl = monitorJSON["url"];
|
|
||||||
break;
|
|
||||||
case "docker":
|
|
||||||
monitorUrl = monitorJSON["docker_host"];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
monitorUrl = monitorJSON["hostname"];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const baseURL = await setting("primaryBaseURL");
|
const baseURL = await setting("primaryBaseURL");
|
||||||
let dashboardUrl;
|
let dashboardUrl;
|
||||||
if (baseURL) {
|
if (baseURL) {
|
||||||
|
@ -240,7 +225,7 @@ class Teams extends NotificationProvider {
|
||||||
const payload = this._notificationPayloadFactory({
|
const payload = this._notificationPayloadFactory({
|
||||||
heartbeatJSON: heartbeatJSON,
|
heartbeatJSON: heartbeatJSON,
|
||||||
monitorName: monitorJSON.name,
|
monitorName: monitorJSON.name,
|
||||||
monitorUrl: monitorUrl,
|
monitorUrl: this.extractAdress(monitorJSON),
|
||||||
dashboardUrl: dashboardUrl,
|
dashboardUrl: dashboardUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,9 @@ class ZohoCliq extends NotificationProvider {
|
||||||
*/
|
*/
|
||||||
_statusMessageFactory = (status, monitorName) => {
|
_statusMessageFactory = (status, monitorName) => {
|
||||||
if (status === DOWN) {
|
if (status === DOWN) {
|
||||||
return `🔴 Application [${monitorName}] went down\n`;
|
return `🔴 [${monitorName}] went down\n`;
|
||||||
} else if (status === UP) {
|
} else if (status === UP) {
|
||||||
return `✅ Application [${monitorName}] is back online\n`;
|
return `### ✅ [${monitorName}] is back online\n`;
|
||||||
}
|
}
|
||||||
return "Notification\n";
|
return "Notification\n";
|
||||||
};
|
};
|
||||||
|
@ -46,16 +46,11 @@ class ZohoCliq extends NotificationProvider {
|
||||||
monitorUrl,
|
monitorUrl,
|
||||||
}) => {
|
}) => {
|
||||||
const payload = [];
|
const payload = [];
|
||||||
payload.push("### Uptime Kuma\n");
|
|
||||||
payload.push(this._statusMessageFactory(status, monitorName));
|
payload.push(this._statusMessageFactory(status, monitorName));
|
||||||
payload.push(`*Description:* ${monitorMessage}`);
|
payload.push(`*Description:* ${monitorMessage}`);
|
||||||
|
|
||||||
if (monitorName) {
|
|
||||||
payload.push(`*Monitor:* ${monitorName}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (monitorUrl && monitorUrl !== "https://") {
|
if (monitorUrl && monitorUrl !== "https://") {
|
||||||
payload.push(`*URL:* [${monitorUrl}](${monitorUrl})`);
|
payload.push(`*URL:* ${monitorUrl}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return payload;
|
return payload;
|
||||||
|
@ -87,24 +82,10 @@ class ZohoCliq extends NotificationProvider {
|
||||||
return okMsg;
|
return okMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
let url;
|
|
||||||
switch (monitorJSON["type"]) {
|
|
||||||
case "http":
|
|
||||||
case "keywork":
|
|
||||||
url = monitorJSON["url"];
|
|
||||||
break;
|
|
||||||
case "docker":
|
|
||||||
url = monitorJSON["docker_host"];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
url = monitorJSON["hostname"];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const payload = this._notificationPayloadFactory({
|
const payload = this._notificationPayloadFactory({
|
||||||
monitorMessage: heartbeatJSON.msg,
|
monitorMessage: heartbeatJSON.msg,
|
||||||
monitorName: monitorJSON.name,
|
monitorName: monitorJSON.name,
|
||||||
monitorUrl: url,
|
monitorUrl: this.extractAdress(monitorJSON),
|
||||||
status: heartbeatJSON.status
|
status: heartbeatJSON.status
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue