Merge pull request #2377 (Zoho Cliq Notification Provider)

Zoho Cliq Notification Provider
This commit is contained in:
Louis Lam 2022-12-29 19:00:50 +08:00 committed by GitHub
commit 5554432b31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 144 additions and 0 deletions

View file

@ -0,0 +1,116 @@
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const { DOWN, UP } = require("../../src/util");
class ZohoCliq extends NotificationProvider {
name = "ZohoCliq";
/**
* Generate the message to send
* @param {const} status The status constant
* @param {string} monitorName Name of monitor
* @returns {string}
*/
_statusMessageFactory = (status, monitorName) => {
if (status === DOWN) {
return `🔴 Application [${monitorName}] went down\n`;
} else if (status === UP) {
return `✅ Application [${monitorName}] is back online\n`;
}
return "Notification\n";
};
/**
* Send the notification
* @param {string} webhookUrl URL to send the request to
* @param {Array} payload Payload generated by _notificationPayloadFactory
*/
_sendNotification = async (webhookUrl, payload) => {
await axios.post(webhookUrl, { text: payload.join("\n") });
};
/**
* Generate payload for notification
* @param {const} status The status of the monitor
* @param {string} monitorMessage Message to send
* @param {string} monitorName Name of monitor affected
* @param {string} monitorUrl URL of monitor affected
* @returns {Array}
*/
_notificationPayloadFactory = ({
status,
monitorMessage,
monitorName,
monitorUrl,
}) => {
const payload = [];
payload.push("### Uptime Kuma\n");
payload.push(this._statusMessageFactory(status, monitorName));
payload.push(`*Description:* ${monitorMessage}`);
if (monitorName) {
payload.push(`*Monitor:* ${monitorName}`);
}
if (monitorUrl && monitorUrl !== "https://") {
payload.push(`*URL:* [${monitorUrl}](${monitorUrl})`);
}
return payload;
};
/**
* Send a general notification
* @param {string} webhookUrl URL to send request to
* @param {string} msg Message to send
* @returns {Promise<void>}
*/
_handleGeneralNotification = (webhookUrl, msg) => {
const payload = this._notificationPayloadFactory({
monitorMessage: msg
});
return this._sendNotification(webhookUrl, payload);
};
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
let okMsg = "Sent Successfully.";
try {
if (heartbeatJSON == null) {
await this._handleGeneralNotification(notification.webhookUrl, msg);
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,
status: heartbeatJSON.status
});
await this._sendNotification(notification.webhookUrl, payload);
return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error);
}
}
}
module.exports = ZohoCliq;

View file

@ -44,6 +44,7 @@ const WeCom = require("./notification-providers/wecom");
const GoAlert = require("./notification-providers/goalert"); const GoAlert = require("./notification-providers/goalert");
const SMSManager = require("./notification-providers/smsmanager"); const SMSManager = require("./notification-providers/smsmanager");
const ServerChan = require("./notification-providers/serverchan"); const ServerChan = require("./notification-providers/serverchan");
const ZohoCliq = require("./notification-providers/zoho-cliq");
class Notification { class Notification {
@ -100,6 +101,7 @@ class Notification {
new Webhook(), new Webhook(),
new WeCom(), new WeCom(),
new GoAlert(), new GoAlert(),
new ZohoCliq()
]; ];
for (let item of list) { for (let item of list) {

View file

@ -0,0 +1,18 @@
<template>
<div class="mb-3">
<label for="zcliq-webhookurl" class="form-label">{{ $t("Webhook URL") }}</label>
<input
id="zcliq-webhookurl"
v-model="$parent.notification.webhookUrl"
type="text"
class="form-control"
required
/>
<i18n-t tag="div" keypath="wayToGetZohoCliqURL" class="form-text">
<a
href="https://www.zoho.com/cliq/help/platform/webhook-tokens.html"
target="_blank"
>{{ $t("here") }}</a>
</i18n-t>
</div>
</template>

View file

@ -42,6 +42,7 @@ import Telegram from "./Telegram.vue";
import Webhook from "./Webhook.vue"; import Webhook from "./Webhook.vue";
import WeCom from "./WeCom.vue"; import WeCom from "./WeCom.vue";
import GoAlert from "./GoAlert.vue"; import GoAlert from "./GoAlert.vue";
import ZohoCliq from "./ZohoCliq.vue";
/** /**
* Manage all notification form. * Manage all notification form.
@ -93,6 +94,7 @@ const NotificationFormList = {
"WeCom": WeCom, "WeCom": WeCom,
"GoAlert": GoAlert, "GoAlert": GoAlert,
"ServerChan": ServerChan, "ServerChan": ServerChan,
"ZohoCliq": ZohoCliq
}; };
export default NotificationFormList; export default NotificationFormList;

View file

@ -194,6 +194,7 @@ export default {
here: "εδώ", here: "εδώ",
Required: "Απαιτείται", Required: "Απαιτείται",
telegram: "Telegram", telegram: "Telegram",
"ZohoCliq": "ZohoCliq",
"Bot Token": "Διακριτικό Bot", "Bot Token": "Διακριτικό Bot",
wayToGetTelegramToken: "Μπορείτε να πάρετε ένα διακριτικό από {0}.", wayToGetTelegramToken: "Μπορείτε να πάρετε ένα διακριτικό από {0}.",
"Chat ID": "Chat ID", "Chat ID": "Chat ID",
@ -224,6 +225,7 @@ export default {
teams: "Microsoft Teams", teams: "Microsoft Teams",
"Webhook URL": "Webhook URL", "Webhook URL": "Webhook URL",
wayToGetTeamsURL: "Μπορείτε να μάθετε πώς να δημιουργείτε μια διεύθυνση URL webhook {0}.", wayToGetTeamsURL: "Μπορείτε να μάθετε πώς να δημιουργείτε μια διεύθυνση URL webhook {0}.",
wayToGetZohoCliqURL: "Μπορείτε να μάθετε πώς να δημιουργείτε μια διεύθυνση URL webhook {0}.",
signal: "Signal", signal: "Signal",
Number: "Αριθμός", Number: "Αριθμός",
Recipients: "Αποδέκτες", Recipients: "Αποδέκτες",

View file

@ -209,6 +209,7 @@ export default {
here: "here", here: "here",
Required: "Required", Required: "Required",
telegram: "Telegram", telegram: "Telegram",
"ZohoCliq": "ZohoCliq",
"Bot Token": "Bot Token", "Bot Token": "Bot Token",
wayToGetTelegramToken: "You can get a token from {0}.", wayToGetTelegramToken: "You can get a token from {0}.",
"Chat ID": "Chat ID", "Chat ID": "Chat ID",
@ -241,6 +242,7 @@ export default {
teams: "Microsoft Teams", teams: "Microsoft Teams",
"Webhook URL": "Webhook URL", "Webhook URL": "Webhook URL",
wayToGetTeamsURL: "You can learn how to create a webhook URL {0}.", wayToGetTeamsURL: "You can learn how to create a webhook URL {0}.",
wayToGetZohoCliqURL: "You can learn how to create a webhook URL {0}.",
signal: "Signal", signal: "Signal",
Number: "Number", Number: "Number",
Recipients: "Recipients", Recipients: "Recipients",

View file

@ -191,6 +191,7 @@ export default {
here: "Hemen", here: "Hemen",
Required: "Beharrezkoa", Required: "Beharrezkoa",
telegram: "Telegram", telegram: "Telegram",
"ZohoCliq": "ZohoCliq",
"Bot Token": "Bot Tokena", "Bot Token": "Bot Tokena",
wayToGetTelegramToken: "You can get a token from {0}.", wayToGetTelegramToken: "You can get a token from {0}.",
"Chat ID": "Txat IDa", "Chat ID": "Txat IDa",
@ -221,6 +222,7 @@ export default {
teams: "Microsoft Teams", teams: "Microsoft Teams",
"Webhook URL": "Webhook URL", "Webhook URL": "Webhook URL",
wayToGetTeamsURL: "You can learn how to create a webhook URL {0}.", wayToGetTeamsURL: "You can learn how to create a webhook URL {0}.",
wayToGetZohoCliqURL: "You can learn how to create a webhook URL {0}.",
signal: "Signal", signal: "Signal",
Number: "Zenbakia", Number: "Zenbakia",
Recipients: "Recipients", Recipients: "Recipients",