Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved zoho-cliq message format #4848

Merged
merged 4 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions server/notification-providers/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,6 @@ class Discord extends NotificationProvider {
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["status"] === DOWN) {
let discorddowndata = {
Expand All @@ -68,7 +48,7 @@ class Discord extends NotificationProvider {
},
{
name: monitorJSON["type"] === "push" ? "Service Type" : "Service URL",
value: monitorJSON["type"] === "push" ? "Heartbeat" : address,
value: this.extractAdress(monitorJSON),
},
{
name: `Time (${heartbeatJSON["timezone"]})`,
Expand Down Expand Up @@ -105,7 +85,7 @@ class Discord extends NotificationProvider {
},
{
name: monitorJSON["type"] === "push" ? "Service Type" : "Service URL",
value: monitorJSON["type"] === "push" ? "Heartbeat" : address,
value: this.extractAdress(monitorJSON),
},
{
name: `Time (${heartbeatJSON["timezone"]})`,
Expand Down
30 changes: 30 additions & 0 deletions server/notification-providers/notification-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,36 @@ class NotificationProvider {
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
* @param {any} error The error to throw
Expand Down
23 changes: 1 addition & 22 deletions server/notification-providers/sevenio.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,7 @@ class SevenIO extends NotificationProvider {
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:
if (![ "https://", "http://", "" ].includes(monitorJSON["url"])) {
address = monitorJSON["url"];
}
break;
}

let address = this.extractAdress(monitorJSON);
if (address !== "") {
address = `(${address}) `;
}
Expand Down
7 changes: 1 addition & 6 deletions server/notification-providers/smtp.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,7 @@ class SMTP extends NotificationProvider {

if (monitorJSON !== null) {
monitorName = monitorJSON["name"];

if (monitorJSON["type"] === "http" || monitorJSON["type"] === "keyword" || monitorJSON["type"] === "json-query") {
monitorHostnameOrURL = monitorJSON["url"];
} else {
monitorHostnameOrURL = monitorJSON["hostname"];
}
monitorHostnameOrURL = this.extractAdress(monitorJSON);
}

let serviceStatus = "⚠️ Test";
Expand Down
20 changes: 1 addition & 19 deletions server/notification-providers/squadcast.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,7 @@ class Squadcast extends NotificationProvider {
data.status = "resolve";
}

let address;
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;
data.tags["AlertAddress"] = this.extractAdress(monitorJSON);

monitorJSON["tags"].forEach(tag => {
data.tags[tag["name"]] = {
Expand Down
17 changes: 1 addition & 16 deletions server/notification-providers/teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,21 +216,6 @@ class Teams extends NotificationProvider {
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");
let dashboardUrl;
if (baseURL) {
Expand All @@ -240,7 +225,7 @@ class Teams extends NotificationProvider {
const payload = this._notificationPayloadFactory({
heartbeatJSON: heartbeatJSON,
monitorName: monitorJSON.name,
monitorUrl: monitorUrl,
monitorUrl: this.extractAdress(monitorJSON),
dashboardUrl: dashboardUrl,
});

Expand Down
27 changes: 4 additions & 23 deletions server/notification-providers/zoho-cliq.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class ZohoCliq extends NotificationProvider {
*/
_statusMessageFactory = (status, monitorName) => {
if (status === DOWN) {
return `🔴 Application [${monitorName}] went down\n`;
return `🔴 [${monitorName}] went down\n`;
} else if (status === UP) {
return `✅ Application [${monitorName}] is back online\n`;
return `### ✅ [${monitorName}] is back online\n`;
}
return "Notification\n";
};
Expand Down Expand Up @@ -46,16 +46,11 @@ class ZohoCliq extends NotificationProvider {
monitorUrl,
}) => {
const payload = [];
payload.push("### Uptime Kuma\n");
payload.push(this._statusMessageFactory(status, monitorName));
payload.push(`*Description:* ${monitorMessage}`);

if (monitorName) {
payload.push(`*Monitor:* ${monitorName}`);
FrancYescO marked this conversation as resolved.
Show resolved Hide resolved
}

if (monitorUrl && monitorUrl !== "https://") {
payload.push(`*URL:* [${monitorUrl}](${monitorUrl})`);
payload.push(`*URL:* ${monitorUrl}`);
FrancYescO marked this conversation as resolved.
Show resolved Hide resolved
}

return payload;
Expand Down Expand Up @@ -87,24 +82,10 @@ class ZohoCliq extends NotificationProvider {
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({
monitorMessage: heartbeatJSON.msg,
monitorName: monitorJSON.name,
monitorUrl: url,
monitorUrl: this.extractAdress(monitorJSON),
status: heartbeatJSON.status
});

Expand Down
Loading